From 12f154d0cbd4d0e376a7a5888159d93ced9c450c Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 12 May 2016 17:47:22 +1000 Subject: [PATCH] stream: work towards streambuf and stream impl --- stream.cpp | 12 ++++++------ stream.hpp | 45 +++++++++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/stream.cpp b/stream.cpp index d6708016..f0539c43 100644 --- a/stream.cpp +++ b/stream.cpp @@ -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; } //----------------------------------------------------------------------------- diff --git a/stream.hpp b/stream.hpp index b7866530..2b2e306e 100644 --- a/stream.hpp +++ b/stream.hpp @@ -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 { + public: + virtual ~null_streambuf () { ; } }; - //--------------------------------------------------------------------- + /////////////////////////////////////////////////////////////////////// + class null_ostream : public std::basic_ostream { + 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);