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

Last change on this file since 1437 was 1437, checked in by Peter, 13 years ago

merge patch release 0.4.2 to trunk. Delta 0.4.2-0.4.1

  • 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 1437 2008-08-25 17:55:00Z peter $
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 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 <iostream>
28#include <sstream>
29#include <vector>
30
31namespace theplu {
32namespace yat {
33namespace utility {
34
35  ///
36  /// ostream for sending to multiple columns
37  ///
38  class ColumnStream
39  {
40  public:
41
42    ///
43    /// @brief Constructor
44    ///
45    ColumnStream(std::ostream& os, size_t columns);
46
47    ///
48    /// @brief Destructor
49    ///
50    ~ColumnStream(void);
51
52    ///
53    /// flush to ostream, goes to newline andactivates first column
54    ///
55    void flush(void);
56
57    /**
58       \return reference to margin of column \a c
59     */
60    size_t& margin(size_t c);
61
62    /**
63       \brief jump to next column
64     */
65    void next_column(void);
66
67    ///
68    /// \brief print to active column
69    ///
70    void print(std::stringstream&);
71
72    ///
73    /// \brief select which column is active
74    ///
75    void set_column(size_t);
76
77    /**
78       \return reference to width of column \a c
79     */
80    size_t& width(size_t c);
81
82  private:
83    ///
84    /// @brief Copy Constructor, not implemented
85    ///
86    ColumnStream(const ColumnStream&);
87
88    void fill(size_t, size_t);
89    bool writeline(size_t i);
90    inline size_t columns(void) const { return buffer_.size(); }
91   
92
93    size_t activated_;
94    std::vector<size_t> margins_;
95    std::ostream& os_;
96    std::vector<std::stringstream*> buffer_;
97    std::vector<size_t> width_;
98  };
99
100
101  /**
102     \brief ColumnStream output operator
103
104     Requirement: T should have operator
105     operator<<(ostream&, const T&)
106   */
107  template <typename T>
108  ColumnStream& operator<<(ColumnStream& s, const T& rhs)
109  {
110    std::stringstream ss;
111    ss << rhs;
112    s.print(ss);
113    return s;
114  }
115
116}}} // end of namespace utility, yat, theplu
117
118#endif
Note: See TracBrowser for help on using the repository browser.