// nulstreambuf.h // #if !defined( NULSTREAMBUF__H) #define NULSTREAMBUF__H #include #include template< class char_type , class traits_type = std::char_traits< char_type> > class basic_nulstream_streambuf : public std::basic_streambuf< char_type, traits_type> { private: typedef basic_nulstream_streambuf< char_type, traits_type> this_class; typedef std::basic_streambuf< char_type, traits_type> streambuf_type; typedef std::basic_streambuf< char_type, traits_type> base_class; enum { _BADOFF = -1 /* bad offset - for positioning functions */ }; #ifndef __GNUC__ using typename base_class::int_type; using typename base_class::pos_type; using typename base_class::off_type; #endif protected: // input, not allowed virtual int_type pbackfail(int_type = traits_type::eof()) { // only for output, not for input assert( false); return (traits_type::eof()); } virtual int showmanyc() { // only for output, not for input assert( false); return 0; } virtual int_type underflow() { // only for output, not for input assert( false); return (traits_type::eof()); } virtual int_type uflow() { // only for output, not for input assert( false); return (traits_type::eof()); } virtual std::streamsize xsgetn(char_type *, std::streamsize) { // only for output, not for input assert( false); return 0; } // positioning, not allowed - we're a log virtual pos_type seekoff(off_type, std::ios_base::seekdir, std::ios_base::openmode = std::ios_base::in | std::ios_base::out) { // we don't allow positioning assert( false); return (std::streampos( _BADOFF)); } virtual pos_type seekpos(pos_type, std::ios_base::openmode = std::ios_base::in | std::ios_base::out) { // we don't allow positioning assert( false); return (std::streampos( _BADOFF)); } // output functions // called to write out from the internal // buffer, into the external buffer virtual int sync() { return 0; } virtual streambuf_type *setbuf( char_type * buffer, std::streamsize n) { // ... note: this function MUST be called // before working with this stream buffer // we don't use a buffer - we forward everything assert( buffer == NULL && n == 0); this->setp( NULL, NULL); return this; } virtual int_type overflow(int_type nChar = traits_type::eof()) { return traits_type::not_eof( nChar); } virtual std::streamsize xsputn(const char_type *S, std::streamsize N) { return N; } }; #endif