From 27926249969c7d16a0b552df295636f3ae9e7001 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 21 Dec 2009 10:24:35 +0100 Subject: [PATCH] Expose STL std streams in a consistent manner for serial streams. Previously Fstreams had stdStream() as a public member and the other streams had stream() as a protected member. All serial streams now have public method stdStream() and the stream() method has been eliminated. This is not only more consistent, but also avoids confusion (for the programmer, not the compiler) with the ITstream::stream() method. --- src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C | 33 +++++++++++------ src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H | 22 ++++++------ src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C | 35 ++++++++++++------- src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H | 22 ++++++------ src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C | 2 +- src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H | 32 ++++++++--------- src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H | 30 ++++++++-------- .../IOstreams/StringStreams/IStringStream.H | 7 ++-- .../IOstreams/StringStreams/OStringStream.H | 13 ++++--- .../db/IOstreams/hashes/OSHA1stream.H | 4 +-- src/conversion/ensight/file/ensightFile.C | 18 +++++----- 11 files changed, 124 insertions(+), 94 deletions(-) diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C index 68fe61ce2c..33f243541a 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C @@ -78,17 +78,6 @@ Foam::IFstreamAllocator::~IFstreamAllocator() } -std::istream& Foam::IFstreamAllocator::stdStream() -{ - if (!ifPtr_) - { - FatalErrorIn("IFstreamAllocator::stdStream()") - << "No stream allocated" << abort(FatalError); - } - return *ifPtr_; -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::IFstream::IFstream @@ -143,6 +132,28 @@ Foam::IFstream::~IFstream() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +std::istream& Foam::IFstream::stdStream() +{ + if (!ifPtr_) + { + FatalErrorIn("IFstream::stdStream()") + << "No stream allocated" << abort(FatalError); + } + return *ifPtr_; +} + + +const std::istream& Foam::IFstream::stdStream() const +{ + if (!ifPtr_) + { + FatalErrorIn("IFstream::stdStream() const") + << "No stream allocated" << abort(FatalError); + } + return *ifPtr_; +} + + void Foam::IFstream::print(Ostream& os) const { // Print File data diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H index 791e94df9e..ebe163f445 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H +++ b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H @@ -51,7 +51,7 @@ namespace Foam class IFstream; /*---------------------------------------------------------------------------*\ - Class IFstreamAllocator Declaration + Class IFstreamAllocator Declaration \*---------------------------------------------------------------------------*/ //- A std::istream with ability to handle compressed files @@ -74,19 +74,11 @@ class IFstreamAllocator // Destructor ~IFstreamAllocator(); - - -public: - - // Member functions - - //- Access to underlying std::istream (for e.g. lexer) - istream& stdStream(); }; /*---------------------------------------------------------------------------*\ - Class IFstream Declaration + Class IFstream Declaration \*---------------------------------------------------------------------------*/ class IFstream @@ -136,6 +128,16 @@ public: return pathname_; } + + // STL stream + + //- Access to underlying std::istream + virtual istream& stdStream(); + + //- Const access to underlying std::istream + virtual const istream& stdStream() const; + + // Print //- Print description of IOstream to Ostream diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C index 27dc86436b..16946d7d5b 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C @@ -81,17 +81,6 @@ Foam::OFstreamAllocator::~OFstreamAllocator() } -std::ostream& Foam::OFstreamAllocator::stdStream() -{ - if (!ofPtr_) - { - FatalErrorIn("OFstreamAllocator::stdStream()") - << "No stream allocated." << abort(FatalError); - } - return *ofPtr_; -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::OFstream::OFstream @@ -131,7 +120,7 @@ Foam::OFstream::OFstream } -// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::OFstream::~OFstream() {} @@ -139,6 +128,28 @@ Foam::OFstream::~OFstream() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +std::ostream& Foam::OFstream::stdStream() +{ + if (!ofPtr_) + { + FatalErrorIn("OFstream::stdStream()") + << "No stream allocated." << abort(FatalError); + } + return *ofPtr_; +} + + +const std::ostream& Foam::OFstream::stdStream() const +{ + if (!ofPtr_) + { + FatalErrorIn("OFstreamAllocator::stdStream() const") + << "No stream allocated." << abort(FatalError); + } + return *ofPtr_; +} + + void Foam::OFstream::print(Ostream& os) const { os << " OFstream: "; diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H index 7ad2ebd88a..19654ca35e 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H +++ b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H @@ -51,7 +51,7 @@ namespace Foam class OFstream; /*---------------------------------------------------------------------------*\ - Class OFstreamAllocator Declaration + Class OFstreamAllocator Declaration \*---------------------------------------------------------------------------*/ //- A std::ostream with ability to handle compressed files @@ -74,18 +74,11 @@ class OFstreamAllocator ~OFstreamAllocator(); - -public: - - // Member functions - - //- Access to underlying std::ostream - ostream& stdStream(); }; /*---------------------------------------------------------------------------*\ - Class OFstream Declaration + Class OFstream Declaration \*---------------------------------------------------------------------------*/ class OFstream @@ -138,6 +131,15 @@ public: } + // STL stream + + //- Access to underlying std::ostream + virtual ostream& stdStream(); + + //- Const access to underlying std::ostream + virtual const ostream& stdStream() const; + + // Print //- Print description of IOstream to Ostream @@ -146,8 +148,8 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// Global predefined null output stream +//- Global predefined null output stream "/dev/null" extern OFstream Snull; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C index d98d75d076..76ec06dc5d 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C @@ -551,7 +551,7 @@ Foam::Istream& Foam::ISstream::read(char* buf, std::streamsize count) Foam::Istream& Foam::ISstream::rewind() { - stream().rdbuf()->pubseekpos(0); + stdStream().rdbuf()->pubseekpos(0); return *this; } diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H index 0c6bc9d44b..814d6a3af1 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H @@ -72,23 +72,6 @@ class ISstream void operator=(const ISstream&); -protected: - - // Protected member functions - - //- Return the stream reference - istream& stream() - { - return is_; - } - - //- Return the const stream reference - const istream& stream() const - { - return is_; - } - - public: // Constructors @@ -185,6 +168,21 @@ public: virtual ios_base::fmtflags flags(const ios_base::fmtflags flags); + // STL stream + + //- Access to underlying std::istream + virtual istream& stdStream() + { + return is_; + } + + //- Const access to underlying std::istream + virtual const istream& stdStream() const + { + return is_; + } + + // Print //- Print description of IOstream to Ostream diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H index 5c862afd93..c41cf46d77 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H @@ -67,21 +67,6 @@ class OSstream void operator=(const OSstream&); -protected: - - //- Return the stream reference - ostream& stream() - { - return os_; - } - - //- Return the const stream reference - const ostream& stream() const - { - return os_; - } - - public: // Constructors @@ -187,6 +172,21 @@ public: virtual int precision(const int); + // STL stream + + //- Access to underlying std::ostream + virtual ostream& stdStream() + { + return os_; + } + + //- Const access to underlying std::ostream + virtual const ostream& stdStream() const + { + return os_; + } + + // Print //- Print description of IOstream to Ostream diff --git a/src/OpenFOAM/db/IOstreams/StringStreams/IStringStream.H b/src/OpenFOAM/db/IOstreams/StringStreams/IStringStream.H index d7e9995e9b..5b242537e5 100644 --- a/src/OpenFOAM/db/IOstreams/StringStreams/IStringStream.H +++ b/src/OpenFOAM/db/IOstreams/StringStreams/IStringStream.H @@ -97,7 +97,7 @@ public: ~IStringStream() { - delete &dynamic_cast(stream()); + delete &dynamic_cast(stdStream()); } @@ -108,7 +108,10 @@ public: //- Return the string string str() const { - return dynamic_cast(stream()).str(); + return dynamic_cast + ( + stdStream() + ).str(); } diff --git a/src/OpenFOAM/db/IOstreams/StringStreams/OStringStream.H b/src/OpenFOAM/db/IOstreams/StringStreams/OStringStream.H index 8f76748292..9336daa02c 100644 --- a/src/OpenFOAM/db/IOstreams/StringStreams/OStringStream.H +++ b/src/OpenFOAM/db/IOstreams/StringStreams/OStringStream.H @@ -83,7 +83,7 @@ public: ( dynamic_cast ( - oss.stream() + oss.stdStream() ).str() ) ), @@ -98,7 +98,7 @@ public: ~OStringStream() { - delete &dynamic_cast(stream()); + delete &dynamic_cast(stdStream()); } @@ -109,7 +109,10 @@ public: //- Return the string string str() const { - return dynamic_cast(stream()).str(); + return dynamic_cast + ( + stdStream() + ).str(); } @@ -119,9 +122,9 @@ public: void rewind() { # if __GNUC__ < 4 && __GNUC_MINOR__ < 4 - stream().rdbuf()->pubsetbuf(" ", 1); + stdStream().rdbuf()->pubsetbuf(" ", 1); # else - stream().rdbuf()->pubseekpos(0); + stdStream().rdbuf()->pubseekpos(0); # endif } diff --git a/src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H b/src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H index 00b72fd7bf..7bc2d8abbd 100644 --- a/src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H +++ b/src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H @@ -170,7 +170,7 @@ public: ~OSHA1stream() { - delete &dynamic_cast(stream()); + delete &dynamic_cast(stdStream()); } @@ -181,7 +181,7 @@ public: //- Full access to the sha1 Foam::SHA1& sha1() { - return dynamic_cast(stream()).sha1(); + return dynamic_cast(stdStream()).sha1(); } //- Return SHA1::Digest for the data processed until now diff --git a/src/conversion/ensight/file/ensightFile.C b/src/conversion/ensight/file/ensightFile.C index 095d2659f8..af0ad554e8 100644 --- a/src/conversion/ensight/file/ensightFile.C +++ b/src/conversion/ensight/file/ensightFile.C @@ -91,7 +91,7 @@ Foam::Ostream& Foam::ensightFile::write std::streamsize count ) { - stream().write(buf, count); + stdStream().write(buf, count); return *this; } @@ -126,7 +126,7 @@ Foam::Ostream& Foam::ensightFile::write(const string& value) } else { - stream() << buf; + stdStream() << buf; } return *this; @@ -147,8 +147,8 @@ Foam::Ostream& Foam::ensightFile::write(const label value) } else { - stream().width(10); - stream() << value; + stdStream().width(10); + stdStream() << value; } return *this; @@ -173,8 +173,8 @@ Foam::Ostream& Foam::ensightFile::write } else { - stream().width(fieldWidth); - stream() << value; + stdStream().width(fieldWidth); + stdStream() << value; } return *this; @@ -195,8 +195,8 @@ Foam::Ostream& Foam::ensightFile::write(const scalar value) } else { - stream().width(12); - stream() << value; + stdStream().width(12); + stdStream() << value; } return *this; @@ -207,7 +207,7 @@ void Foam::ensightFile::newline() { if (format() == IOstream::ASCII) { - stream() << nl; + stdStream() << nl; } }