source: trunk/lib/ColumnStream.h @ 234

Last change on this file since 234 was 234, checked in by Peter Johansson, 16 years ago

fixes #87 and #95 and #103 and #104 and #80 and #108, and refs #69

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1#ifndef _theplu_svndigest_column_stream_
2#define _theplu_svndigest_column_stream_
3
4// $Id: ColumnStream.h 234 2007-04-09 12:08:26Z peter $
5
6/*
7  Copyright (C) 2007 Peter Johansson
8
9  This file is part of svndigest, http://lev.thep.lu.se/trac/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 2 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 this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26#include <fstream>
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.