source: trunk/lib/yat/ColumnStream.h @ 795

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

refs #388

Create a sub-directory 'lib/yat' in which files from yat are
placed. The files may be updated via 'make fetch', see file README for
more details on how to change which files are updated/copied through
this mechanism.

The reason we do not use subversion's external mechanism is that we
don't want the files to be synchronised with yat automatically. We
want the update to be moderated by some developer.

I chose to fetch files using the svn client rather than wget because
the svn allows us to get an Id string with information from the yat
repository. 'wget' would just download the file as it appears on the
server that is the string is not expanded.

The file 'config_public.h' is created by configure just as in
yat. This implies that automake adds $(top_builddir)/lib/yat to the
include path so unless in a VPATH build $(top_srcdir)/lib/yat is in
the include path. As we have already added $(top_srcdir)/lib to the
include path, and there are both a lib/utility.h and a
lib/yat/utility.h it is not obvious which file is included when having
'include "utility.h"'. For this reason, when being in bin/ and test/
it is needed to include "../lib/utility.h" rather than "utility.h"
when we want to include 'lib/utility.h'.

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