yat  0.8.3pre
ColumnStream.h
00001 #ifndef _theplu_yat__utility_column_stream_
00002 #define _theplu_yat__utility_column_stream_
00003 
00004 // $Id: ColumnStream.h 2526 2011-07-25 02:03:35Z peter $
00005 
00006 /*
00007   Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
00008   Copyright (C) 2009, 2010, 2011 Peter Johansson
00009 
00010   This file is part of yat, http://dev.thep.lu.se/yat
00011 
00012   yat is free software; you can redistribute it and/or modify it
00013   under the terms of the GNU General Public License as published by
00014   the Free Software Foundation; either version 3 of the License, or
00015   (at your option) any later version.
00016 
00017   yat is distributed in the hope that it will be useful, but
00018   WITHOUT ANY WARRANTY; without even the implied warranty of
00019   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00020   General Public License for more details.
00021 
00022   You should have received a copy of the GNU General Public License
00023   along with yat. If not, see <http://www.gnu.org/licenses/>.
00024 */
00025 
00026 #include <iosfwd>
00027 #include <sstream>
00028 #include <vector>
00029 
00030 namespace theplu {
00031 namespace yat {
00032 namespace utility {
00033 
00037   class ColumnStream
00038   {
00039   public:
00040 
00044     ColumnStream(std::ostream& os, size_t columns);
00045 
00049     ~ColumnStream(void);
00050 
00054     void flush(void);
00055 
00059     size_t& margin(size_t c);
00060 
00064     void next_column(void);
00065 
00069     void print(std::stringstream&);
00070 
00074     void set_column(size_t);
00075 
00079     size_t& width(size_t c);
00080 
00081   private:
00085     ColumnStream(const ColumnStream&);
00086 
00087     void fill(size_t, size_t);
00088     bool writeline(size_t i);
00089     size_t columns(void) const;
00090     
00091 
00092     size_t activated_;
00093     std::vector<size_t> margins_;
00094     std::ostream& os_;
00095     std::vector<std::stringstream*> buffer_;
00096     std::vector<size_t> width_;
00097   };
00098 
00099 
00108   template <typename T>
00109   ColumnStream& operator<<(ColumnStream& s, const T& rhs)
00110   {
00111     std::stringstream ss;
00112     ss << rhs;
00113     s.print(ss);
00114     return s;
00115   }
00116 
00117 }}} // end of namespace utility, yat, theplu
00118 
00119 #endif

Generated on Thu Dec 20 2012 03:12:58 for yat by  doxygen 1.8.0-20120409