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