#ifndef __NULLSTREAM_H__ #define __NULLSTREAM_H__ #include #include #include /* * ヌルストリーム * nul,/dev/nullと同じ動作 */ template< class _Elem, class _Traits> class basic_NullStreambuf : public std::basic_streambuf<_Elem, _Traits> { protected: typedef std::basic_streambuf<_Elem, _Traits> super_t; typedef std::streamsize streamsize; typedef typename super_t::int_type int_type; public: basic_NullStreambuf() throw(std::ios_base::failure) : super_t() {} virtual ~basic_NullStreambuf() {} protected: int_type overflow(int_type c = _Traits::eof()){ return _Traits::not_eof(c); } streamsize xsputn(const _Elem *s, streamsize n){ return (streamsize)n; } streamsize xsgetn(_Elem *s, streamsize n){ return (streamsize)0; } int_type underflow(){ return _Traits::eof(); } int_type uflow(){ return _Traits::eof(); } }; typedef basic_NullStreambuf > NullStreambuf; class NullStream : public std::iostream{ public: typedef NullStreambuf buf_t; protected: typedef std::iostream super_t; buf_t buf; public: NullStream() throw(std::ios_base::failure) : buf(), super_t(&buf){} ~NullStream(){} }; #endif /* __NULLSTREAM_H__ */