source: trunk/yat/ColumnStream.h @ 1397

Last change on this file since 1397 was 1397, checked in by Peter Johansson, 12 years ago

latest yat

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1#ifndef _theplu_yat__utility_column_stream_
2#define _theplu_yat__utility_column_stream_
3
4// $Id: ColumnStream.h 2526 2011-07-25 02:03:35Z peter $
5
6/*
7  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009, 2010, 2011 Peter Johansson
9
10  This file is part of yat, http://dev.thep.lu.se/yat
11
12  yat 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 3 of the License, or
15  (at your option) any later version.
16
17  yat 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 yat. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include <iosfwd>
27#include <sstream>
28#include <vector>
29
30namespace theplu {
31namespace yat {
32namespace utility {
33
34  ///
35  /// ostream for sending to multiple columns
36  ///
37  class ColumnStream
38  {
39  public:
40
41    ///
42    /// @brief Constructor
43    ///
44    ColumnStream(std::ostream& os, size_t columns);
45
46    ///
47    /// @brief Destructor
48    ///
49    ~ColumnStream(void);
50
51    ///
52    /// flush to ostream, goes to newline andactivates first column
53    ///
54    void flush(void);
55
56    /**
57       \return reference to margin of column \a c
58     */
59    size_t& margin(size_t c);
60
61    /**
62       \brief jump to next column
63     */
64    void next_column(void);
65
66    ///
67    /// \brief print to active column
68    ///
69    void print(std::stringstream&);
70
71    ///
72    /// \brief select which column is active
73    ///
74    void set_column(size_t);
75
76    /**
77       \return reference to width of column \a c
78     */
79    size_t& width(size_t c);
80
81  private:
82    ///
83    /// @brief Copy Constructor, not implemented
84    ///
85    ColumnStream(const ColumnStream&);
86
87    void fill(size_t, size_t);
88    bool writeline(size_t i);
89    size_t columns(void) const;
90   
91
92    size_t activated_;
93    std::vector<size_t> margins_;
94    std::ostream& os_;
95    std::vector<std::stringstream*> buffer_;
96    std::vector<size_t> width_;
97  };
98
99
100  /**
101     \brief ColumnStream output operator
102
103     Requirement: T should have operator
104     operator<<(ostream&, const T&)
105
106     \relates ColumnStream
107   */
108  template <typename T>
109  ColumnStream& operator<<(ColumnStream& s, const T& rhs)
110  {
111    std::stringstream ss;
112    ss << rhs;
113    s.print(ss);
114    return s;
115  }
116
117}}} // end of namespace utility, yat, theplu
118
119#endif
Note: See TracBrowser for help on using the repository browser.