00001 #ifndef _theplu_yat__utility_column_stream_
00002 #define _theplu_yat__utility_column_stream_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <fstream>
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 inline size_t columns(void) const { return buffer_.size(); }
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 }}}
00118
00119 #endif