Chris@16: // (C) Copyright Gennadiy Rozental 2002-2008. Chris@16: // (C) Copyright Daryle Walker 2000-2001. Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org/libs/test for the library home page. Chris@16: // Chris@16: // File : $RCSfile$ Chris@16: // Chris@101: // Version : $Revision$ Chris@16: // Chris@16: // Description : simulate /dev/null stream Chris@16: // *************************************************************************** Chris@16: Chris@16: #ifndef BOOST_NULLSTREAM_HPP_071894GER Chris@16: #define BOOST_NULLSTREAM_HPP_071894GER Chris@16: Chris@16: #include // for std::basic_ostream Chris@16: #include // for std::basic_streambuf Chris@16: #include // for std::char_traits Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: //____________________________________________________________________________// Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: // ************************************************************************** // Chris@16: // ************** basic_nullbuf ************** // Chris@16: // ************************************************************************** // Chris@16: // Class for a buffer that reads nothing and writes to nothing. Chris@16: // Idea from an Usenet post by Tom at Chris@16: // 27 Oct 2000 14:06:21 GMT on comp.lang.c++. Chris@16: Chris@16: template > Chris@16: class basic_nullbuf : public ::std::basic_streambuf { Chris@16: typedef ::std::basic_streambuf base_type; Chris@16: public: Chris@16: // Types Chris@16: typedef typename base_type::char_type char_type; Chris@16: typedef typename base_type::traits_type traits_type; Chris@16: typedef typename base_type::int_type int_type; Chris@16: typedef typename base_type::pos_type pos_type; Chris@16: typedef typename base_type::off_type off_type; Chris@16: Chris@16: // Use automatic default constructor and destructor Chris@16: Chris@16: protected: Chris@16: // The default implementations of the miscellaneous virtual Chris@16: // member functions are sufficient. Chris@16: Chris@16: // The default implementations of the input & putback virtual Chris@16: // member functions, being nowhere but EOF, are sufficient. Chris@16: Chris@16: // The output virtual member functions need to be changed to Chris@16: // accept anything without any problems, instead of being at EOF. Chris@16: virtual ::std::streamsize xsputn( char_type const* /*s*/, ::std::streamsize n ) { return n; } // "s" is unused Chris@16: virtual int_type overflow( int_type c = traits_type::eof() ) { return traits_type::not_eof( c ); } Chris@16: }; Chris@16: Chris@16: typedef basic_nullbuf nullbuf; Chris@16: typedef basic_nullbuf wnullbuf; Chris@16: Chris@16: // ************************************************************************** // Chris@16: // ************** basic_onullstream ************** // Chris@16: // ************************************************************************** // Chris@16: // Output streams based on basic_nullbuf. Chris@16: Chris@16: #ifdef BOOST_MSVC Chris@16: # pragma warning(push) Chris@16: # pragma warning(disable: 4355) // 'this' : used in base member initializer list Chris@16: #endif Chris@16: Chris@16: template< typename CharType, class CharTraits = ::std::char_traits > Chris@16: class basic_onullstream : private boost::base_from_member > Chris@16: , public ::std::basic_ostream { Chris@16: typedef boost::base_from_member > pbase_type; Chris@16: typedef ::std::basic_ostream base_type; Chris@16: public: Chris@16: // Constructor Chris@16: basic_onullstream() : pbase_type(), base_type( &this->pbase_type::member ) {} Chris@16: }; Chris@16: Chris@16: #ifdef BOOST_MSVC Chris@16: # pragma warning(default: 4355) Chris@16: #endif Chris@16: Chris@16: typedef basic_onullstream onullstream; Chris@16: typedef basic_onullstream wonullstream; Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: //____________________________________________________________________________// Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_NULLSTREAM_HPP_071894GER