]> git.lyx.org Git - lyx.git/blob - boost/boost/test/detail/nullstream.hpp
update to boost 1.32.0
[lyx.git] / boost / boost / test / detail / nullstream.hpp
1 //  (C) Copyright Gennadiy Rozental 2002-2003.
2 //  (C) Copyright Daryle Walker 2000-2001. 
3 //  Distributed under the Boost Software License, Version 1.0.
4 //  (See accompanying file LICENSE_1_0.txt or copy at 
5 //  http://www.boost.org/LICENSE_1_0.txt)
6
7 //  See http://www.boost.org/libs/test for the library home page.
8 //
9 //  File        : $RCSfile: nullstream.hpp,v $
10 //
11 //  Version     : $Revision: 1.9 $
12 //
13 //  Description : simulate /dev/null stream
14 // ***************************************************************************
15
16 #ifndef BOOST_NULLSTREAM_HPP_071894GER
17 #define BOOST_NULLSTREAM_HPP_071894GER
18
19 #include <ostream>    // for std::basic_ostream
20 #include <streambuf>  // for std::basic_streambuf
21 #include <string>     // for std::char_traits
22
23 #include <boost/utility/base_from_member.hpp>
24
25 namespace boost {
26
27 // ************************************************************************** //
28 // **************                 basic_nullbuf                ************** //
29 // ************************************************************************** //
30 //  Class for a buffer that reads nothing and writes to nothing.
31 //  Idea from an Usenet post by Tom <the_wid@my-deja.com> at
32 //  27 Oct 2000 14:06:21 GMT on comp.lang.c++.
33
34 template<typename CharType, class CharTraits = ::std::char_traits<CharType> >
35 class basic_nullbuf : public ::std::basic_streambuf<CharType, CharTraits> {
36     typedef ::std::basic_streambuf<CharType, CharTraits>  base_type;
37 public:
38     // Types
39     typedef typename base_type::char_type    char_type;
40     typedef typename base_type::traits_type  traits_type;
41     typedef typename base_type::int_type     int_type;
42     typedef typename base_type::pos_type     pos_type;
43     typedef typename base_type::off_type     off_type;
44
45     // Use automatic default constructor and destructor
46
47 protected:
48     // The default implementations of the miscellaneous virtual
49     // member functions are sufficient.
50
51     // The default implementations of the input & putback virtual
52     // member functions, being nowhere but EOF, are sufficient.
53
54     // The output virtual member functions need to be changed to
55     // accept anything without any problems, instead of being at EOF.
56     virtual  ::std::streamsize  xsputn( char_type const* /*s*/, ::std::streamsize n )   { return n; } // "s" is unused
57     virtual  int_type           overflow( int_type c = traits_type::eof() )         { return traits_type::not_eof( c ); }
58 };
59
60 typedef basic_nullbuf<char>      nullbuf;
61 typedef basic_nullbuf<wchar_t>  wnullbuf;
62
63 // ************************************************************************** //
64 // **************               basic_onullstream              ************** //
65 // ************************************************************************** //
66 //  Output streams based on basic_nullbuf.
67
68 template< typename CharType, class CharTraits = ::std::char_traits<CharType> >
69 class basic_onullstream : private boost::base_from_member<basic_nullbuf<CharType, CharTraits> >
70                         , public ::std::basic_ostream<CharType, CharTraits> {
71     typedef boost::base_from_member<basic_nullbuf<CharType, CharTraits> >   pbase_type;
72     typedef ::std::basic_ostream<CharType, CharTraits>                      base_type;
73 public:
74     // Constructor
75     basic_onullstream() : pbase_type(), base_type( &this->pbase_type::member ) {}
76 };
77
78 typedef basic_onullstream<char>      onullstream;
79 typedef basic_onullstream<wchar_t>  wonullstream;
80
81 }  // namespace boost
82
83 // ***************************************************************************
84 //  Revision History :
85 //  
86 //  $Log: nullstream.hpp,v $
87 //  Revision 1.9  2004/07/19 12:21:08  rogeeff
88 //  guard rename
89 //
90 //  Revision 1.8  2004/05/21 06:19:35  rogeeff
91 //  licence update
92 //
93 //  Revision 1.7  2003/12/01 00:41:56  rogeeff
94 //  prerelease cleaning
95 //
96 // ***************************************************************************
97
98 #endif  // BOOST_NULLSTREAM_HPP_071894GER