source: trunk/lib/ColumnStream.h @ 791

Last change on this file since 791 was 768, checked in by Peter Johansson, 13 years ago

Merged patch release 0.6.7 to trunk. Delta 0.6.7 - 0.6.6

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1#ifndef _theplu_svndigest_column_stream_
2#define _theplu_svndigest_column_stream_
3
4// $Id: ColumnStream.h 768 2009-01-31 21:30:37Z peter $
5
6/*
7  Copyright (C) 2007, 2008 Peter Johansson
8  Copyright (C) 2008 Jari Häkkinen
9
10  This file is part of svndigest, http://dev.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 3 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 svndigest. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include <iosfwd>
27#include <sstream>
28#include <vector>
29
30namespace theplu{
31namespace svndigest{
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    inline size_t& margin(size_t c) { return margins_[c]; }
56
57    void next_column(void);
58
59    ///
60    /// \brief print to active column
61    ///
62    void print(std::stringstream&);
63
64    ///
65    /// \brief select which column is active
66    ///
67    void set_column(size_t);
68
69    inline size_t& width(size_t c) { return width_[c]; }
70
71  private:
72    ///
73    /// @brief Copy Constructor, not implemented
74    ///
75    ColumnStream(const ColumnStream&);
76
77    void fill(size_t, size_t);
78    bool writeline(size_t i);
79    inline size_t columns(void) const { return buffer_.size(); }
80   
81
82    size_t activated_;
83    std::vector<size_t> margins_;
84    std::ostream& os_;
85    std::vector<std::stringstream*> buffer_;
86    std::vector<size_t> width_;
87  };
88
89
90  template <typename T>
91  ColumnStream& operator<<(ColumnStream& s, const T& rhs)
92  {
93    std::stringstream ss;
94    ss << rhs;
95    s.print(ss);
96    return s;
97  }
98
99}} // end of namespace svndigest and namespace theplu
100
101#endif
Note: See TracBrowser for help on using the repository browser.