Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:43

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  (C) Copyright Daryle Walker 2000-2001.
0003 //  Distributed under the Boost Software License, Version 1.0.
0004 //  (See accompanying file LICENSE_1_0.txt or copy at
0005 //  http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 //  See http://www.boost.org/libs/test for the library home page.
0008 //
0009 //  File        : $RCSfile$
0010 //
0011 //  Version     : $Revision$
0012 //
0013 //  Description : simulate /dev/null stream
0014 // ***************************************************************************
0015 
0016 #ifndef BOOST_TEST_UTILS_NULLSTREAM_HPP
0017 #define BOOST_TEST_UTILS_NULLSTREAM_HPP
0018 
0019 // STL
0020 #include <ostream>    // for std::basic_ostream
0021 #include <streambuf>  // for std::basic_streambuf
0022 #include <string>     // for std::char_traits
0023 
0024 // Boost
0025 #include <boost/utility/base_from_member.hpp>
0026 
0027 #include <boost/test/detail/suppress_warnings.hpp>
0028 
0029 //____________________________________________________________________________//
0030 
0031 namespace boost {
0032 
0033 // ************************************************************************** //
0034 // **************                 basic_nullbuf                ************** //
0035 // ************************************************************************** //
0036 //  Class for a buffer that reads nothing and writes to nothing.
0037 //  Idea from an Usenet post by Tom <the_wid@my-deja.com> at
0038 //  27 Oct 2000 14:06:21 GMT on comp.lang.c++.
0039 
0040 template<typename CharType, class CharTraits = ::std::char_traits<CharType> >
0041 class basic_nullbuf : public ::std::basic_streambuf<CharType, CharTraits> {
0042     typedef ::std::basic_streambuf<CharType, CharTraits>  base_type;
0043 public:
0044     // Types
0045     typedef typename base_type::char_type    char_type;
0046     typedef typename base_type::traits_type  traits_type;
0047     typedef typename base_type::int_type     int_type;
0048     typedef typename base_type::pos_type     pos_type;
0049     typedef typename base_type::off_type     off_type;
0050 
0051     // Use automatic default constructor and destructor
0052 
0053 protected:
0054     // The default implementations of the miscellaneous virtual
0055     // member functions are sufficient.
0056 
0057     // The default implementations of the input & putback virtual
0058     // member functions, being nowhere but EOF, are sufficient.
0059 
0060     // The output virtual member functions need to be changed to
0061     // accept anything without any problems, instead of being at EOF.
0062     virtual  ::std::streamsize  xsputn( char_type const* /*s*/, ::std::streamsize n )   { return n; } // "s" is unused
0063     virtual  int_type           overflow( int_type c = traits_type::eof() )         { return traits_type::not_eof( c ); }
0064 };
0065 
0066 typedef basic_nullbuf<char>      nullbuf;
0067 typedef basic_nullbuf<wchar_t>  wnullbuf;
0068 
0069 // ************************************************************************** //
0070 // **************               basic_onullstream              ************** //
0071 // ************************************************************************** //
0072 //  Output streams based on basic_nullbuf.
0073 
0074 #ifdef BOOST_MSVC
0075 # pragma warning(push)
0076 # pragma warning(disable: 4355) // 'this' : used in base member initializer list
0077 #endif
0078 
0079 template< typename CharType, class CharTraits = ::std::char_traits<CharType> >
0080 class basic_onullstream : private boost::base_from_member<basic_nullbuf<CharType, CharTraits> >
0081                         , public ::std::basic_ostream<CharType, CharTraits> {
0082     typedef boost::base_from_member<basic_nullbuf<CharType, CharTraits> >   pbase_type;
0083     typedef ::std::basic_ostream<CharType, CharTraits>                      base_type;
0084 public:
0085     // Constructor
0086     basic_onullstream() : pbase_type(), base_type( &this->pbase_type::member ) {}
0087 };
0088 
0089 #ifdef BOOST_MSVC
0090 # pragma warning(default: 4355)
0091 # pragma warning(pop)
0092 #endif
0093 
0094 typedef basic_onullstream<char>      onullstream;
0095 typedef basic_onullstream<wchar_t>  wonullstream;
0096 
0097 }  // namespace boost
0098 
0099 //____________________________________________________________________________//
0100 
0101 #include <boost/test/detail/enable_warnings.hpp>
0102 
0103 #endif  // BOOST_TEST_UTILS_NULLSTREAM_HPP