1 | #ifndef _theplu_svndigest_column_stream_ |
---|
2 | #define _theplu_svndigest_column_stream_ |
---|
3 | |
---|
4 | // $Id: ColumnStream.h 646 2008-06-03 22:05:22Z jari $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2007 Peter Johansson |
---|
8 | Copyright (C) 2008 Jari Häkkinen |
---|
9 | |
---|
10 | This file is part of svndigest, http://trac.thep.lu.se/svndigest |
---|
11 | |
---|
12 | svndigest is free software; you can redistribute it and/or modify it |
---|
13 | under the terms of the GNU General Public License as published by |
---|
14 | the Free Software Foundation; either version 2 of the License, or |
---|
15 | (at your option) any later version. |
---|
16 | |
---|
17 | svndigest is distributed in the hope that it will be useful, but |
---|
18 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
20 | General Public License for more details. |
---|
21 | |
---|
22 | You should have received a copy of the GNU General Public License |
---|
23 | along with this program; if not, write to the Free Software |
---|
24 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
25 | 02111-1307, USA. |
---|
26 | */ |
---|
27 | |
---|
28 | #include <iosfwd> |
---|
29 | #include <sstream> |
---|
30 | #include <vector> |
---|
31 | |
---|
32 | namespace theplu{ |
---|
33 | namespace svndigest{ |
---|
34 | |
---|
35 | /// |
---|
36 | /// ostream for sending to multiple columns |
---|
37 | /// |
---|
38 | class ColumnStream |
---|
39 | { |
---|
40 | public: |
---|
41 | |
---|
42 | /// |
---|
43 | /// @brief Constructor |
---|
44 | /// |
---|
45 | ColumnStream(std::ostream& os, size_t columns); |
---|
46 | |
---|
47 | /// |
---|
48 | /// @brief Destructor |
---|
49 | /// |
---|
50 | ~ColumnStream(void); |
---|
51 | |
---|
52 | /// |
---|
53 | /// flush to ostream, goes to newline andactivates first column |
---|
54 | /// |
---|
55 | void flush(void); |
---|
56 | |
---|
57 | inline size_t& margin(size_t c) { return margins_[c]; } |
---|
58 | |
---|
59 | void next_column(void); |
---|
60 | |
---|
61 | /// |
---|
62 | /// \brief print to active column |
---|
63 | /// |
---|
64 | void print(std::stringstream&); |
---|
65 | |
---|
66 | /// |
---|
67 | /// \brief select which column is active |
---|
68 | /// |
---|
69 | void set_column(size_t); |
---|
70 | |
---|
71 | inline size_t& width(size_t c) { return width_[c]; } |
---|
72 | |
---|
73 | private: |
---|
74 | /// |
---|
75 | /// @brief Copy Constructor, not implemented |
---|
76 | /// |
---|
77 | ColumnStream(const ColumnStream&); |
---|
78 | |
---|
79 | void fill(size_t, size_t); |
---|
80 | bool writeline(size_t i); |
---|
81 | inline size_t columns(void) const { return buffer_.size(); } |
---|
82 | |
---|
83 | |
---|
84 | size_t activated_; |
---|
85 | std::vector<size_t> margins_; |
---|
86 | std::ostream& os_; |
---|
87 | std::vector<std::stringstream*> buffer_; |
---|
88 | std::vector<size_t> width_; |
---|
89 | }; |
---|
90 | |
---|
91 | |
---|
92 | template <typename T> |
---|
93 | ColumnStream& operator<<(ColumnStream& s, const T& rhs) |
---|
94 | { |
---|
95 | std::stringstream ss; |
---|
96 | ss << rhs; |
---|
97 | s.print(ss); |
---|
98 | return s; |
---|
99 | } |
---|
100 | |
---|
101 | }} // end of namespace svndigest and namespace theplu |
---|
102 | |
---|
103 | #endif |
---|