source: branches/0.4-stable/yat/utility/ColumnStream.h @ 1743

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

updating copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1#ifndef _theplu_yat__utility_column_stream_
2#define _theplu_yat__utility_column_stream_
3
4// $Id: ColumnStream.h 1743 2009-01-23 14:20:30Z peter $
5
6/*
7  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2008 Peter Johansson
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 2 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 this program; if not, write to the Free Software
24  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25  02111-1307, USA.
26*/
27#include <fstream>
28#include <iostream>
29#include <sstream>
30#include <vector>
31
32namespace theplu {
33namespace yat {
34namespace utility {
35
36  ///
37  /// ostream for sending to multiple columns
38  ///
39  class ColumnStream
40  {
41  public:
42
43    ///
44    /// @brief Constructor
45    ///
46    ColumnStream(std::ostream& os, size_t columns);
47
48    ///
49    /// @brief Destructor
50    ///
51    ~ColumnStream(void);
52
53    ///
54    /// flush to ostream, goes to newline andactivates first column
55    ///
56    void flush(void);
57
58    /**
59       \return reference to margin of column \a c
60     */
61    size_t& margin(size_t c);
62
63    /**
64       \brief jump to next column
65     */
66    void next_column(void);
67
68    ///
69    /// \brief print to active column
70    ///
71    void print(std::stringstream&);
72
73    ///
74    /// \brief select which column is active
75    ///
76    void set_column(size_t);
77
78    /**
79       \return reference to width of column \a c
80     */
81    size_t& width(size_t c);
82
83  private:
84    ///
85    /// @brief Copy Constructor, not implemented
86    ///
87    ColumnStream(const ColumnStream&);
88
89    void fill(size_t, size_t);
90    bool writeline(size_t i);
91    inline size_t columns(void) const { return buffer_.size(); }
92   
93
94    size_t activated_;
95    std::vector<size_t> margins_;
96    std::ostream& os_;
97    std::vector<std::stringstream*> buffer_;
98    std::vector<size_t> width_;
99  };
100
101
102  /**
103     \brief ColumnStream output operator
104
105     Requirement: T should have operator
106     operator<<(ostream&, const T&)
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.