STYLE: relocate stream allocators to Detail namespace

This commit is contained in:
Mark Olesen
2018-04-13 10:24:22 +02:00
parent 4cf932b230
commit 53ae09ad04
12 changed files with 118 additions and 98 deletions

View File

@ -37,7 +37,7 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname) Foam::Detail::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
: :
allocatedPtr_(nullptr), allocatedPtr_(nullptr),
compression_(IOstream::UNCOMPRESSED) compression_(IOstream::UNCOMPRESSED)
@ -61,7 +61,6 @@ Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
} }
delete allocatedPtr_; delete allocatedPtr_;
allocatedPtr_ = new igzstream((pathname + ".gz").c_str()); allocatedPtr_ = new igzstream((pathname + ".gz").c_str());
if (allocatedPtr_->good()) if (allocatedPtr_->good())
@ -74,7 +73,7 @@ Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::IFstreamAllocator::~IFstreamAllocator() Foam::Detail::IFstreamAllocator::~IFstreamAllocator()
{ {
deallocate(); deallocate();
} }
@ -82,7 +81,7 @@ Foam::IFstreamAllocator::~IFstreamAllocator()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::IFstreamAllocator::deallocate() void Foam::Detail::IFstreamAllocator::deallocate()
{ {
if (allocatedPtr_) if (allocatedPtr_)
{ {
@ -101,7 +100,7 @@ Foam::IFstream::IFstream
versionNumber version versionNumber version
) )
: :
IFstreamAllocator(pathname), Detail::IFstreamAllocator(pathname),
ISstream ISstream
( (
*allocatedPtr_, *allocatedPtr_,
@ -135,12 +134,6 @@ Foam::IFstream::IFstream
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::IFstream::~IFstream()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
std::istream& Foam::IFstream::stdStream() std::istream& Foam::IFstream::stdStream()

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,7 @@ Class
Foam::IFstream Foam::IFstream
Description Description
Input from file stream, using a ISstream Input from file stream, using an ISstream
SourceFiles SourceFiles
IFstream.C IFstream.C
@ -47,8 +47,11 @@ using std::ifstream;
namespace Foam namespace Foam
{ {
namespace Detail
{
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class IFstreamAllocator Declaration Class Detail::IFstreamAllocator Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
//- A std::istream with the ability to handle compressed files //- A std::istream with the ability to handle compressed files
@ -82,6 +85,8 @@ protected:
}; };
} // end namespace Detail
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class IFstream Declaration Class IFstream Declaration
@ -89,7 +94,7 @@ protected:
class IFstream class IFstream
: :
public IFstreamAllocator, public Detail::IFstreamAllocator,
public ISstream public ISstream
{ {
public: public:
@ -110,18 +115,18 @@ public:
//- Destructor //- Destructor
~IFstream(); ~IFstream() = default;
// Member Functions // Member Functions
// Access // Access
//- Read/write access to the name of the stream //- Read/write access to the name of the stream
using ISstream::name; using ISstream::name;
// STL stream // STL stream
//- Access to underlying std::istream //- Access to underlying std::istream
virtual std::istream& stdStream(); virtual std::istream& stdStream();
@ -133,17 +138,17 @@ public:
virtual void rewind(); virtual void rewind();
// Print // Print
//- Print description of IOstream to Ostream //- Print description of IOstream to Ostream
virtual void print(Ostream& os) const; virtual void print(Ostream& os) const;
// Member operators // Member Operators
//- Return a non-const reference to const IFstream //- Return a non-const reference to const IFstream
// Needed for read-constructors where the stream argument is temporary: // Needed for read-constructors where the stream argument is temporary:
// e.g. thing thisThing(IFstream("thingFileName")()); // e.g. thing thisThing(IFstream("fileName")());
IFstream& operator()() const; IFstream& operator()() const;
}; };

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -34,10 +34,9 @@ namespace Foam
defineTypeNameAndDebug(OFstream, 0); defineTypeNameAndDebug(OFstream, 0);
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::OFstreamAllocator::OFstreamAllocator Foam::Detail::OFstreamAllocator::OFstreamAllocator
( (
const fileName& pathname, const fileName& pathname,
IOstream::compressionType compression, IOstream::compressionType compression,
@ -100,13 +99,13 @@ Foam::OFstreamAllocator::OFstreamAllocator
} }
Foam::OFstreamAllocator::~OFstreamAllocator() Foam::Detail::OFstreamAllocator::~OFstreamAllocator()
{ {
deallocate(); deallocate();
} }
void Foam::OFstreamAllocator::deallocate() void Foam::Detail::OFstreamAllocator::deallocate()
{ {
if (allocatedPtr_) if (allocatedPtr_)
{ {
@ -127,7 +126,7 @@ Foam::OFstream::OFstream
const bool append const bool append
) )
: :
OFstreamAllocator(pathname, compression, append), Detail::OFstreamAllocator(pathname, compression, append),
OSstream OSstream
( (
*allocatedPtr_, *allocatedPtr_,
@ -160,12 +159,6 @@ Foam::OFstream::OFstream
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::OFstream::~OFstream()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
std::ostream& Foam::OFstream::stdStream() std::ostream& Foam::OFstream::stdStream()

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,7 @@ Class
Foam::OFstream Foam::OFstream
Description Description
Output to file stream, using a OSstream Output to file stream, using an OSstream
SourceFiles SourceFiles
OFstream.C OFstream.C
@ -47,8 +47,11 @@ using std::ofstream;
namespace Foam namespace Foam
{ {
namespace Detail
{
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class OFstreamAllocator Declaration Class Detail::OFstreamAllocator Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
//- A std::ostream with the ability to handle compressed files //- A std::ostream with the ability to handle compressed files
@ -84,6 +87,8 @@ protected:
}; };
} // end namespace Detail
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class OFstream Declaration Class OFstream Declaration
@ -91,7 +96,7 @@ protected:
class OFstream class OFstream
: :
public OFstreamAllocator, public Detail::OFstreamAllocator,
public OSstream public OSstream
{ {
public: public:
@ -114,18 +119,18 @@ public:
//- Destructor //- Destructor
~OFstream(); ~OFstream() = default;
// Member functions // Member functions
// Access // Access
//- Read/write access to the name of the stream //- Read/write access to the name of the stream
using OSstream::name; using OSstream::name;
// STL stream // STL stream
//- Access to underlying std::ostream //- Access to underlying std::ostream
virtual std::ostream& stdStream(); virtual std::ostream& stdStream();
@ -134,7 +139,7 @@ public:
virtual const std::ostream& stdStream() const; virtual const std::ostream& stdStream() const;
// Print // Print
//- Print description of IOstream to Ostream //- Print description of IOstream to Ostream
void print(Ostream& os) const; void print(Ostream& os) const;

View File

@ -44,8 +44,11 @@ SourceFiles
namespace Foam namespace Foam
{ {
namespace Detail
{
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class StringStreamAllocator Declaration Class Detail::StringStreamAllocator Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
//- Allocator for variants of a std stringstream //- Allocator for variants of a std stringstream
@ -96,6 +99,8 @@ public:
} }
}; };
} // end of namespace Detail
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class IStringStream Declaration Class IStringStream Declaration
@ -104,10 +109,10 @@ public:
//- Input from string buffer, using a ISstream //- Input from string buffer, using a ISstream
class IStringStream class IStringStream
: :
public StringStreamAllocator<std::istringstream>, public Detail::StringStreamAllocator<std::istringstream>,
public ISstream public ISstream
{ {
typedef StringStreamAllocator<std::istringstream> allocator_type; typedef Detail::StringStreamAllocator<std::istringstream> allocator_type;
public: public:
@ -181,10 +186,10 @@ public:
//- Output to string buffer, using a OSstream //- Output to string buffer, using a OSstream
class OStringStream class OStringStream
: :
public StringStreamAllocator<std::ostringstream>, public Detail::StringStreamAllocator<std::ostringstream>,
public OSstream public OSstream
{ {
typedef StringStreamAllocator<std::ostringstream> allocator_type; typedef Detail::StringStreamAllocator<std::ostringstream> allocator_type;
public: public:

View File

@ -27,9 +27,6 @@ Class
Description Description
An output stream for calculating SHA1 digests. An output stream for calculating SHA1 digests.
SourceFiles
OSHA1stream.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef OSHA1stream_H #ifndef OSHA1stream_H
@ -43,9 +40,6 @@ SourceFiles
namespace Foam namespace Foam
{ {
class osha1stream;
class OSHA1stream;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class osha1stream Declaration Class osha1stream Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -65,36 +59,30 @@ class osha1stream
SHA1 sha1_; SHA1 sha1_;
protected: protected:
// Protected members
//- Put sequence of characters
virtual std::streamsize xsputn(const char* str, std::streamsize n)
{
sha1_.append(str, n);
return n;
}
//- Put sequence of characters
virtual std::streamsize xsputn(const char* s, std::streamsize n)
{
sha1_.append(s, n);
return n;
}
public: public:
// Constructors //- Construct null
sha1buf()
//- Construct null {}
sha1buf()
{}
// Public member functions //- Full access to the sha1
inline SHA1& sha1()
//- Full access to the sha1 {
inline SHA1& sha1() return sha1_;
{ }
return sha1_;
}
}; };
// Private data // Private Data
//- Reference to the underlying buffer //- Reference to the underlying buffer
sha1buf buf_; sha1buf buf_;
@ -127,8 +115,11 @@ public:
}; };
namespace Detail
{
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class OSHA1streamAllocator Declaration Class Detail::OSHA1streamAllocator Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
//- Allocator for an osha1stream //- Allocator for an osha1stream
@ -136,7 +127,7 @@ class OSHA1streamAllocator
{ {
protected: protected:
// Protected data // Protected Data
typedef osha1stream stream_type; typedef osha1stream stream_type;
@ -179,6 +170,8 @@ public:
}; };
} // end of namespace Detail
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class OSHA1stream Declaration Class OSHA1stream Declaration
@ -187,17 +180,17 @@ public:
//- The output stream for calculating SHA1 digests //- The output stream for calculating SHA1 digests
class OSHA1stream class OSHA1stream
: :
public OSHA1streamAllocator, public Detail::OSHA1streamAllocator,
public OSstream public OSstream
{ {
typedef OSHA1streamAllocator allocator_type; typedef Detail::OSHA1streamAllocator allocator_type;
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- No copy construct
OSHA1stream(const OSHA1stream&) = delete; OSHA1stream(const OSHA1stream&) = delete;
//- Disallow default bitwise assignment //- No copy assignment
void operator=(const OSHA1stream&) = delete; void operator=(const OSHA1stream&) = delete;
public: public:

View File

@ -110,6 +110,7 @@ Foam::base64Layer::base64Layer(std::ostream& os)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::base64Layer::~base64Layer() Foam::base64Layer::~base64Layer()
{ {
close(); close();

View File

@ -47,8 +47,11 @@ See Also
namespace Foam namespace Foam
{ {
namespace Detail
{
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class IListStreamAllocator Declaration Class Detail::IListStreamAllocator Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
//- An stream/stream-buffer input allocator with List storage //- An stream/stream-buffer input allocator with List storage
@ -118,6 +121,8 @@ public:
} }
}; };
} // end namespace Detail
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class IListStream Declaration Class IListStream Declaration
@ -126,10 +131,10 @@ public:
//- An ISstream with internal List storage //- An ISstream with internal List storage
class IListStream class IListStream
: :
public IListStreamAllocator, public Detail::IListStreamAllocator,
public ISstream public ISstream
{ {
typedef IListStreamAllocator allocator_type; typedef Detail::IListStreamAllocator allocator_type;
public: public:

View File

@ -134,8 +134,11 @@ public:
}; };
namespace Detail
{
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class OCountStreamAllocator Declaration Class Detail::OCountStreamAllocator Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
//- An stream/stream-buffer allocator for counting //- An stream/stream-buffer allocator for counting
@ -189,6 +192,8 @@ public:
} }
}; };
} // end of namespace Detail
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class OCountStream Declaration Class OCountStream Declaration
@ -197,10 +202,10 @@ public:
//- An output stream for calculating byte counts //- An output stream for calculating byte counts
class OCountStream class OCountStream
: :
public OCountStreamAllocator, public Detail::OCountStreamAllocator,
public OSstream public OSstream
{ {
typedef OCountStreamAllocator allocator_type; typedef Detail::OCountStreamAllocator allocator_type;
public: public:
@ -225,7 +230,7 @@ public:
{} {}
// Member functions // Member Functions
//- Rewind the stream, reset the count, clearing any old errors //- Rewind the stream, reset the count, clearing any old errors
virtual void rewind() virtual void rewind()

View File

@ -53,8 +53,11 @@ See Also
namespace Foam namespace Foam
{ {
namespace Detail
{
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class OListStreamAllocator Declaration Class Detail::OListStreamAllocator Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
//- An stream/stream-buffer output allocator with DynamicList-like storage //- An stream/stream-buffer output allocator with DynamicList-like storage
@ -358,6 +361,8 @@ public:
} }
}; };
} // end of namespace Detail
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class OListStream Declaration Class OListStream Declaration
@ -366,10 +371,10 @@ public:
//- An OSstream attached to a List //- An OSstream attached to a List
class OListStream class OListStream
: :
public OListStreamAllocator, public Detail::OListStreamAllocator,
public OSstream public OSstream
{ {
typedef OListStreamAllocator allocator_type; typedef Detail::OListStreamAllocator allocator_type;
public: public:

View File

@ -109,8 +109,11 @@ public:
}; };
namespace Detail
{
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class UIListStreamAllocator Declaration Class Detail::UIListStreamAllocator Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
//- An stream/stream-buffer input allocator for a externally allocated list //- An stream/stream-buffer input allocator for a externally allocated list
@ -188,6 +191,8 @@ public:
} }
}; };
} // end of namespace Detail
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class UIListStream Declaration Class UIListStream Declaration
@ -195,10 +200,10 @@ public:
class UIListStream class UIListStream
: :
public UIListStreamAllocator, public Detail::UIListStreamAllocator,
public ISstream public ISstream
{ {
typedef UIListStreamAllocator allocator_type; typedef Detail::UIListStreamAllocator allocator_type;
public: public:
@ -260,7 +265,7 @@ public:
{} {}
// Member functions // Member Functions
//- Return the current get position in the buffer //- Return the current get position in the buffer
std::streampos pos() const std::streampos pos() const
@ -279,7 +284,7 @@ public:
virtual void print(Ostream& os) const; virtual void print(Ostream& os) const;
// Member operators // Member Operators
//- A non-const reference to const Istream //- A non-const reference to const Istream
// Needed for read-constructors where the stream argument is temporary // Needed for read-constructors where the stream argument is temporary

View File

@ -90,8 +90,11 @@ See Also
namespace Foam namespace Foam
{ {
namespace Detail
{
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class UOListStreamAllocator Declaration Class Detail::UOListStreamAllocator Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
//- An stream/stream-buffer allocator for external buffers //- An stream/stream-buffer allocator for external buffers
@ -161,6 +164,8 @@ public:
} }
}; };
} // end of namespace Detail
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class UOListStream Declaration Class UOListStream Declaration
@ -169,10 +174,10 @@ public:
//- An OSstream attached to an unallocated external buffer //- An OSstream attached to an unallocated external buffer
class UOListStream class UOListStream
: :
public UOListStreamAllocator, public Detail::UOListStreamAllocator,
public OSstream public OSstream
{ {
typedef UOListStreamAllocator allocator_type; typedef Detail::UOListStreamAllocator allocator_type;
public: public:
@ -241,7 +246,7 @@ public:
{} {}
// Member functions // Member Functions
//- Rewind the stream, clearing any old errors //- Rewind the stream, clearing any old errors
virtual void rewind() virtual void rewind()