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"
using util::stream::null;
using util::stream::null_ostream;
using util::stream::bits;
//-----------------------------------------------------------------------------
std::ostream&
null::put (char)
null_ostream::put (char)
{ return *this; }
//-----------------------------------------------------------------------------
bool
null::good (void) const
null_ostream::good (void) const
{ return !bad () && !eof () && !fail (); }
//-----------------------------------------------------------------------------
bool null::bad (void) const { return false; }
bool null::eof (void) const { return false; }
bool null::fail (void) const { return false; }
bool null_ostream::bad (void) const { return false; }
bool null_ostream::eof (void) const { return false; }
bool null_ostream::fail (void) const { return false; }
//-----------------------------------------------------------------------------

View File

@ -48,28 +48,37 @@ namespace util {
return os << +n.val;
}
///////////////////////////////////////////////////////////////////////
class null : public std::ostream {
public:
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;
class null_streambuf : public std::basic_streambuf<char> {
public:
virtual ~null_streambuf () { ; }
};
//---------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////
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 {
bits (uintmax_t value, unsigned count);