source: trunk/yat/utility/ColumnStream.h @ 1707

Last change on this file since 1707 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
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 1487 2008-09-10 08:41:36Z jari $
5
6/*
7  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
8
9  This file is part of svndigest, http://dev.thep.lu.se/svndigest
10
11  svndigest is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation; either version 3 of the License, or
14  (at your option) any later version.
15
16  svndigest is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24#include <fstream>
25#include <iostream>
26#include <sstream>
27#include <vector>
28
29namespace theplu {
30namespace yat {
31namespace utility {
32
33  ///
34  /// ostream for sending to multiple columns
35  ///
36  class ColumnStream
37  {
38  public:
39
40    ///
41    /// @brief Constructor
42    ///
43    ColumnStream(std::ostream& os, size_t columns);
44
45    ///
46    /// @brief Destructor
47    ///
48    ~ColumnStream(void);
49
50    ///
51    /// flush to ostream, goes to newline andactivates first column
52    ///
53    void flush(void);
54
55    /**
56       \return reference to margin of column \a c
57     */
58    size_t& margin(size_t c);
59
60    /**
61       \brief jump to next column
62     */
63    void next_column(void);
64
65    ///
66    /// \brief print to active column
67    ///
68    void print(std::stringstream&);
69
70    ///
71    /// \brief select which column is active
72    ///
73    void set_column(size_t);
74
75    /**
76       \return reference to width of column \a c
77     */
78    size_t& width(size_t c);
79
80  private:
81    ///
82    /// @brief Copy Constructor, not implemented
83    ///
84    ColumnStream(const ColumnStream&);
85
86    void fill(size_t, size_t);
87    bool writeline(size_t i);
88    inline size_t columns(void) const { return buffer_.size(); }
89   
90
91    size_t activated_;
92    std::vector<size_t> margins_;
93    std::ostream& os_;
94    std::vector<std::stringstream*> buffer_;
95    std::vector<size_t> width_;
96  };
97
98
99  /**
100     \brief ColumnStream output operator
101
102     Requirement: T should have operator
103     operator<<(ostream&, const T&)
104   */
105  template <typename T>
106  ColumnStream& operator<<(ColumnStream& s, const T& rhs)
107  {
108    std::stringstream ss;
109    ss << rhs;
110    s.print(ss);
111    return s;
112  }
113
114}}} // end of namespace utility, yat, theplu
115
116#endif
Note: See TracBrowser for help on using the repository browser.