968 |
11 Oct 07 |
peter |
1 |
#ifndef _theplu_yat__utility_column_stream_ |
968 |
11 Oct 07 |
peter |
2 |
#define _theplu_yat__utility_column_stream_ |
968 |
11 Oct 07 |
peter |
3 |
|
968 |
11 Oct 07 |
peter |
// $Id$ |
968 |
11 Oct 07 |
peter |
5 |
|
968 |
11 Oct 07 |
peter |
6 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009, 2010 Peter Johansson |
968 |
11 Oct 07 |
peter |
10 |
|
2290 |
07 Jul 10 |
peter |
This file is part of yat, http://dev.thep.lu.se/yat |
968 |
11 Oct 07 |
peter |
12 |
|
2290 |
07 Jul 10 |
peter |
yat is free software; you can redistribute it and/or modify it |
968 |
11 Oct 07 |
peter |
under the terms of the GNU General Public License as published by |
1486 |
09 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
968 |
11 Oct 07 |
peter |
(at your option) any later version. |
968 |
11 Oct 07 |
peter |
17 |
|
2290 |
07 Jul 10 |
peter |
yat is distributed in the hope that it will be useful, but |
968 |
11 Oct 07 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
968 |
11 Oct 07 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
968 |
11 Oct 07 |
peter |
General Public License for more details. |
968 |
11 Oct 07 |
peter |
22 |
|
968 |
11 Oct 07 |
peter |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
968 |
11 Oct 07 |
peter |
25 |
*/ |
2514 |
11 Jul 11 |
peter |
26 |
|
2076 |
06 Oct 09 |
peter |
27 |
#include <iosfwd> |
968 |
11 Oct 07 |
peter |
28 |
#include <sstream> |
968 |
11 Oct 07 |
peter |
29 |
#include <vector> |
968 |
11 Oct 07 |
peter |
30 |
|
968 |
11 Oct 07 |
peter |
31 |
namespace theplu { |
968 |
11 Oct 07 |
peter |
32 |
namespace yat { |
968 |
11 Oct 07 |
peter |
33 |
namespace utility { |
968 |
11 Oct 07 |
peter |
34 |
|
968 |
11 Oct 07 |
peter |
35 |
/// |
3232 |
21 May 14 |
peter |
/// ostream for sending to multiple columns |
968 |
11 Oct 07 |
peter |
37 |
/// |
968 |
11 Oct 07 |
peter |
38 |
class ColumnStream |
968 |
11 Oct 07 |
peter |
39 |
{ |
968 |
11 Oct 07 |
peter |
40 |
public: |
968 |
11 Oct 07 |
peter |
41 |
|
968 |
11 Oct 07 |
peter |
42 |
/// |
968 |
11 Oct 07 |
peter |
/// @brief Constructor |
968 |
11 Oct 07 |
peter |
44 |
/// |
968 |
11 Oct 07 |
peter |
45 |
ColumnStream(std::ostream& os, size_t columns); |
968 |
11 Oct 07 |
peter |
46 |
|
968 |
11 Oct 07 |
peter |
47 |
/// |
968 |
11 Oct 07 |
peter |
/// @brief Destructor |
968 |
11 Oct 07 |
peter |
49 |
/// |
968 |
11 Oct 07 |
peter |
50 |
~ColumnStream(void); |
968 |
11 Oct 07 |
peter |
51 |
|
968 |
11 Oct 07 |
peter |
52 |
/// |
3232 |
21 May 14 |
peter |
/// flush to ostream, goes to newline and activates first column |
968 |
11 Oct 07 |
peter |
54 |
/// |
968 |
11 Oct 07 |
peter |
55 |
void flush(void); |
968 |
11 Oct 07 |
peter |
56 |
|
968 |
11 Oct 07 |
peter |
57 |
/** |
968 |
11 Oct 07 |
peter |
\return reference to margin of column \a c |
968 |
11 Oct 07 |
peter |
59 |
*/ |
968 |
11 Oct 07 |
peter |
60 |
size_t& margin(size_t c); |
968 |
11 Oct 07 |
peter |
61 |
|
968 |
11 Oct 07 |
peter |
62 |
/** |
968 |
11 Oct 07 |
peter |
\brief jump to next column |
968 |
11 Oct 07 |
peter |
64 |
*/ |
968 |
11 Oct 07 |
peter |
65 |
void next_column(void); |
968 |
11 Oct 07 |
peter |
66 |
|
968 |
11 Oct 07 |
peter |
67 |
/// |
968 |
11 Oct 07 |
peter |
/// \brief print to active column |
968 |
11 Oct 07 |
peter |
69 |
/// |
968 |
11 Oct 07 |
peter |
70 |
void print(std::stringstream&); |
968 |
11 Oct 07 |
peter |
71 |
|
968 |
11 Oct 07 |
peter |
72 |
/// |
968 |
11 Oct 07 |
peter |
/// \brief select which column is active |
968 |
11 Oct 07 |
peter |
74 |
/// |
968 |
11 Oct 07 |
peter |
75 |
void set_column(size_t); |
968 |
11 Oct 07 |
peter |
76 |
|
968 |
11 Oct 07 |
peter |
77 |
/** |
968 |
11 Oct 07 |
peter |
\return reference to width of column \a c |
968 |
11 Oct 07 |
peter |
79 |
*/ |
968 |
11 Oct 07 |
peter |
80 |
size_t& width(size_t c); |
968 |
11 Oct 07 |
peter |
81 |
|
968 |
11 Oct 07 |
peter |
82 |
private: |
968 |
11 Oct 07 |
peter |
83 |
/// |
968 |
11 Oct 07 |
peter |
/// @brief Copy Constructor, not implemented |
968 |
11 Oct 07 |
peter |
85 |
/// |
968 |
11 Oct 07 |
peter |
86 |
ColumnStream(const ColumnStream&); |
968 |
11 Oct 07 |
peter |
87 |
|
968 |
11 Oct 07 |
peter |
88 |
void fill(size_t, size_t); |
968 |
11 Oct 07 |
peter |
89 |
bool writeline(size_t i); |
2512 |
11 Jul 11 |
peter |
90 |
size_t columns(void) const; |
968 |
11 Oct 07 |
peter |
91 |
|
968 |
11 Oct 07 |
peter |
92 |
size_t activated_; |
968 |
11 Oct 07 |
peter |
93 |
std::vector<size_t> margins_; |
968 |
11 Oct 07 |
peter |
94 |
std::ostream& os_; |
968 |
11 Oct 07 |
peter |
95 |
std::vector<std::stringstream*> buffer_; |
968 |
11 Oct 07 |
peter |
96 |
std::vector<size_t> width_; |
968 |
11 Oct 07 |
peter |
97 |
}; |
968 |
11 Oct 07 |
peter |
98 |
|
968 |
11 Oct 07 |
peter |
99 |
|
968 |
11 Oct 07 |
peter |
100 |
/** |
968 |
11 Oct 07 |
peter |
\brief ColumnStream output operator |
968 |
11 Oct 07 |
peter |
102 |
|
968 |
11 Oct 07 |
peter |
Requirement: T should have operator |
968 |
11 Oct 07 |
peter |
operator<<(ostream&, const T&) |
1887 |
31 Mar 09 |
peter |
105 |
|
1887 |
31 Mar 09 |
peter |
\relates ColumnStream |
968 |
11 Oct 07 |
peter |
107 |
*/ |
968 |
11 Oct 07 |
peter |
108 |
template <typename T> |
968 |
11 Oct 07 |
peter |
109 |
ColumnStream& operator<<(ColumnStream& s, const T& rhs) |
968 |
11 Oct 07 |
peter |
110 |
{ |
968 |
11 Oct 07 |
peter |
111 |
std::stringstream ss; |
968 |
11 Oct 07 |
peter |
112 |
ss << rhs; |
968 |
11 Oct 07 |
peter |
113 |
s.print(ss); |
968 |
11 Oct 07 |
peter |
114 |
return s; |
968 |
11 Oct 07 |
peter |
115 |
} |
968 |
11 Oct 07 |
peter |
116 |
|
968 |
11 Oct 07 |
peter |
117 |
}}} // end of namespace utility, yat, theplu |
968 |
11 Oct 07 |
peter |
118 |
|
968 |
11 Oct 07 |
peter |
119 |
#endif |