source: trunk/debathena/third/schroot/sbuild/sbuild-nostream.h @ 24167

Revision 24167, 2.2 KB checked in by broder, 15 years ago (diff)
Import schroot upstream into subversion.
RevLine 
[24167]1/* Copyright © 2005-2007  Roger Leigh <rleigh@debian.org>
2 *
3 * schroot is free software: you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * schroot is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program.  If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 *********************************************************************/
18
19#ifndef SBUILD_NOSTREAM_H
20#define SBUILD_NOSTREAM_H
21
22#include <streambuf>
23#include <ostream>
24
25namespace sbuild
26{
27
28  /**
29   * Null stream buffer.  This stream buffer acts as a bit-bucket,
30   * discarding all input.
31   */
32  template <class cT, class traits = std::char_traits<cT> >
33  class basic_nbuf: public std::basic_streambuf<cT, traits>
34  {
35    /**
36     * Output buffer.  EOF is never returned.
37     *
38     * @param c the character to output.
39     * @returns traits::not_eof is always returned, never traits::eof.
40     */
41    typename traits::int_type
42    overflow (typename traits::int_type c)
43    {
44      return traits::not_eof(c); // indicate success
45    }
46  };
47
48  /**
49   * Null output stream.  This ostream discards all input, because it
50   * uses a basic_nbuf stream buffer.
51   */
52  template <class cT, class traits = std::char_traits<cT> >
53  class basic_nostream: public std::basic_ostream<cT, traits>
54  {
55  public:
56    /// The constructor.
57    basic_nostream ():
58      std::basic_ios<cT, traits>(&nbuf),
59      std::basic_ostream<cT, traits>(&nbuf)
60    {
61      init(&nbuf);
62    }
63
64  private:
65    /// The stream buffer.
66    basic_nbuf<cT, traits> nbuf;
67  };
68
69  /// A null ostream.
70  typedef basic_nostream<char> nostream;
71  /// A wide null ostream.
72  typedef basic_nostream<wchar_t> wnostream;
73
74  /// A null ostream.
75  extern nostream cnull;
76
77}
78
79#endif /* SBUILD_NOSTREAM_H */
80
81/*
82 * Local Variables:
83 * mode:C++
84 * End:
85 */
Note: See TracBrowser for help on using the repository browser.