stream: work towards streambuf and stream impl

This commit is contained in:
Danny Robson 2016-05-12 17:47:22 +10:00
parent 67402eee42
commit 12f154d0cb
2 changed files with 33 additions and 24 deletions

View File

@ -18,25 +18,25 @@
#include "debug.hpp" #include "debug.hpp"
using util::stream::null; using util::stream::null_ostream;
using util::stream::bits; using util::stream::bits;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
std::ostream& std::ostream&
null::put (char) null_ostream::put (char)
{ return *this; } { return *this; }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool
null::good (void) const null_ostream::good (void) const
{ return !bad () && !eof () && !fail (); } { return !bad () && !eof () && !fail (); }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool null::bad (void) const { return false; } bool null_ostream::bad (void) const { return false; }
bool null::eof (void) const { return false; } bool null_ostream::eof (void) const { return false; }
bool null::fail (void) const { return false; } bool null_ostream::fail (void) const { return false; }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -48,28 +48,37 @@ namespace util {
return os << +n.val; return os << +n.val;
} }
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
class null : public std::ostream { class null_streambuf : public std::basic_streambuf<char> {
public: public:
std::ostream & put (char c); virtual ~null_streambuf () { ; }
std::ostream & write (const char *s, std::streamsize n);
std::streampos tellp (void);
std::ostream & seekp (std::streampos pos);
std::ostream & seekp (std::streamoff off,
std::ios_base::seekdir dir);
std::ostream & flush (void);
bool good (void) const;
bool bad (void) const;
bool eof (void) const;
bool fail (void) const;
}; };
//--------------------------------------------------------------------- ///////////////////////////////////////////////////////////////////////
class null_ostream : public std::basic_ostream<char> {
public:
virtual ~null_ostream () { ; }
std::ostream & put (char c);
std::ostream & write (const char *s, std::streamsize n);
std::streampos tellp (void);
std::ostream & seekp (std::streampos pos);
std::ostream & seekp (std::streamoff off,
std::ios_base::seekdir dir);
std::ostream & flush (void);
bool good (void) const;
bool bad (void) const;
bool eof (void) const;
bool fail (void) const;
};
///////////////////////////////////////////////////////////////////////
struct bits { struct bits {
bits (uintmax_t value, unsigned count); bits (uintmax_t value, unsigned count);