source: NonGTP/Boost/boost/test/utils/nullstream.hpp @ 857

Revision 857, 4.7 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]1//  (C) Copyright Gennadiy Rozental 2002-2005.
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.4 $
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#include <boost/test/detail/suppress_warnings.hpp>
26
27//____________________________________________________________________________//
28
29namespace boost {
30
31// ************************************************************************** //
32// **************                 basic_nullbuf                ************** //
33// ************************************************************************** //
34//  Class for a buffer that reads nothing and writes to nothing.
35//  Idea from an Usenet post by Tom <the_wid@my-deja.com> at
36//  27 Oct 2000 14:06:21 GMT on comp.lang.c++.
37
38template<typename CharType, class CharTraits = ::std::char_traits<CharType> >
39class basic_nullbuf : public ::std::basic_streambuf<CharType, CharTraits> {
40    typedef ::std::basic_streambuf<CharType, CharTraits>  base_type;
41public:
42    // Types
43    typedef typename base_type::char_type    char_type;
44    typedef typename base_type::traits_type  traits_type;
45    typedef typename base_type::int_type     int_type;
46    typedef typename base_type::pos_type     pos_type;
47    typedef typename base_type::off_type     off_type;
48
49    // Use automatic default constructor and destructor
50
51protected:
52    // The default implementations of the miscellaneous virtual
53    // member functions are sufficient.
54
55    // The default implementations of the input & putback virtual
56    // member functions, being nowhere but EOF, are sufficient.
57
58    // The output virtual member functions need to be changed to
59    // accept anything without any problems, instead of being at EOF.
60    virtual  ::std::streamsize  xsputn( char_type const* /*s*/, ::std::streamsize n )   { return n; } // "s" is unused
61    virtual  int_type           overflow( int_type c = traits_type::eof() )         { return traits_type::not_eof( c ); }
62};
63
64typedef basic_nullbuf<char>      nullbuf;
65typedef basic_nullbuf<wchar_t>  wnullbuf;
66
67// ************************************************************************** //
68// **************               basic_onullstream              ************** //
69// ************************************************************************** //
70//  Output streams based on basic_nullbuf.
71
72#ifdef BOOST_MSVC
73# pragma warning(push)
74# pragma warning(disable: 4355) // 'this' : used in base member initializer list
75#endif
76
77template< typename CharType, class CharTraits = ::std::char_traits<CharType> >
78class basic_onullstream : private boost::base_from_member<basic_nullbuf<CharType, CharTraits> >
79                        , public ::std::basic_ostream<CharType, CharTraits> {
80    typedef boost::base_from_member<basic_nullbuf<CharType, CharTraits> >   pbase_type;
81    typedef ::std::basic_ostream<CharType, CharTraits>                      base_type;
82public:
83    // Constructor
84    basic_onullstream() : pbase_type(), base_type( &this->pbase_type::member ) {}
85};
86
87#ifdef BOOST_MSVC
88# pragma warning(default: 4355)
89#endif
90
91typedef basic_onullstream<char>      onullstream;
92typedef basic_onullstream<wchar_t>  wonullstream;
93
94}  // namespace boost
95
96//____________________________________________________________________________//
97
98#include <boost/test/detail/enable_warnings.hpp>
99
100// ***************************************************************************
101//  Revision History :
102// 
103//  $Log: nullstream.hpp,v $
104//  Revision 1.4  2005/02/20 08:27:08  rogeeff
105//  This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
106//
107//  Revision 1.3  2005/02/01 06:40:07  rogeeff
108//  copyright update
109//  old log entries removed
110//  minor stilistic changes
111//  depricated tools removed
112//
113//  Revision 1.2  2005/01/30 01:42:49  rogeeff
114//  warnings suppressed
115//
116//  Revision 1.1  2005/01/22 18:21:40  rogeeff
117//  moved sharable staff into utils
118//
119// ***************************************************************************
120
121#endif  // BOOST_NULLSTREAM_HPP_071894GER
Note: See TracBrowser for help on using the repository browser.