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 #include <fstream>
00025 #include <iostream>
00026 #include <sstream>
00027 #include <vector>
00028
00029 namespace theplu {
00030 namespace yat {
00031 namespace utility {
00032
00036 class ColumnStream
00037 {
00038 public:
00039
00043 ColumnStream(std::ostream& os, size_t columns);
00044
00048 ~ColumnStream(void);
00049
00053 void flush(void);
00054
00058 size_t& margin(size_t c);
00059
00063 void next_column(void);
00064
00068 void print(std::stringstream&);
00069
00073 void set_column(size_t);
00074
00078 size_t& width(size_t c);
00079
00080 private:
00084 ColumnStream(const ColumnStream&);
00085
00086 void fill(size_t, size_t);
00087 bool writeline(size_t i);
00088 inline size_t columns(void) const { return buffer_.size(); }
00089
00090
00091 size_t activated_;
00092 std::vector<size_t> margins_;
00093 std::ostream& os_;
00094 std::vector<std::stringstream*> buffer_;
00095 std::vector<size_t> width_;
00096 };
00097
00098
00105 template <typename T>
00106 ColumnStream& operator<<(ColumnStream& s, const T& rhs)
00107 {
00108 std::stringstream ss;
00109 ss << rhs;
00110 s.print(ss);
00111 return s;
00112 }
00113
00114 }}}
00115
00116 #endif