From e8cf2a2c623ed31a30332de0e714906fb417e180 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Fri, 19 Feb 2021 12:18:19 +0100 Subject: [PATCH] ENH: more consistent use of IOstreamOption - improves interface and data consistency. Older signatures are still active (via the Foam_IOstream_extras define). - refine internals for IOstreamOption streamFormat, versionNumber ENH: improve data alignment for IOstream and IOobject - fit sizeof label/scalar into unsigned char STYLE: remove dead code --- .../test/primitives/Test-primitives.C | 4 +- applications/test/sizeof/Test-sizeof.C | 4 +- src/OpenFOAM/db/IOobject/IOobject.C | 44 +++--- src/OpenFOAM/db/IOobject/IOobject.H | 29 ++-- src/OpenFOAM/db/IOobject/IOobjectI.H | 10 +- src/OpenFOAM/db/IOobject/IOobjectReadHeader.C | 12 +- .../decomposedBlockData/decomposedBlockData.C | 49 +++--- .../decomposedBlockData/decomposedBlockData.H | 5 +- src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C | 4 +- src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H | 4 +- src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H | 8 +- .../db/IOstreams/Fstreams/masterOFstream.C | 8 +- .../db/IOstreams/Fstreams/masterOFstream.H | 12 +- .../db/IOstreams/IOstreams/IOstream.H | 142 +++++++++--------- .../db/IOstreams/IOstreams/IOstreamOption.H | 47 +++--- src/OpenFOAM/db/IOstreams/IOstreams/Istream.H | 10 +- src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H | 8 +- src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C | 9 +- src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H | 8 +- src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C | 7 +- src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H | 9 +- .../db/IOstreams/Pstreams/PstreamBuffers.C | 9 +- .../db/IOstreams/Pstreams/PstreamBuffers.H | 9 +- .../db/IOstreams/Pstreams/UIPstream.H | 6 +- .../db/IOstreams/Pstreams/UOPstream.C | 6 +- .../db/IOstreams/Pstreams/UOPstream.H | 4 +- src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H | 10 +- src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H | 10 +- .../db/IOstreams/Sstreams/prefixOSstream.H | 12 +- .../db/IOstreams/StringStreams/StringStream.H | 91 ++++++++--- src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C | 39 ++--- src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H | 132 +++++++++++++--- src/OpenFOAM/db/IOstreams/Tstreams/OTstream.C | 6 +- src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H | 28 ++-- .../db/IOstreams/hashes/OSHA1stream.H | 42 +++--- .../db/IOstreams/memory/IListStream.H | 64 ++++++-- .../db/IOstreams/memory/OCountStream.H | 24 ++- .../db/IOstreams/memory/OListStream.H | 72 +++++++-- .../db/IOstreams/memory/UIListStream.H | 102 +++++++++---- .../db/IOstreams/memory/UOListStream.H | 105 ++++++++++--- src/OpenFOAM/db/Time/TimeIO.C | 2 +- .../primitiveEntry/primitiveEntryIO.C | 5 +- src/OpenFOAM/db/regIOobject/regIOobject.H | 10 +- src/OpenFOAM/db/regIOobject/regIOobjectRead.C | 6 +- .../db/regIOobject/regIOobjectWrite.C | 47 +----- .../global/debug/simpleObjectRegistry.C | 4 +- .../collatedFileOperation/OFstreamCollator.C | 55 ++----- .../collatedFileOperation/OFstreamCollator.H | 51 +++---- .../collatedFileOperation.C | 30 ++-- .../collatedFileOperation.H | 14 +- .../hostCollatedFileOperation.H | 5 +- .../threadedCollatedOFstream.C | 8 +- .../threadedCollatedOFstream.H | 27 ++-- .../fileOperation/fileOperation.H | 4 +- .../masterUncollatedFileOperation.C | 10 +- .../masterUncollatedFileOperation.H | 12 +- .../uncollatedFileOperation.C | 4 +- .../uncollatedFileOperation.H | 6 +- .../tableReaders/csv/csvTableReader.C | 7 +- .../polyBoundaryMesh/polyBoundaryMesh.C | 2 +- .../primitives/functions/Function1/CSV/CSV.C | 7 +- src/Pstream/dummy/UIPread.C | 10 +- src/Pstream/mpi/UIPread.C | 6 +- src/conversion/ccm/reader/ccmReader.C | 8 +- src/conversion/ccm/reader/ccmReader.H | 7 +- src/conversion/ccm/reader/ccmReaderAux.C | 16 +- src/conversion/common/reader/meshReader.C | 10 +- src/conversion/common/reader/meshReader.H | 6 +- src/conversion/common/reader/meshReaderAux.C | 12 +- src/conversion/fire/FIREMeshReader.C | 2 +- .../ensight/read/ensightReadFile.C | 6 +- .../ensight/read/ensightReadFile.H | 6 +- src/fileFormats/fire/FIRECore.C | 2 +- src/fileFormats/obj/OBJstream.H | 10 +- .../readers/ensight/ensightSurfaceReader.H | 4 +- .../surfaceFormats/stl/STLsurfaceFormat.C | 10 +- .../surfaceFormats/stl/STLsurfaceFormat.H | 10 +- 77 files changed, 964 insertions(+), 681 deletions(-) diff --git a/applications/test/primitives/Test-primitives.C b/applications/test/primitives/Test-primitives.C index 0064400290e..1fe56e2ae9f 100644 --- a/applications/test/primitives/Test-primitives.C +++ b/applications/test/primitives/Test-primitives.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -346,7 +346,7 @@ int main(int argc, char *argv[]) is.setScalarByteSize(sizeof(otherType)); Info<< "Stream scalar-size (" - << is.scalarByteSize() << ") is native: " + << label(is.scalarByteSize()) << ") is native: " << Switch(is.checkScalarSize<otherType>()) << nl; diff --git a/applications/test/sizeof/Test-sizeof.C b/applications/test/sizeof/Test-sizeof.C index 78423b0e049..692531acab9 100644 --- a/applications/test/sizeof/Test-sizeof.C +++ b/applications/test/sizeof/Test-sizeof.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -38,6 +38,7 @@ Description #include "PstreamBuffers.H" #include "argList.H" #include "Time.H" +#include "IOobject.H" namespace Foam { @@ -132,6 +133,7 @@ int main(int argc, char *argv[]) cout<<"string:" << sizeof(Foam::string) << nl; } + cout<<"IOobject:" << sizeof(Foam::IOobject) << nl; cout<<"IOstream:" << sizeof(Foam::IOstream) << nl; cout<<"PstreamBuffers:" << sizeof(Foam::PstreamBuffers) << nl; cout<<"Time:" << sizeof(Foam::Time) << nl; diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index e25418fef3b..7b0928ebe6b 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -290,7 +290,8 @@ Foam::IOobject::IOobject const objectRegistry& registry, readOption ro, writeOption wo, - bool registerObject + bool registerObject, + bool globalObject ) : name_(name), @@ -298,14 +299,15 @@ Foam::IOobject::IOobject note_(), instance_(instance), local_(), - db_(registry), rOpt_(ro), wOpt_(wo), registerObject_(registerObject), - globalObject_(false), + globalObject_(globalObject), objState_(GOOD), - labelByteSize_(sizeof(label)), - scalarByteSize_(sizeof(scalar)) + sizeofLabel_(static_cast<unsigned char>(sizeof(label))), + sizeofScalar_(static_cast<unsigned char>(sizeof(scalar))), + + db_(registry) { if (objectRegistry::debug) { @@ -334,14 +336,15 @@ Foam::IOobject::IOobject note_(), instance_(instance), local_(local), - db_(registry), rOpt_(ro), wOpt_(wo), registerObject_(registerObject), globalObject_(globalObject), objState_(GOOD), - labelByteSize_(sizeof(label)), - scalarByteSize_(sizeof(scalar)) + sizeofLabel_(static_cast<unsigned char>(sizeof(label))), + sizeofScalar_(static_cast<unsigned char>(sizeof(scalar))), + + db_(registry) { if (objectRegistry::debug) { @@ -368,14 +371,15 @@ Foam::IOobject::IOobject note_(), instance_(), local_(), - db_(registry), rOpt_(ro), wOpt_(wo), registerObject_(registerObject), globalObject_(globalObject), objState_(GOOD), - labelByteSize_(sizeof(label)), - scalarByteSize_(sizeof(scalar)) + sizeofLabel_(static_cast<unsigned char>(sizeof(label))), + sizeofScalar_(static_cast<unsigned char>(sizeof(scalar))), + + db_(registry) { if (!fileNameComponents(path, instance_, local_, name_)) { @@ -405,14 +409,15 @@ Foam::IOobject::IOobject note_(io.note_), instance_(io.instance_), local_(io.local_), - db_(registry), rOpt_(io.rOpt_), wOpt_(io.wOpt_), registerObject_(io.registerObject_), globalObject_(io.globalObject_), objState_(io.objState_), - labelByteSize_(io.labelByteSize_), - scalarByteSize_(io.scalarByteSize_) + sizeofLabel_(io.sizeofLabel_), + sizeofScalar_(io.sizeofScalar_), + + db_(registry) {} @@ -427,14 +432,15 @@ Foam::IOobject::IOobject note_(io.note_), instance_(io.instance_), local_(io.local_), - db_(io.db_), rOpt_(io.rOpt_), wOpt_(io.wOpt_), registerObject_(io.registerObject_), globalObject_(io.globalObject_), objState_(io.objState_), - labelByteSize_(io.labelByteSize_), - scalarByteSize_(io.scalarByteSize_) + sizeofLabel_(io.sizeofLabel_), + sizeofScalar_(io.sizeofScalar_), + + db_(io.db_) {} @@ -566,8 +572,8 @@ void Foam::IOobject::operator=(const IOobject& io) wOpt_ = io.wOpt_; globalObject_ = io.globalObject_; objState_ = io.objState_; - labelByteSize_ = io.labelByteSize_; - scalarByteSize_ = io.scalarByteSize_; + sizeofLabel_ = io.sizeofLabel_; + sizeofScalar_ = io.sizeofScalar_; } diff --git a/src/OpenFOAM/db/IOobject/IOobject.H b/src/OpenFOAM/db/IOobject/IOobject.H index e8f35947f7e..409c5036908 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.H +++ b/src/OpenFOAM/db/IOobject/IOobject.H @@ -163,9 +163,6 @@ private: //- Local path component fileName local_; - //- Reference to the objectRegistry - const objectRegistry& db_; - //- Read option readOption rOpt_; @@ -181,11 +178,14 @@ private: //- IOobject state objectState objState_; - //- The label byte-size (could also be stored as byte) - unsigned short labelByteSize_; + //- The sizeof (label) in bytes, possibly read from the header + unsigned char sizeofLabel_; + + //- The sizeof (scalar) in bytes, possibly read from the header + unsigned char sizeofScalar_; - //- The scalar byte-size (could also be stored as byte) - unsigned short scalarByteSize_; + //- Reference to the objectRegistry + const objectRegistry& db_; protected: @@ -294,7 +294,8 @@ public: const objectRegistry& registry, readOption r=NO_READ, writeOption w=NO_WRITE, - bool registerObject=true + bool registerObject = true, + bool globalObject = false ); //- Construct from name, instance, local, registry, io options @@ -306,7 +307,7 @@ public: const objectRegistry& registry, readOption r=NO_READ, writeOption w=NO_WRITE, - bool registerObject=true, + bool registerObject = true, bool globalObject = false ); @@ -368,7 +369,7 @@ public: //- Return the local objectRegistry const objectRegistry& db() const; - //- Return time + //- Return Time associated with the objectRegistry const Time& time() const; //- Return name @@ -404,11 +405,11 @@ public: //- Is object same for all processors? inline bool& globalObject(); - //- The label byte-size, possibly read from the header - inline unsigned labelByteSize() const; + //- The sizeof (label) in bytes, possibly read from the header + inline unsigned labelByteSize() const noexcept; - //- The scalar byte-size, possibly read from the header - inline unsigned scalarByteSize() const; + //- The sizeof (scalar) in bytes, possibly read from the header + inline unsigned scalarByteSize() const noexcept; // Checks diff --git a/src/OpenFOAM/db/IOobject/IOobjectI.H b/src/OpenFOAM/db/IOobject/IOobjectI.H index 2c4f7a84f2e..345ca59dd6e 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectI.H +++ b/src/OpenFOAM/db/IOobject/IOobjectI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -133,15 +133,15 @@ inline bool& Foam::IOobject::globalObject() } -inline unsigned Foam::IOobject::labelByteSize() const +inline unsigned Foam::IOobject::labelByteSize() const noexcept { - return labelByteSize_; + return static_cast<unsigned>(sizeofLabel_); } -inline unsigned Foam::IOobject::scalarByteSize() const +inline unsigned Foam::IOobject::scalarByteSize() const noexcept { - return scalarByteSize_; + return static_cast<unsigned>(sizeofScalar_); } diff --git a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C index 7726a6d76a6..ed0ea688a48 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C @@ -84,22 +84,22 @@ bool Foam::IOobject::readHeader(Istream& is) // The note entry is optional headerDict.readIfPresent("note", note_); - labelByteSize_ = sizeof(label); - scalarByteSize_ = sizeof(scalar); + sizeofLabel_ = sizeof(label); + sizeofScalar_ = sizeof(scalar); // The arch information is optional string arch; if (headerDict.readIfPresent("arch", arch)) { unsigned val = foamVersion::labelByteSize(arch); - if (val) labelByteSize_ = val; + if (val) sizeofLabel_ = static_cast<unsigned char>(val); val = foamVersion::scalarByteSize(arch); - if (val) scalarByteSize_ = val; + if (val) sizeofScalar_ = static_cast<unsigned char>(val); } - is.setLabelByteSize(labelByteSize_); - is.setScalarByteSize(scalarByteSize_); + is.setLabelByteSize(sizeofLabel_); + is.setScalarByteSize(sizeofScalar_); } else { diff --git a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C index b4388efb1c6..89affe61e0c 100644 --- a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C +++ b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C @@ -186,8 +186,7 @@ bool Foam::decomposedBlockData::readMasterHeader(IOobject& io, Istream& is) void Foam::decomposedBlockData::writeHeader ( Ostream& os, - const IOstream::versionNumber version, - const IOstream::streamFormat format, + IOstreamOption streamOpt, const word& objectType, const string& note, const fileName& location, @@ -197,8 +196,8 @@ void Foam::decomposedBlockData::writeHeader IOobject::writeBanner(os) << "FoamFile" << nl << '{' << nl - << " version " << version << ';' << nl - << " format " << format << ';' << nl + << " version " << streamOpt.version() << ';' << nl + << " format " << streamOpt.format() << ';' << nl << " arch " << foamVersion::buildArch << ';' << nl; if (Pstream::parRun()) @@ -274,8 +273,8 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlock List<char> data(is); is.fatalCheck("read(Istream&) : reading entry"); - IOstream::versionNumber ver(IOstream::currentVersion); - IOstream::streamFormat fmt; + IOstreamOption::versionNumber ver(IOstreamOption::currentVersion); + IOstreamOption::streamFormat fmt; unsigned labelByteSize; unsigned scalarByteSize; { @@ -566,24 +565,24 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks //- Set stream properties from realIsPtr on master // Scatter master header info - string versionString; - label formatValue; + int verValue; + int fmtValue; unsigned labelByteSize; unsigned scalarByteSize; if (UPstream::master(comm)) { - versionString = realIsPtr().version().str(); - formatValue = static_cast<label>(realIsPtr().format()); + verValue = realIsPtr().version().canonical(); + fmtValue = static_cast<int>(realIsPtr().format()); labelByteSize = realIsPtr().labelByteSize(); scalarByteSize = realIsPtr().scalarByteSize(); } - Pstream::scatter(versionString); //, Pstream::msgType(), comm); - Pstream::scatter(formatValue); //, Pstream::msgType(), comm); + Pstream::scatter(verValue); //, Pstream::msgType(), comm); + Pstream::scatter(fmtValue); //, Pstream::msgType(), comm); Pstream::scatter(labelByteSize); //, Pstream::msgType(), comm); Pstream::scatter(scalarByteSize); //, Pstream::msgType(), comm); - realIsPtr().version(IOstream::versionNumber(versionString)); - realIsPtr().format(IOstream::streamFormat(formatValue)); + realIsPtr().version(IOstreamOption::versionNumber::canonical(verValue)); + realIsPtr().format(IOstreamOption::streamFormat(fmtValue)); realIsPtr().setLabelByteSize(labelByteSize); realIsPtr().setScalarByteSize(scalarByteSize); @@ -971,20 +970,27 @@ bool Foam::decomposedBlockData::writeData(Ostream& os) const const List<char>& data = *this; IOobject io(*this); + IOstreamOption streamOpt(os); + + int verValue; + int fmtValue; // Re-read my own data to find out the header information if (Pstream::master(comm_)) { UIListStream headerStream(data); io.readHeader(headerStream); + + verValue = headerStream.version().canonical(); + fmtValue = static_cast<int>(headerStream.format()); } // Scatter header information + Pstream::scatter(verValue, Pstream::msgType(), comm_); + Pstream::scatter(fmtValue, Pstream::msgType(), comm_); - string versionString(os.version().str()); - label formatValue(os.format()); - Pstream::scatter(versionString, Pstream::msgType(), comm_); - Pstream::scatter(formatValue, Pstream::msgType(), comm_); + streamOpt.version(IOstreamOption::versionNumber::canonical(verValue)); + streamOpt.format(IOstreamOption::streamFormat(fmtValue)); //word masterName(name()); //Pstream::scatter(masterName, Pstream::msgType(), comm_); @@ -999,11 +1005,10 @@ bool Foam::decomposedBlockData::writeData(Ostream& os) const if (!Pstream::master(comm_)) { - writeHeader + decomposedBlockData::writeHeader ( os, - IOstreamOption::versionNumber(versionString), - IOstreamOption::streamFormat(formatValue), + streamOpt, io.headerClassName(), io.note(), masterLocation, @@ -1074,7 +1079,7 @@ Foam::label Foam::decomposedBlockData::numBlocks(const fileName& fName) label nBlocks = 0; IFstream is(fName); - is.fatalCheck("decomposedBlockData::numBlocks(const fileName&)"); + is.fatalCheck(FUNCTION_NAME); if (!is.good()) { diff --git a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.H b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.H index 8e790bbc6bb..e56059b1a21 100644 --- a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.H +++ b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.H @@ -67,7 +67,7 @@ protected: const label comm_; - // Protected member functions + // Protected Member Functions //- Helper: determine number of processors whose recvSizes fits // ito maxBufferSize @@ -154,8 +154,7 @@ public: static void writeHeader ( Ostream& os, - const IOstream::versionNumber version, - const IOstream::streamFormat format, + IOstreamOption streamOpt, const word& objectType, const string& note, const fileName& location, diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C index 59e20b3530e..6e2916411bb 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C @@ -48,7 +48,7 @@ Foam::IFstream::IFstream Foam::ifstreamPointer(pathname), ISstream(*(ifstreamPointer::get()), pathname, streamOpt) { - IOstream::compression(ifstreamPointer::whichCompression()); + IOstreamOption::compression(ifstreamPointer::whichCompression()); setClosed(); @@ -73,7 +73,7 @@ Foam::IFstream::IFstream << "Cannot open empty file name" << Foam::endl; } - else if (IOstreamOption::COMPRESSED == IOstream::compression()) + else if (IOstreamOption::COMPRESSED == IOstreamOption::compression()) { InfoInFunction << "Decompressing " << (this->name() + ".gz") << Foam::endl; diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H index 1361725ec2b..d28d09d0305 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H +++ b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -76,7 +76,7 @@ public: ( const fileName& pathname, IOstreamOption::streamFormat fmt, - IOstreamOption::versionNumber ver = currentVersion + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion ) : IFstream(pathname, IOstreamOption(fmt, ver)) diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H index a9a7629d1a8..53b9689b455 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H +++ b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -81,12 +81,12 @@ public: ( const fileName& pathname, IOstreamOption::streamFormat fmt, - IOstreamOption::versionNumber ver = currentVersion, - IOstreamOption::compressionType comp = IOstreamOption::UNCOMPRESSED, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion, + IOstreamOption::compressionType cmp = IOstreamOption::UNCOMPRESSED, const bool append = false ) : - OFstream(pathname, IOstreamOption(fmt, comp, ver), append) + OFstream(pathname, IOstreamOption(fmt, ver, cmp), append) {} diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.C index d9a9e7a9d26..f6608a5b7c4 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -54,9 +54,7 @@ void Foam::masterOFstream::checkWrite OFstream os ( fName, - IOstream::BINARY, //format(), - version(), - compression_, + IOstreamOption(IOstreamOption::BINARY, version(), compression_), append_ ); if (!os.good()) @@ -189,7 +187,7 @@ Foam::masterOFstream::masterOFstream const bool valid ) : - OStringStream(streamOpt.format(), streamOpt.version()), + OStringStream(streamOpt), pathName_(pathName), compression_(streamOpt.compression()), append_(append), diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.H b/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.H index cfe0b868d74..85be1c4715b 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.H +++ b/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -57,7 +57,7 @@ class masterOFstream const fileName pathName_; - const IOstream::compressionType compression_; + const IOstreamOption::compressionType compression_; const bool append_; @@ -99,9 +99,9 @@ public: masterOFstream ( const fileName& pathname, - streamFormat fmt, - versionNumber ver = currentVersion, - compressionType comp = compressionType::UNCOMPRESSED, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion, + IOstreamOption::compressionType cmp = IOstreamOption::UNCOMPRESSED, const bool append = false, const bool valid = true ) @@ -109,7 +109,7 @@ public: masterOFstream ( pathname, - IOstreamOption(fmt, comp, ver), + IOstreamOption(fmt, ver, cmp), append, valid ) diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H index 796cdf6d7cd..1ae6996c4a1 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -64,6 +64,10 @@ using std::cin; using std::cout; using std::cerr; +// Additional constructors and methods (as per v2012 and earlier) +#define Foam_IOstream_extras +// COMPAT_OPENFOAM_ORG + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam @@ -84,8 +88,8 @@ public: //- Enumeration for stream open/closed state enum streamAccess : char { - CLOSED = 0, //!< stream not open - OPENED //!< stream is open + CLOSED = 0, //!< The stream is not open + OPENED //!< The stream is open }; @@ -102,15 +106,17 @@ protected: //- Name for any generic stream - normally treat as readonly static fileName staticName_; - streamAccess openClosed_; + //- Mirror of internal stream io state + std::ios_base::iostate ioState_; - ios_base::iostate ioState_; + //- The stream open/closed state + streamAccess openClosed_; - //- The label byte-size (could also be stored as byte) - unsigned short labelByteSize_; + //- The sizeof (label), possibly read from the header + unsigned char sizeofLabel_; - //- The scalar byte-size (could also be stored as byte) - unsigned short scalarByteSize_; + //- The sizeof (scalar), possibly read from the header + unsigned char sizeofScalar_; //- The file line label lineNumber_; @@ -121,27 +127,27 @@ protected: // Access //- Set stream opened - void setOpened() + void setOpened() noexcept { openClosed_ = OPENED; } //- Set stream closed - void setClosed() + void setClosed() noexcept { openClosed_ = CLOSED; } //- Set stream state - void setState(ios_base::iostate state) + void setState(std::ios_base::iostate state) noexcept { ioState_ = state; } - //- Set stream to be good - void setGood() + //- Set stream state to be good + void setGood() noexcept { - ioState_ = ios_base::iostate(0); + ioState_ = std::ios_base::iostate(0); } @@ -163,10 +169,10 @@ public: explicit IOstream(IOstreamOption streamOpt = IOstreamOption()) : IOstreamOption(streamOpt), + ioState_(std::ios_base::iostate(0)), openClosed_(CLOSED), - ioState_(ios_base::iostate(0)), - labelByteSize_(sizeof(label)), - scalarByteSize_(sizeof(scalar)), + sizeofLabel_(static_cast<unsigned char>(sizeof(label))), + sizeofScalar_(static_cast<unsigned char>(sizeof(scalar))), lineNumber_(0) { setBad(); @@ -175,12 +181,12 @@ public: //- Construct with format, version (compression) IOstream ( - streamFormat fmt, - versionNumber ver, - compressionType comp = compressionType::UNCOMPRESSED + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver, + IOstreamOption::compressionType cmp = IOstreamOption::UNCOMPRESSED ) : - IOstream(IOstreamOption(fmt, comp, ver)) + IOstream(IOstreamOption(fmt, ver, cmp)) {} @@ -209,50 +215,50 @@ public: // Generate a FatalIOError when an error has occurred. bool fatalCheck(const char* operation) const; - //- Return true if stream has been opened - bool opened() const + //- True if stream has been opened + bool opened() const noexcept { return openClosed_ == OPENED; } - //- Return true if stream is closed - bool closed() const + //- True if stream is closed + bool closed() const noexcept { return openClosed_ == CLOSED; } - //- Return true if next operation might succeed - bool good() const + //- True if next operation might succeed + bool good() const noexcept { return ioState_ == 0; } - //- Return true if end of input seen - bool eof() const + //- True if end of input seen + bool eof() const noexcept { - return ioState_ & ios_base::eofbit; + return ioState_ & std::ios_base::eofbit; } - //- Return true if next operation will fail - bool fail() const + //- True if next operation will fail + bool fail() const noexcept { - return ioState_ & (ios_base::badbit | ios_base::failbit); + return ioState_ & (std::ios_base::badbit | std::ios_base::failbit); } - //- Return true if stream is corrupted - bool bad() const + //- True if stream is corrupted + bool bad() const noexcept { - return ioState_ & ios_base::badbit; + return ioState_ & std::ios_base::badbit; } //- Return true if the stream has not failed - explicit operator bool() const + explicit operator bool() const noexcept { return !fail(); } //- Return true if the stream has failed - bool operator!() const + bool operator!() const noexcept { return fail(); } @@ -260,28 +266,28 @@ public: // Element sizes (precision) - //- The label byte-size associated with the stream - unsigned labelByteSize() const + //- The sizeof (label) in bytes associated with the stream + unsigned labelByteSize() const noexcept { - return labelByteSize_; + return static_cast<unsigned>(sizeofLabel_); } - //- The scalar byte-size associated with the stream - unsigned scalarByteSize() const + //- The sizeof (scalar) in bytes associated with the stream + unsigned scalarByteSize() const noexcept { - return scalarByteSize_; + return static_cast<unsigned>(sizeofScalar_); } - //- Set the label byte-size associated with the stream - void setLabelByteSize(unsigned nbytes) + //- Set the sizeof (label) in bytes associated with the stream + void setLabelByteSize(unsigned nbytes) noexcept { - labelByteSize_ = nbytes; + sizeofLabel_ = static_cast<unsigned char>(nbytes); } - //- Set the scalar byte-size associated with the stream - void setScalarByteSize(unsigned nbytes) + //- Set the sizeof (scalar) in bytes associated with the stream + void setScalarByteSize(unsigned nbytes) noexcept { - scalarByteSize_ = nbytes; + sizeofScalar_ = static_cast<unsigned char>(nbytes); } @@ -289,38 +295,38 @@ public: //- is the same as the given type template<class T = label> typename std::enable_if<std::is_integral<T>::value, bool>::type - checkLabelSize() const + checkLabelSize() const noexcept { - return labelByteSize_ == sizeof(T); + return sizeofLabel_ == sizeof(T); } //- Check if the scalar byte-size associated with the stream //- is the same as the given type template<class T = scalar> typename std::enable_if<std::is_floating_point<T>::value, bool>::type - checkScalarSize() const + checkScalarSize() const noexcept { - return scalarByteSize_ == sizeof(T); + return sizeofScalar_ == sizeof(T); } // Stream State Functions //- Const access to the current stream line number - label lineNumber() const + label lineNumber() const noexcept { return lineNumber_; } //- Non-const access to the current stream line number - label& lineNumber() + label& lineNumber() noexcept { return lineNumber_; } //- Set the stream line number // \return the previous value - label lineNumber(const label num) + label lineNumber(const label num) noexcept { const label old(lineNumber_); lineNumber_ = num; @@ -331,36 +337,36 @@ public: virtual ios_base::fmtflags flags() const = 0; //- Return the default precision - static unsigned int defaultPrecision() + static unsigned int defaultPrecision() noexcept { return precision_; } //- Reset the default precision // \return the previous value - static unsigned int defaultPrecision(unsigned int prec) + static unsigned int defaultPrecision(unsigned int prec) noexcept { unsigned int old(precision_); precision_ = prec; return old; } - //- Set stream to have reached eof - void setEof() + //- Set stream state as reached 'eof' + void setEof() noexcept { - ioState_ |= ios_base::eofbit; + ioState_ |= std::ios_base::eofbit; } - //- Set stream to have failed - void setFail() + //- Set stream state as 'failed' + void setFail() noexcept { - ioState_ |= ios_base::failbit; + ioState_ |= std::ios_base::failbit; } - //- Set stream to be bad + //- Set stream state to be 'bad' void setBad() { - ioState_ |= ios_base::badbit; + ioState_ |= std::ios_base::badbit; } //- Set flags of stream diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.H b/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.H index 84b7df0036d..b1ae05ac4fa 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -123,39 +123,36 @@ public: // Member Functions - //- Compare differences in the versions - // Negative when 'this' is less than other. - // Positive when 'this' is greater than other. - int compare(const versionNumber& other) const noexcept + //- A string representation as major.minor + std::string str() const { - return number_ - other.number_; + return + ( + std::to_string(int(number_ / 10)) // major + + '.' + + std::to_string(int(number_ % 10)) // minor + ); } - //- The canonical major/minor pair as an integer value. - int canonical() noexcept + //- From version to canonical integer value + int canonical() const noexcept { return number_; } - //- Return the major version number. - int getMajor() const noexcept - { - return int(number_ / 10); - } - - //- Return the minor version number - int getMinor() const noexcept + //- From canonical integer value to version + static versionNumber canonical(int verNum) noexcept { - return int(number_ % 10); + // Split into major/minor + return versionNumber(int(verNum / 10), int(verNum % 10)); } - //- A string representation of major.minor - std::string str() const + //- Compare differences in the versions + // Negative when 'this' is less than other. + // Positive when 'this' is greater than other. + int compare(const versionNumber& other) const noexcept { - return - std::to_string(getMajor()) - + '.' - + std::to_string(getMinor()); + return number_ - other.number_; } }; @@ -364,6 +361,8 @@ public: }; +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + //- Output format type as text string (ascii | binary) Ostream& operator<<(Ostream& os, const IOstreamOption::streamFormat& fmt); @@ -371,6 +370,8 @@ Ostream& operator<<(Ostream& os, const IOstreamOption::streamFormat& fmt); Ostream& operator<<(Ostream& os, const IOstreamOption::versionNumber& ver); +// * * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * // + // Comparison Operators //- Version number equality diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H index b01dec6bff8..051db3781e4 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -96,12 +96,12 @@ public: //- Construct with format, version (compression) explicit Istream ( - streamFormat fmt, - versionNumber ver = currentVersion, - compressionType comp = compressionType::UNCOMPRESSED + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion, + IOstreamOption::compressionType cmp = IOstreamOption::UNCOMPRESSED ) : - Istream(IOstreamOption(fmt, comp, ver)) + Istream(IOstreamOption(fmt, ver, cmp)) {} diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H index e27dcc0c6ad..6f0b87e6271 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H @@ -96,12 +96,12 @@ public: //- Construct with format, version (compression) explicit Ostream ( - streamFormat fmt, - versionNumber ver = currentVersion, - compressionType comp = compressionType::UNCOMPRESSED + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion, + IOstreamOption::compressionType cmp = IOstreamOption::UNCOMPRESSED ) : - Ostream(IOstreamOption(fmt, comp, ver)) + Ostream(IOstreamOption(fmt, ver, cmp)) {} diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C index ef0fd33d608..db80b49e8ad 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2013 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,8 +37,8 @@ Foam::IPstream::IPstream const label bufSize, const int tag, const label comm, - streamFormat format, - versionNumber version + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver ) : Pstream(commsType, bufSize), @@ -50,8 +51,8 @@ Foam::IPstream::IPstream tag, // tag comm, false, // do not clear buf_ if at end - format, - version + fmt, + ver ), externalBufPosition_(0) {} diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H index dd1b0909194..fe42f3c2a25 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2013 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -64,7 +65,7 @@ public: // Constructors //- Construct given process index to read from and optional buffer size, - // read format and IO version + //- read format and IO version IPstream ( const commsTypes commsType, @@ -72,10 +73,9 @@ public: const label bufSize = 0, const int tag = UPstream::msgType(), const label comm = UPstream::worldComm, - streamFormat format=BINARY, - versionNumber version=currentVersion + IOstreamOption::streamFormat fmt = IOstreamOption::BINARY, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion ); - }; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C index c27649d77c6..ee1322fdc09 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2013 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,12 +37,12 @@ Foam::OPstream::OPstream const label bufSize, const int tag, const label comm, - streamFormat format, - versionNumber version + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver ) : Pstream(commsType, bufSize), - UOPstream(commsType, toProcNo, buf_, tag, comm, true, format, version) + UOPstream(commsType, toProcNo, buf_, tag, comm, true, fmt, ver) {} diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H index 52d297a69a5..575cb048bac 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2013 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,13 +56,12 @@ class OPstream public Pstream, public UOPstream { - public: // Constructors //- Construct given process index to send to and optional buffer size, - // write format and IO version + //- write format and IO version OPstream ( const commsTypes commsType, @@ -69,10 +69,9 @@ public: const label bufSize = 0, const int tag = UPstream::msgType(), const label comm = UPstream::worldComm, - streamFormat format=BINARY, - versionNumber version=currentVersion + IOstreamOption::streamFormat fmt = IOstreamOption::BINARY, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion ); - }; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C index cd5cb39a85c..117e7f505d7 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,15 +40,15 @@ Foam::PstreamBuffers::PstreamBuffers const UPstream::commsTypes commsType, const int tag, const label comm, - IOstream::streamFormat format, - IOstream::versionNumber version + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver ) : commsType_(commsType), tag_(tag), comm_(comm), - format_(format), - version_(version), + format_(fmt), + version_(ver), sendBuf_(UPstream::nProcs(comm)), recvBuf_(UPstream::nProcs(comm)), recvBufPos_(UPstream::nProcs(comm), 0), diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H index df574758242..072ce891da8 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -99,9 +100,9 @@ class PstreamBuffers const label comm_; - const IOstream::streamFormat format_; + const IOstreamOption::streamFormat format_; - const IOstream::versionNumber version_; + const IOstreamOption::versionNumber version_; //- Send buffer List<DynamicList<char>> sendBuf_; @@ -130,8 +131,8 @@ public: const UPstream::commsTypes commsType, const int tag = UPstream::msgType(), const label comm = UPstream::worldComm, - IOstream::streamFormat format=IOstream::BINARY, - IOstream::versionNumber version=IOstream::currentVersion + IOstreamOption::streamFormat vmt = IOstreamOption::BINARY, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion ); //- Destructor diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H index 508e3e8eb00..9a6b8e7ae81 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H @@ -101,7 +101,7 @@ public: // Constructors //- Construct given process index to read from and optional buffer size, - // read format and IO version + //- read format and IO version UIPstream ( const commsTypes commsType, @@ -111,8 +111,8 @@ public: const int tag = UPstream::msgType(), const label comm = UPstream::worldComm, const bool clearAtEnd = false, // destroy externalBuf if at end - streamFormat format=BINARY, - versionNumber version=currentVersion + IOstreamOption::streamFormat fmt = IOstreamOption::BINARY, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion ); //- Construct given buffers diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C index 82f72e866b4..f550056ca06 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C @@ -126,12 +126,12 @@ Foam::UOPstream::UOPstream const int tag, const label comm, const bool sendAtDestruct, - streamFormat format, - versionNumber version + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver ) : UPstream(commsType), - Ostream(format, version), + Ostream(fmt, ver), toProcNo_(toProcNo), sendBuf_(sendBuf), tag_(tag), diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H index 590a58b92ba..68393e97be4 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H @@ -113,8 +113,8 @@ public: const int tag = UPstream::msgType(), const label comm = UPstream::worldComm, const bool sendAtDestruct = true, - streamFormat format=BINARY, - versionNumber version=currentVersion + IOstreamOption::streamFormat fmt = IOstreamOption::BINARY, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion ); //- Construct given buffers diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H index eaa2a92420d..60206a4db57 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2012 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -103,12 +103,12 @@ public: ( std::istream& is, const string& streamName, - streamFormat fmt, - versionNumber ver = currentVersion, - compressionType comp = compressionType::UNCOMPRESSED + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion, + IOstreamOption::compressionType cmp = IOstreamOption::UNCOMPRESSED ) : - ISstream(is, streamName, IOstreamOption(fmt, comp, ver)) + ISstream(is, streamName, IOstreamOption(fmt, ver, cmp)) {} diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H index 20793f82cd1..1efaeca724d 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2014 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -90,12 +90,12 @@ public: ( std::ostream& os, const string& streamName, - streamFormat fmt, - versionNumber ver = currentVersion, - compressionType comp = compressionType::UNCOMPRESSED + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion, + IOstreamOption::compressionType cmp = IOstreamOption::UNCOMPRESSED ) : - OSstream(os, streamName, IOstreamOption(fmt, comp, ver)) + OSstream(os, streamName, IOstreamOption(fmt, ver, cmp)) {} diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.H index fea59bc2aa3..1cdf23ec0ef 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2014 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,7 +28,7 @@ Class Foam::prefixOSstream Description - Version of OSstream which prints a prefix on each line. + Version of OSstream that prints a prefix on each line. This is useful for running in parallel as it allows the processor number to be automatically prepended to each message line. @@ -85,12 +85,12 @@ public: ( std::ostream& os, const string& streamName, - streamFormat fmt, - versionNumber ver = currentVersion, - compressionType comp = compressionType::UNCOMPRESSED + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion, + IOstreamOption::compressionType cmp = IOstreamOption::UNCOMPRESSED ) : - prefixOSstream(os, streamName, IOstreamOption(fmt, comp, ver)) + prefixOSstream(os, streamName, IOstreamOption(fmt, ver, cmp)) {} diff --git a/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H b/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H index 49e23bc9b02..e27e2d7a06e 100644 --- a/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H +++ b/src/OpenFOAM/db/IOstreams/StringStreams/StringStream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -71,10 +71,7 @@ protected: // Constructors //- Default construct - StringStreamAllocator() - : - stream_() - {} + StringStreamAllocator() = default; //- Copy construct from string StringStreamAllocator(const std::string& s) @@ -107,7 +104,7 @@ public: Class IStringStream Declaration \*---------------------------------------------------------------------------*/ -//- Input from string buffer, using a ISstream +//- Input from string buffer, using a ISstream. Always UNCOMPRESSED. class IStringStream : public Detail::StringStreamAllocator<std::istringstream>, @@ -119,41 +116,36 @@ public: // Constructors - //- Default construct + //- Default construct or with specified stream option explicit IStringStream ( - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(), - ISstream(stream_, "input", format, version) + ISstream(stream_, "input", streamOpt.format(), streamOpt.version()) {} //- Construct from std::string explicit IStringStream ( const std::string& s, - streamFormat format=ASCII, - versionNumber version=currentVersion, - const Foam::string& name="input" + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(s), - ISstream(stream_, name, format, version) + ISstream(stream_, "input", streamOpt.format(), streamOpt.version()) {} //- Construct from char* explicit IStringStream ( const char* s, - streamFormat format=ASCII, - versionNumber version=currentVersion, - const Foam::string& name="input" + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(s), - ISstream(stream_, name, format, version) + ISstream(stream_, "input", streamOpt.format(), streamOpt.version()) {} //- Copy construct, copies content and format @@ -185,6 +177,44 @@ public: { return const_cast<IStringStream&>(*this); } + + + // Additional constructors and methods (as per v2012 and earlier) + #ifdef Foam_IOstream_extras + + //- Default construct + explicit IStringStream + ( + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + IStringStream(IOstreamOption(fmt, ver)) + {} + + //- Construct from std::string + IStringStream + ( + const std::string& s, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + IStringStream(s, IOstreamOption(fmt, ver)) + {} + + //- Construct from char* + IStringStream + ( + const char* s, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + IStringStream(s, IOstreamOption(fmt, ver)) + {} + + #endif /* Foam_IOstream_extras */ }; @@ -192,7 +222,7 @@ public: Class OStringStream Declaration \*---------------------------------------------------------------------------*/ -//- Output to string buffer, using a OSstream +//- Output to string buffer, using a OSstream. Always UNCOMPRESSED. class OStringStream : public Detail::StringStreamAllocator<std::ostringstream>, @@ -204,15 +234,14 @@ public: // Constructors - //- Default construct + //- Default construct or with specified stream option explicit OStringStream ( - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(), - OSstream(stream_, "output", format, version) + OSstream(stream_, "output", streamOpt.format(), streamOpt.version()) {} //- Copy construct, copies content and format @@ -241,6 +270,22 @@ public: //- Print stream description to Ostream virtual void print(Ostream& os) const; + + + // Older style, without stream option (including 2012 release) + #ifdef Foam_IOstream_extras + + //- Default construct + explicit OStringStream + ( + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + OStringStream(IOstreamOption(fmt, ver)) + {} + + #endif /* Foam_IOstream_extras */ }; diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C index 4736a1eb463..41876f5e2ae 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C @@ -55,10 +55,10 @@ Foam::label Foam::ITstream::parseStream(ISstream& is, tokenList& tokens) Foam::tokenList Foam::ITstream::parse ( const UList<char>& input, - streamFormat format + IOstreamOption streamOpt ) { - UIListStream is(input, format, IOstream::currentVersion); + UIListStream is(input, streamOpt); tokenList tokens; parseStream(is, tokens); @@ -69,16 +69,10 @@ Foam::tokenList Foam::ITstream::parse Foam::tokenList Foam::ITstream::parse ( const std::string& input, - streamFormat format + IOstreamOption streamOpt ) { - UIListStream is - ( - input.data(), - input.size(), - format, - IOstream::currentVersion - ); + UIListStream is(input.data(), input.size(), streamOpt); tokenList tokens; parseStream(is, tokens); @@ -89,10 +83,10 @@ Foam::tokenList Foam::ITstream::parse Foam::tokenList Foam::ITstream::parse ( const char* input, - streamFormat format + IOstreamOption streamOpt ) { - UIListStream is(input, strlen(input), format, IOstream::currentVersion); + UIListStream is(input, strlen(input), streamOpt); tokenList tokens; parseStream(is, tokens); @@ -141,16 +135,15 @@ Foam::ITstream::ITstream ( const string& name, const UList<char>& input, - streamFormat format, - versionNumber version + IOstreamOption streamOpt ) : - Istream(format, version), + Istream(streamOpt.format(), streamOpt.version()), tokenList(), name_(name), tokenIndex_(0) { - UIListStream is(input, format, version); + UIListStream is(input, streamOpt); parseStream(is, static_cast<tokenList&>(*this)); ITstream::rewind(); @@ -161,16 +154,15 @@ Foam::ITstream::ITstream ( const string& name, const std::string& input, - streamFormat format, - versionNumber version + IOstreamOption streamOpt ) : - Istream(format, version), + Istream(streamOpt.format(), streamOpt.version()), tokenList(), name_(name), tokenIndex_(0) { - UIListStream is(input.data(), input.size(), format, version); + UIListStream is(input.data(), input.size(), streamOpt); parseStream(is, static_cast<tokenList&>(*this)); ITstream::rewind(); @@ -181,16 +173,15 @@ Foam::ITstream::ITstream ( const string& name, const char* input, - streamFormat format, - versionNumber version + IOstreamOption streamOpt ) : - Istream(format, version), + Istream(streamOpt.format(), streamOpt.version()), tokenList(), name_(name), tokenIndex_(0) { - UIListStream is(input, strlen(input), format, version); + UIListStream is(input, strlen(input), streamOpt); parseStream(is, static_cast<tokenList&>(*this)); ITstream::rewind(); diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H index 923d7512f37..394e1df4280 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -115,16 +115,15 @@ public: setGood(); } - //- Construct from components + //- Construct from components, copying the tokens ITstream ( const string& name, const UList<token>& tokens, - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ) : - Istream(format, version), + Istream(streamOpt.format(), streamOpt.version()), tokenList(tokens), name_(name), tokenIndex_(0) @@ -138,11 +137,10 @@ public: ( const string& name, List<token>&& tokens, - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ) : - Istream(format, version), + Istream(streamOpt.format(), streamOpt.version()), tokenList(std::move(tokens)), name_(name), tokenIndex_(0) @@ -157,8 +155,7 @@ public: ( const string& name, const UList<char>& input, - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ); //- Construct token list by parsing the input string @@ -167,8 +164,7 @@ public: ( const string& name, const std::string& input, - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ); //- Construct token list by parsing the input character sequence @@ -177,8 +173,7 @@ public: ( const string& name, const char* input, - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ); @@ -193,7 +188,7 @@ public: static tokenList parse ( const UList<char>& input, - streamFormat format=ASCII + IOstreamOption streamOpt = IOstreamOption() ); //- Create token list by parsing the input string until @@ -201,7 +196,7 @@ public: static tokenList parse ( const std::string& input, - streamFormat format=ASCII + IOstreamOption streamOpt = IOstreamOption() ); //- Create token list by parsing the input character sequence until @@ -209,7 +204,7 @@ public: static tokenList parse ( const char* input, - streamFormat format=ASCII + IOstreamOption streamOpt = IOstreamOption() ); @@ -359,6 +354,109 @@ public: //- Move assignment of tokens, with rewind() void operator=(List<token>&& toks); + + + // Additional constructors and methods (as per v2012 and earlier) + #ifdef Foam_IOstream_extras + + //- Construct from components, copying the tokens + ITstream + ( + const string& name, + const UList<token>& tokens, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + ITstream(name, tokens, IOstreamOption(fmt, ver)) + {} + + //- Construct from components, transferring the tokens + ITstream + ( + const string& name, + List<token>&& tokens, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + ITstream(name, std::move(tokens), IOstreamOption(fmt, ver)) + {} + + //- Construct token list by parsing the input character sequence + // Uses UIListStream internally. + ITstream + ( + const string& name, + const UList<char>& input, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + ITstream(name, input, IOstreamOption(fmt, ver)) + {} + + //- Construct token list by parsing the input string + // Uses UIListStream internally. + ITstream + ( + const string& name, + const std::string& input, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + ITstream(name, input, IOstreamOption(fmt, ver)) + {} + + //- Construct token list by parsing the input character sequence + // Uses UIListStream internally. + ITstream + ( + const string& name, + const char* input, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + ITstream(name, input, IOstreamOption(fmt, ver)) + {} + + + //- Create token list by parsing the input character sequence until + //- no good tokens remain. + static tokenList parse + ( + const UList<char>& input, + IOstreamOption::streamFormat fmt + ) + { + return parse(input, IOstreamOption(fmt)); + } + + //- Create token list by parsing the input string until + //- no good tokens remain. + static tokenList parse + ( + const std::string& input, + IOstreamOption::streamFormat fmt + ) + { + return parse(input, IOstreamOption(fmt)); + } + + //- Create token list by parsing the input character sequence until + //- no good tokens remain. + static tokenList parse + ( + const char* input, + IOstreamOption::streamFormat fmt + ) + { + return parse(input, IOstreamOption(fmt)); + } + + #endif /* Foam_IOstream_extras */ }; diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.C b/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.C index 159c31ee4e6..7dc51413e50 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.C +++ b/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -143,7 +143,7 @@ Foam::Ostream& Foam::OTstream::write(const doubleScalar val) Foam::Ostream& Foam::OTstream::write(const char* data, std::streamsize count) { - if (format() != BINARY) + if (format() != IOstreamOption::BINARY) { FatalErrorInFunction << "stream format not binary" @@ -173,7 +173,7 @@ Foam::Ostream& Foam::OTstream::writeRaw bool Foam::OTstream::beginRawWrite(std::streamsize count) { - if (format() != BINARY) + if (format() != IOstreamOption::BINARY) { FatalErrorInFunction << "stream format not binary" diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H b/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H index b7b56ecaf31..de56b330ba1 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H +++ b/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -73,16 +73,6 @@ public: setGood(); } - //- Construct with format, version - explicit OTstream - ( - streamFormat fmt, - versionNumber ver = currentVersion - ) - : - OTstream(IOstreamOption(fmt, ver)) - {} - //- Copy construct OTstream(const OTstream& os) : @@ -268,6 +258,22 @@ public: //- Print stream description to Ostream void print(Ostream& os) const; + + + // Additional constructors and methods (as per v2012 and earlier) + #ifdef Foam_IOstream_extras + + //- Construct empty with format, version + explicit OTstream + ( + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + OTstream(IOstreamOption(fmt, ver)) + {} + + #endif /* Foam_IOstream_extras */ }; diff --git a/src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H b/src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H index 3336941f46a..763745aa25b 100644 --- a/src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H +++ b/src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -72,10 +72,8 @@ class osha1stream public: - //- Construct null - sha1buf() - {} - + //- Default construct + sha1buf() = default; //- Full access to the sha1 inline SHA1& sha1() @@ -94,7 +92,7 @@ public: // Constructors - //- Construct null + //- Default construct osha1stream() : std::ostream(&buf_) @@ -114,7 +112,6 @@ public: { return buf_.sha1(); } - }; @@ -140,11 +137,8 @@ protected: // Constructors - //- Construct null - OSHA1streamAllocator() - : - stream_() - {} + //- Default construct + OSHA1streamAllocator() = default; public: @@ -170,7 +164,6 @@ public: { return stream_.sha1().clear(); } - }; } // End namespace Detail @@ -201,14 +194,13 @@ public: // Constructors //- Construct with an empty digest - OSHA1stream + explicit OSHA1stream ( - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(), - OSstream(stream_, "sha1", format, version) + OSstream(stream_, "sha1", streamOpt.format(), streamOpt.version()) {} @@ -230,6 +222,22 @@ public: { sha1().clear(); } + + + // Additional constructors and methods (as per v2012 and earlier) + #ifdef Foam_IOstream_extras + + //- Construct empty + explicit OSHA1stream + ( + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + OSHA1stream(IOstreamOption(fmt, ver)) + {} + + #endif /* Foam_IOstream_extras */ }; diff --git a/src/OpenFOAM/db/IOstreams/memory/IListStream.H b/src/OpenFOAM/db/IOstreams/memory/IListStream.H index 260ea509abd..d641da05875 100644 --- a/src/OpenFOAM/db/IOstreams/memory/IListStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/IListStream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -48,7 +48,6 @@ See Also namespace Foam { - namespace Detail { @@ -130,7 +129,7 @@ public: Class IListStream Declaration \*---------------------------------------------------------------------------*/ -//- An ISstream with internal List storage +//- An ISstream with internal List storage. Always UNCOMPRESSED. class IListStream : public Detail::IListStreamAllocator, @@ -145,26 +144,22 @@ public: //- Default construct with an empty list explicit IListStream ( - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(), - ISstream(stream_, "input", format, version) + ISstream(stream_, "input", streamOpt.format(), streamOpt.version()) {} - //- Move construct from List explicit IListStream ( ::Foam::List<char>&& buffer, // Fully qualify (issue #1521) - streamFormat format=ASCII, - versionNumber version=currentVersion, - const Foam::string& name="input" + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(std::move(buffer)), - ISstream(stream_, name, format, version) + ISstream(stream_, "input", streamOpt.format(), streamOpt.version()) {} @@ -173,13 +168,11 @@ public: explicit IListStream ( DynamicList<char,SizeMin>&& buffer, - streamFormat format=ASCII, - versionNumber version=currentVersion, - const Foam::string& name="input" + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(std::move(buffer)), - ISstream(stream_, name, format, version) + ISstream(stream_, "input", streamOpt.format(), streamOpt.version()) {} @@ -215,6 +208,47 @@ public: { return const_cast<Istream&>(static_cast<const Istream&>(*this)); } + + + // Additional constructors and methods (as per v2012 and earlier) + #ifdef Foam_IOstream_extras + + //- Construct with an empty list + explicit IListStream + ( + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + IListStream(IOstreamOption(fmt, ver)) + {} + + + //- Move construct from List + IListStream + ( + ::Foam::List<char>&& buffer, // Fully qualify (issue #1521) + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + IListStream(std::move(buffer), IOstreamOption(fmt, ver)) + {} + + + //- Move construct from DynamicList + template<int SizeMin> + explicit IListStream + ( + DynamicList<char,SizeMin>&& buffer, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + IListStream(std::move(buffer), IOstreamOption(fmt, ver)) + {} + + #endif /* Foam_IOstream_extras */ }; diff --git a/src/OpenFOAM/db/IOstreams/memory/OCountStream.H b/src/OpenFOAM/db/IOstreams/memory/OCountStream.H index 162a9df9416..971856d92c6 100644 --- a/src/OpenFOAM/db/IOstreams/memory/OCountStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/OCountStream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -260,12 +260,11 @@ public: //- Default construct explicit OCountStream ( - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(), - OSstream(stream_, "count", format, version) + OSstream(stream_, "count", streamOpt.format(), streamOpt.version()) {} //- Copy construct @@ -287,6 +286,23 @@ public: //- Print stream description to Ostream virtual void print(Ostream& os) const; + + + // Additional constructors and methods (as per v2012 and earlier) + #ifdef Foam_IOstream_extras + + //- Default construct + explicit OCountStream + ( + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + OCountStream(IOstreamOption(fmt, ver)) + {} + + + #endif /* Foam_IOstream_extras */ }; diff --git a/src/OpenFOAM/db/IOstreams/memory/OListStream.H b/src/OpenFOAM/db/IOstreams/memory/OListStream.H index c556e3ebd30..f02b5ef7f1f 100644 --- a/src/OpenFOAM/db/IOstreams/memory/OListStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/OListStream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -409,36 +409,33 @@ public: //- Default construct (empty output) explicit OListStream ( - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(), - OSstream(stream_, "output", format, version) + OSstream(stream_, "output", streamOpt.format(), streamOpt.version()) {} //- Construct with initial reserved number of bytes explicit OListStream ( size_t nbytes, - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(nbytes), - OSstream(stream_, "output", format, version) + OSstream(stream_, "output", streamOpt.format(), streamOpt.version()) {} //- Move construct from an existing List explicit OListStream ( List<char>&& buffer, - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(std::move(buffer)), - OSstream(stream_, "output", format, version) + OSstream(stream_, "output", streamOpt.format(), streamOpt.version()) {} //- Move construct from an existing DynamicList @@ -446,12 +443,11 @@ public: explicit OListStream ( DynamicList<char,SizeMin>&& buffer, - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(std::move(buffer)), - OSstream(stream_, "output", format, version) + OSstream(stream_, "output", streamOpt.format(), streamOpt.version()) {} @@ -466,6 +462,56 @@ public: //- Print stream description to Ostream virtual void print(Ostream& os) const; + + + // Additional constructors and methods (as per v2012 and earlier) + #ifdef Foam_IOstream_extras + + //- Default construct (empty output) + explicit OListStream + ( + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + OListStream(IOstreamOption(fmt, ver)) + {} + + //- Construct with initial reserved number of bytes + explicit OListStream + ( + size_t nbytes, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + OListStream(nbytes, IOstreamOption(fmt, ver)) + {} + + //- Move construct from an existing List + OListStream + ( + List<char>&& buffer, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + OListStream(std::move(buffer), IOstreamOption(fmt, ver)) + {} + + //- Move construct from an existing DynamicList + template<int SizeMin> + OListStream + ( + DynamicList<char,SizeMin>&& buffer, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + OListStream(std::move(buffer), IOstreamOption(fmt, ver)) + {} + + #endif /* Foam_IOstream_extras */ }; diff --git a/src/OpenFOAM/db/IOstreams/memory/UIListStream.H b/src/OpenFOAM/db/IOstreams/memory/UIListStream.H index 3a6c6e98aad..9e3c93f5b0c 100644 --- a/src/OpenFOAM/db/IOstreams/memory/UIListStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/UIListStream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -216,54 +216,44 @@ public: ( const char* buffer, size_t nbytes, - streamFormat format=ASCII, - versionNumber version=currentVersion, - const Foam::string& name="input" + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(const_cast<char*>(buffer), nbytes), - ISstream(stream_, name, format, version) - {} - - - //- Construct using data area from a FixedList - template<unsigned N> - explicit UIListStream - ( - const FixedList<char, N>& buffer, - streamFormat format=ASCII, - versionNumber version=currentVersion, - const Foam::string& name="input" - ) - : - UIListStream(buffer.cdata(), N, format, version, name) + ISstream(stream_, "input", streamOpt.format(), streamOpt.version()) {} //- Construct using data area from a List and number of bytes UIListStream ( const UList<char>& buffer, - label size, - streamFormat format=ASCII, - versionNumber version=currentVersion, - const Foam::string& name="input" + size_t nbytes, + IOstreamOption streamOpt = IOstreamOption() ) : - UIListStream(buffer.cdata(), size, format, version, name) + UIListStream(buffer.cdata(), nbytes, streamOpt) {} - //- Construct using data area from a List and its inherent storage size // Uses addressed size, thus no special treatment for a DynamicList explicit UIListStream ( const UList<char>& buffer, - streamFormat format=ASCII, - versionNumber version=currentVersion, - const Foam::string& name="input" + IOstreamOption streamOpt = IOstreamOption() + ) + : + UIListStream(buffer.cdata(), buffer.size(), streamOpt) + {} + + //- Construct using data area from a FixedList + template<unsigned N> + explicit UIListStream + ( + const FixedList<char, N>& buffer, + IOstreamOption streamOpt = IOstreamOption() ) : - UIListStream(buffer.cdata(), buffer.size(), format, version, name) + UIListStream(buffer.cdata(), N, streamOpt) {} @@ -294,6 +284,60 @@ public: { return const_cast<Istream&>(static_cast<const Istream&>(*this)); } + + + // Additional constructors and methods (as per v2012 and earlier) + #ifdef Foam_IOstream_extras + + //- Construct using specified buffer and number of bytes + UIListStream + ( + const char* buffer, + size_t nbytes, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + UIListStream(buffer, nbytes, IOstreamOption(fmt, ver)) + {} + + //- Construct using data area from a List and number of bytes + UIListStream + ( + const UList<char>& buffer, + size_t nbytes, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + UIListStream(buffer.cdata(), nbytes, IOstreamOption(fmt, ver)) + {} + + //- Construct using data area from a List and its inherent storage size + // Uses addressed size, thus no special treatment for a DynamicList + UIListStream + ( + const UList<char>& buf, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + UIListStream(buf.cdata(), buf.size(), IOstreamOption(fmt, ver)) + {} + + //- Construct using data area from a FixedList + template<unsigned N> + UIListStream + ( + const FixedList<char, N>& buffer, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + UIListStream(buffer.cdata(), N, IOstreamOption(fmt, ver)) + {} + + #endif /* Foam_IOstream_extras */ }; diff --git a/src/OpenFOAM/db/IOstreams/memory/UOListStream.H b/src/OpenFOAM/db/IOstreams/memory/UOListStream.H index 34487f26206..3e8c78226ae 100644 --- a/src/OpenFOAM/db/IOstreams/memory/UOListStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/UOListStream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -190,60 +190,54 @@ public: ( char* buffer, size_t nbytes, - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ) : allocator_type(buffer, nbytes), - OSstream(stream_, "output", format, version) + OSstream(stream_, "output", streamOpt.format(), streamOpt.version()) {} //- Construct using data area from a List and number of bytes UOListStream ( UList<char>& buffer, - size_t size, - streamFormat format=ASCII, - versionNumber version=currentVersion + size_t nbytes, + IOstreamOption streamOpt = IOstreamOption() ) : - UOListStream(buffer.data(), size, format, version) + UOListStream(buffer.data(), nbytes, streamOpt) {} - //- Construct using data area from a FixedList - template<unsigned N> + //- Construct using data area from a List and its inherent storage size explicit UOListStream ( - FixedList<char, N>& buffer, - streamFormat format=ASCII, - versionNumber version=currentVersion + UList<char>& buffer, + IOstreamOption streamOpt = IOstreamOption() ) : - UOListStream(buffer.data(), N, format, version) + UOListStream(buffer.data(), buffer.size(), streamOpt) {} - //- Construct using data area from a List and its inherent storage size + //- Construct using data area from a FixedList + template<unsigned N> explicit UOListStream ( - UList<char>& buffer, - streamFormat format=ASCII, - versionNumber version=currentVersion + FixedList<char, N>& buffer, + IOstreamOption streamOpt = IOstreamOption() ) : - UOListStream(buffer.data(), buffer.size(), format, version) + UOListStream(buffer.data(), N, streamOpt) {} - //- Construct using data area from a DynamicList and its capacity template<int SizeMin> explicit UOListStream ( DynamicList<char,SizeMin>& buffer, - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ) : - UOListStream(buffer.data(), buffer.capacity(), format, version) + UOListStream(buffer.data(), buffer.capacity(), streamOpt) {} @@ -258,6 +252,71 @@ public: //- Print stream description to Ostream virtual void print(Ostream& os) const; + + + // Additional constructors and methods (as per v2012 and earlier) + #ifdef Foam_IOstream_extras + + //- Construct using specified buffer and number of bytes + UOListStream + ( + char* buffer, + size_t nbytes, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + UOListStream(buffer, nbytes, IOstreamOption(fmt, ver)) + {} + + //- Construct using data area from a List and number of bytes + UOListStream + ( + UList<char>& buffer, + size_t nbytes, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + UOListStream(buffer.data(), nbytes, IOstreamOption(fmt, ver)) + {} + + //- Construct using data area from a List and its inherent storage size + UOListStream + ( + UList<char>& buffer, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + UOListStream(buffer.data(), buffer.size(), IOstreamOption(fmt, ver)) + {} + + //- Construct using data area from a FixedList + template<unsigned N> + UOListStream + ( + FixedList<char, N>& buffer, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + UOListStream(buffer.data(), N, IOstreamOption(fmt, ver)) + {} + + //- Construct using data area from a DynamicList and its capacity + template<int SizeMin> + UOListStream + ( + DynamicList<char,SizeMin>& buf, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion + ) + : + UOListStream(buf.data(), buf.capacity(), IOstreamOption(fmt, ver)) + {} + + #endif /* Foam_IOstream_extras */ }; diff --git a/src/OpenFOAM/db/Time/TimeIO.C b/src/OpenFOAM/db/Time/TimeIO.C index 1a57de375c9..dfe975357db 100644 --- a/src/OpenFOAM/db/Time/TimeIO.C +++ b/src/OpenFOAM/db/Time/TimeIO.C @@ -249,7 +249,7 @@ void Foam::Time::readDict() for (simpleRegIOobject* obj : objects) { - OStringStream os(IOstream::ASCII); + OStringStream os; os << dict; IStringStream is(os.str()); obj->readData(is); diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C index 5b1cd5f8cd7..eb1f21d2249 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -252,8 +252,7 @@ Foam::primitiveEntry::primitiveEntry ( is.name() + '.' + key, tokenList(10), - is.format(), - is.version() + static_cast<IOstreamOption>(is) ) { readEntry(dict, is); diff --git a/src/OpenFOAM/db/regIOobject/regIOobject.H b/src/OpenFOAM/db/regIOobject/regIOobject.H index d1ed8278727..262122f8bf5 100644 --- a/src/OpenFOAM/db/regIOobject/regIOobject.H +++ b/src/OpenFOAM/db/regIOobject/regIOobject.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -78,7 +78,7 @@ protected: //- Helper: check readOpt flags and read if necessary bool readHeaderOk ( - const IOstream::streamFormat PstreamFormat, + const IOstreamOption::streamFormat fmt, const word& typeName ); @@ -358,9 +358,9 @@ public: FOAM_DEPRECATED_FOR(2020-02, "writeObject(IOstreamOption, bool)") virtual bool writeObject ( - IOstream::streamFormat fmt, - IOstream::versionNumber ver, - IOstream::compressionType comp, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver, + IOstreamOption::compressionType comp, const bool valid ) const; }; diff --git a/src/OpenFOAM/db/regIOobject/regIOobjectRead.C b/src/OpenFOAM/db/regIOobject/regIOobjectRead.C index 01b67843c4e..f987de06340 100644 --- a/src/OpenFOAM/db/regIOobject/regIOobjectRead.C +++ b/src/OpenFOAM/db/regIOobject/regIOobjectRead.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2018 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,7 +37,7 @@ License bool Foam::regIOobject::readHeaderOk ( - const IOstream::streamFormat format, + const IOstreamOption::streamFormat fmt, const word& typeName ) { @@ -77,7 +77,7 @@ bool Foam::regIOobject::readHeaderOk || isHeaderOk ) { - return fileHandler().read(*this, masterOnly, format, typeName); + return fileHandler().read(*this, masterOnly, fmt, typeName); } return false; diff --git a/src/OpenFOAM/db/regIOobject/regIOobjectWrite.C b/src/OpenFOAM/db/regIOobject/regIOobjectWrite.C index c913550406c..867aff11cfc 100644 --- a/src/OpenFOAM/db/regIOobject/regIOobjectWrite.C +++ b/src/OpenFOAM/db/regIOobject/regIOobjectWrite.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,7 +28,6 @@ License #include "regIOobject.H" #include "Time.H" -#include "OSspecific.H" #include "OFstream.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -42,8 +41,7 @@ bool Foam::regIOobject::writeObject if (!good()) { SeriousErrorInFunction - << "bad object " << name() - << endl; + << "bad object " << name() << endl; return false; } @@ -51,8 +49,7 @@ bool Foam::regIOobject::writeObject if (instance().empty()) { SeriousErrorInFunction - << "instance undefined for object " << name() - << endl; + << "instance undefined for object " << name() << endl; return false; } @@ -97,9 +94,6 @@ bool Foam::regIOobject::writeObject } - bool osGood = false; - - // Everyone check or just master bool masterOnly = isGlobal @@ -108,36 +102,9 @@ bool Foam::regIOobject::writeObject || regIOobject::fileModificationChecking == inotifyMaster ); - + bool osGood = false; if (Pstream::master() || !masterOnly) { - //if (mkDir(path())) - //{ - // // Try opening an OFstream for object - // OFstream os(objectPath(), streamOpt); - // - // // If any of these fail, return (leave error handling to Ostream - // // class) - // if (!os.good()) - // { - // return false; - // } - // - // if (!writeHeader(os)) - // { - // return false; - // } - // - // // Write the data to the Ostream - // if (!writeData(os)) - // { - // return false; - // } - // - // writeEndDivider(os); - // - // osGood = os.good(); - //} osGood = fileHandler().writeObject(*this, streamOpt, valid); } else @@ -174,9 +141,9 @@ bool Foam::regIOobject::write(const bool valid) const bool Foam::regIOobject::writeObject ( - IOstream::streamFormat fmt, - IOstream::versionNumber ver, - IOstream::compressionType cmp, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver, + IOstreamOption::compressionType cmp, const bool valid ) const { diff --git a/src/OpenFOAM/global/debug/simpleObjectRegistry.C b/src/OpenFOAM/global/debug/simpleObjectRegistry.C index 1f20f10b295..445b3f0b813 100644 --- a/src/OpenFOAM/global/debug/simpleObjectRegistry.C +++ b/src/OpenFOAM/global/debug/simpleObjectRegistry.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -57,7 +57,7 @@ void Foam::simpleObjectRegistry::setValues if (dEntry.isDict()) { - OStringStream os(IOstream::ASCII); + OStringStream os; os << dEntry.dict(); IStringStream is(os.str()); diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.C b/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.C index 2f146ea2ebb..3ecbd4d1ca0 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.C +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.C @@ -44,14 +44,12 @@ namespace Foam bool Foam::OFstreamCollator::writeFile ( const label comm, - const word& typeName, + const word& objectType, const fileName& fName, const string& masterData, const labelUList& recvSizes, const PtrList<SubList<char>>& slaveData, // optional slave data - IOstream::streamFormat fmt, - IOstream::versionNumber ver, - IOstream::compressionType cmp, + IOstreamOption streamOpt, const bool append ) { @@ -79,17 +77,7 @@ bool Foam::OFstreamCollator::writeFile if (UPstream::master(comm)) { Foam::mkDir(fName.path()); - osPtr.reset - ( - new OFstream - ( - fName, - fmt, - ver, - cmp, - append - ) - ); + osPtr.reset(new OFstream(fName, streamOpt, append)); // We don't have IOobject so cannot use IOobject::writeHeader if (!append) @@ -97,9 +85,8 @@ bool Foam::OFstreamCollator::writeFile decomposedBlockData::writeHeader ( *osPtr, - ver, - fmt, - typeName, + streamOpt, + objectType, "", // note fName, // location fName.name() // object name @@ -195,7 +182,7 @@ void* Foam::OFstreamCollator::writeAll(void *threadarg) PtrList<SubList<char>> slaveData; if (ptr->slaveData_.size()) { - slaveData.setSize(ptr->slaveData_.size()); + slaveData.resize(ptr->slaveData_.size()); forAll(slaveData, proci) { if (ptr->slaveData_.set(proci)) @@ -216,14 +203,12 @@ void* Foam::OFstreamCollator::writeAll(void *threadarg) bool ok = writeFile ( ptr->comm_, - ptr->typeName_, + ptr->objectType_, ptr->pathName_, ptr->data_, ptr->sizes_, slaveData, - ptr->format_, - ptr->version_, - ptr->compression_, + ptr->streamOpt_, ptr->append_ ); if (!ok) @@ -354,12 +339,10 @@ Foam::OFstreamCollator::~OFstreamCollator() bool Foam::OFstreamCollator::write ( - const word& typeName, + const word& objectType, const fileName& fName, const string& data, - IOstream::streamFormat fmt, - IOstream::versionNumber ver, - IOstream::compressionType cmp, + IOstreamOption streamOpt, const bool append, const bool useThread ) @@ -393,14 +376,12 @@ bool Foam::OFstreamCollator::write return writeFile ( localComm_, - typeName, + objectType, fName, data, recvSizes, dummySlaveData, - fmt, - ver, - cmp, + streamOpt, append ); } @@ -429,7 +410,7 @@ bool Foam::OFstreamCollator::write new writeData ( threadComm_, // Note: comm not actually used anymore - typeName, + objectType, fName, ( Pstream::master(localComm_) @@ -437,9 +418,7 @@ bool Foam::OFstreamCollator::write : string::null ), recvSizes, - fmt, - ver, - cmp, + streamOpt, append ) ); @@ -559,13 +538,11 @@ bool Foam::OFstreamCollator::write new writeData ( threadComm_, - typeName, + objectType, fName, data, recvSizes, - fmt, - ver, - cmp, + streamOpt, append ) ); diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.H b/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.H index ee48b604290..636a0309b77 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.H +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/OFstreamCollator.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017-2018 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,9 +43,6 @@ Description collecting is done locally; the thread only does the writing (since the data has already been collected) - -Operation determine - SourceFiles OFstreamCollator.C @@ -71,45 +69,39 @@ namespace Foam class OFstreamCollator { - // Private class + // Private Class class writeData { public: const label comm_; - const word typeName_; + const word objectType_; const fileName pathName_; const string data_; const labelList sizes_; PtrList<List<char>> slaveData_; - const IOstream::streamFormat format_; - const IOstream::versionNumber version_; - const IOstream::compressionType compression_; + const IOstreamOption streamOpt_; const bool append_; writeData ( const label comm, - const word& typeName, + const word& objectType, const fileName& pathName, const string& data, const labelList& sizes, - IOstream::streamFormat format, - IOstream::versionNumber version, - IOstream::compressionType compression, + IOstreamOption streamOpt, const bool append ) : comm_(comm), - typeName_(typeName), + objectType_(objectType), pathName_(pathName), data_(data), sizes_(sizes), - slaveData_(0), - format_(format), - version_(version), - compression_(compression), + slaveData_(), + streamOpt_(streamOpt), append_(append) {} @@ -157,14 +149,12 @@ class OFstreamCollator static bool writeFile ( const label comm, - const word& typeName, + const word& objectType, const fileName& fName, const string& masterData, const labelUList& recvSizes, const PtrList<SubList<char>>& slaveData, - IOstream::streamFormat fmt, - IOstream::versionNumber ver, - IOstream::compressionType cmp, + IOstreamOption streamOpt, const bool append ); @@ -185,10 +175,10 @@ public: // Constructors //- Construct from buffer size. 0 = do not use thread - OFstreamCollator(const off_t maxBufferSize); + explicit OFstreamCollator(const off_t maxBufferSize); - //- Construct from buffer size (0 = do not use thread) and local - // thread + //- Construct from buffer size (0 = do not use thread) + //- and specified communicator OFstreamCollator(const off_t maxBufferSize, const label comm); @@ -196,18 +186,17 @@ public: virtual ~OFstreamCollator(); - // Member functions + // Member Functions - //- Write file with contents. Blocks until writethread has space - // available (total file sizes < maxBufferSize) + //- Write file with contents. + // Blocks until writethread has space available + // (total file sizes < maxBufferSize) bool write ( - const word& typeName, + const word& objectType, const fileName&, const string& data, - IOstream::streamFormat, - IOstream::versionNumber, - IOstream::compressionType, + IOstreamOption streamOpt, const bool append, const bool useThread = true ); diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C b/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C index a984a57b387..1fd1bd0ecdd 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017-2018 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -161,7 +161,7 @@ bool Foam::fileOperations::collatedFileOperation::appendObject // Create string from all data to write string buf; { - OStringStream os(streamOpt.format(), streamOpt.version()); + OStringStream os(streamOpt); if (isMaster) { if (!io.writeHeader(os)) @@ -204,23 +204,15 @@ bool Foam::fileOperations::collatedFileOperation::appendObject if (isMaster) { - IOobject::writeBanner(os) - << "FoamFile\n{\n" - << " version " << os.version() << ";\n" - << " format " << os.format() << ";\n" - << " class " << decomposedBlockData::typeName - << ";\n"; - - // This may be useful to have as well - if (os.format() == IOstream::BINARY) - { - os << " arch " << foamVersion::buildArch << ";\n"; - } - - os << " location " << pathName << ";\n" - << " object " << pathName.name() << ";\n" - << "}" << nl; - IOobject::writeDivider(os) << nl; + decomposedBlockData::writeHeader + ( + os, + static_cast<IOstreamOption>(os), + decomposedBlockData::typeName, // class + "", // note + pathName, // location + pathName.name() // object + ); } // Write data diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.H b/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.H index 7876080e84d..fd421743fe0 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.H +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.H @@ -105,7 +105,7 @@ public: TypeName("collated"); - // Static data + // Static Data //- Max size of thread buffer size. This is the overall size of // all files to be written. Starts blocking if not enough size. @@ -115,8 +115,8 @@ public: // Constructors - //- Construct null - collatedFileOperation(bool verbose); + //- Default construct + explicit collatedFileOperation(bool verbose); //- Construct from user communicator collatedFileOperation @@ -163,8 +163,8 @@ public: //- Actual name of processors dir virtual word processorsDir(const fileName&) const; - //- Set number of processor directories/results. Only used in - // decomposePar + //- Set number of processor directories/results. + //- Only used in decomposePar virtual void setNProcs(const label nProcs); }; @@ -197,9 +197,7 @@ public: //- Needs threading virtual bool needsThreading() const { - return - collatedFileOperation::maxThreadFileBufferSize - > 0; + return (collatedFileOperation::maxThreadFileBufferSize > 0); } }; diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/hostCollatedFileOperation.H b/src/OpenFOAM/global/fileOperations/collatedFileOperation/hostCollatedFileOperation.H index f1b5dc58c62..5927583cc30 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/hostCollatedFileOperation.H +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/hostCollatedFileOperation.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017-2018 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -90,8 +91,8 @@ public: // Constructors - //- Construct null - hostCollatedFileOperation(const bool verbose); + //- Default construct + explicit hostCollatedFileOperation(const bool verbose); //- Destructor diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.C b/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.C index e3c7cc20edf..07d1ffc1467 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.C +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017-2018 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,7 +40,7 @@ Foam::threadedCollatedOFstream::threadedCollatedOFstream const bool useThread ) : - OStringStream(streamOpt.format(), streamOpt.version()), + OStringStream(streamOpt), writer_(writer), pathName_(pathName), compression_(streamOpt.compression()), @@ -57,9 +57,7 @@ Foam::threadedCollatedOFstream::~threadedCollatedOFstream() decomposedBlockData::typeName, pathName_, str(), - IOstream::BINARY, - version(), - compression_, + IOstreamOption(IOstream::BINARY, version(), compression_), false, // append=false useThread_ ); diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.H b/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.H index 87990ec39a0..fabc873f5ea 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.H +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017-2018 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -44,6 +45,7 @@ SourceFiles namespace Foam { +// Forward Declarations class OFstreamCollator; /*---------------------------------------------------------------------------*\ @@ -54,13 +56,14 @@ class threadedCollatedOFstream : public OStringStream { - // Private data + // Private Data + //- The backend writer OFstreamCollator& writer_; const fileName pathName_; - const IOstream::compressionType compression_; + const IOstreamOption::compressionType compression_; const bool useThread_; @@ -78,14 +81,22 @@ public: const bool useThread = true ); + + //- Destructor + ~threadedCollatedOFstream(); + + + // Additional constructors and methods (as per v2012 and earlier) + #ifdef Foam_IOstream_extras + //- Construct and set stream status threadedCollatedOFstream ( OFstreamCollator& writer, const fileName& pathname, - streamFormat fmt, - versionNumber ver = currentVersion, - compressionType comp = compressionType::UNCOMPRESSED, + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion, + IOstreamOption::compressionType cmp = IOstreamOption::UNCOMPRESSED, const bool useThread = true ) : @@ -93,14 +104,12 @@ public: ( writer, pathname, - IOstreamOption(fmt, ver, comp), + IOstreamOption(fmt, ver, cmp), useThread ) {} - - //- Destructor - ~threadedCollatedOFstream(); + #endif /* Foam_IOstream_extras */ }; diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H index 412c22ef866..ac3ce897a75 100644 --- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H +++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -437,7 +437,7 @@ public: ( regIOobject&, const bool masterOnly, - const IOstream::streamFormat format, + const IOstreamOption::streamFormat format, const word& typeName ) const = 0; diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C index 2dc64cb0399..69a078a22e5 100644 --- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C +++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017-2018 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -500,7 +500,7 @@ void Foam::fileOperations::masterUncollatedFileOperation::readAndSend PstreamBuffers& pBufs ) { - IFstream ifs(filePath, IOstream::streamFormat::BINARY); + IFstream ifs(filePath, IOstreamOption::BINARY); if (!ifs.good()) { @@ -516,7 +516,7 @@ void Foam::fileOperations::masterUncollatedFileOperation::readAndSend << filePath << endl; } - if (ifs.compression() == IOstream::compressionType::COMPRESSED) + if (ifs.compression() == IOstreamOption::COMPRESSED) { // Could use Foam::fileSize, estimate uncompressed size (eg, 2x) // and then string reserve followed by string assign... @@ -2087,7 +2087,7 @@ bool Foam::fileOperations::masterUncollatedFileOperation::read ( regIOobject& io, const bool masterOnly, - const IOstream::streamFormat format, + const IOstreamOption::streamFormat format, const word& typeName ) const { @@ -2203,7 +2203,7 @@ bool Foam::fileOperations::masterUncollatedFileOperation::writeObject setTime(io.time()); autoPtr<OSstream> osPtr(NewOFstream(pathName, streamOpt, valid)); - OSstream& os = osPtr(); + OSstream& os = *osPtr; // If any of these fail, return (leave error handling to Ostream class) if (!os.good()) diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H index 03ccd0fd616..661f07759c2 100644 --- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H +++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -89,7 +89,7 @@ class masterUncollatedFileOperation { protected: - // Protected data + // Protected Data //- Any communicator allocated by me const label myComm_; @@ -98,7 +98,7 @@ protected: mutable HashPtrTable<instantList> times_; - // Protected classes + // Protected Classes class mkDirOp { @@ -488,8 +488,8 @@ public: // Constructors - //- Construct null - masterUncollatedFileOperation(bool verbose); + //- Default construct + explicit masterUncollatedFileOperation(bool verbose); //- Construct from communicator masterUncollatedFileOperation(const label comm, bool verbose); @@ -679,7 +679,7 @@ public: ( regIOobject&, const bool masterOnly, - const IOstream::streamFormat format, + const IOstreamOption::streamFormat format, const word& typeName ) const; diff --git a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C index b930c685fe0..d54f983e835 100644 --- a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C +++ b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -613,7 +613,7 @@ bool Foam::fileOperations::uncollatedFileOperation::read ( regIOobject& io, const bool masterOnly, - const IOstream::streamFormat format, + const IOstreamOption::streamFormat format, const word& typeName ) const { diff --git a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H index 3e2ec313e4b..fc5d7b1b8de 100644 --- a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H +++ b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -86,7 +86,7 @@ public: // Constructors //- Default construct - uncollatedFileOperation(bool verbose); + explicit uncollatedFileOperation(bool verbose); //- Destructor @@ -272,7 +272,7 @@ public: ( regIOobject&, const bool masterOnly, - const IOstream::streamFormat format, + const IOstreamOption::streamFormat format, const word& typeName ) const; diff --git a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.C b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.C index bc09a69dde6..4e2ebaab6d1 100644 --- a/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.C +++ b/src/OpenFOAM/interpolations/interpolationTable/tableReaders/csv/csvTableReader.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -225,10 +225,9 @@ void Foam::csvTableReader<Type>::write(Ostream& os) const os.writeEntry("refColumn", refColumn_); // Force writing labelList in ASCII - const enum IOstream::streamFormat fmt = os.format(); - os.format(IOstream::ASCII); + const auto oldFmt = os.format(IOstream::ASCII); os.writeEntry("componentColumns", componentColumns_); - os.format(fmt); + os.format(oldFmt); os.writeEntry("separator", string(separator_)); } diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index 81bf9400b3a..001b19df7ba 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -1181,7 +1181,7 @@ bool Foam::polyBoundaryMesh::writeObject const bool valid ) const { - streamOpt.compression(IOstream::UNCOMPRESSED); + streamOpt.compression(IOstreamOption::UNCOMPRESSED); return regIOobject::writeObject(streamOpt, valid); } diff --git a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C index 1aaedfa1d59..03fb6b86c0c 100644 --- a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C +++ b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -260,10 +260,9 @@ void Foam::Function1Types::CSV<Type>::writeEntries(Ostream& os) const os.writeEntry("refColumn", refColumn_); // Force writing labelList in ASCII - const enum IOstream::streamFormat fmt = os.format(); - os.format(IOstream::ASCII); + const auto oldFmt = os.format(IOstream::ASCII); os.writeEntry("componentColumns", componentColumns_); - os.format(fmt); + os.format(oldFmt); os.writeEntry("separator", string(separator_)); os.writeEntry("mergeSeparators", mergeSeparators_); diff --git a/src/Pstream/dummy/UIPread.C b/src/Pstream/dummy/UIPread.C index 2817f74ac51..3663e35f594 100644 --- a/src/Pstream/dummy/UIPread.C +++ b/src/Pstream/dummy/UIPread.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,12 +42,12 @@ Foam::UIPstream::UIPstream const int tag, const label comm, const bool clearAtEnd, - streamFormat format, - versionNumber version + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver ) : UPstream(commsType), - Istream(format, version), + Istream(fmt, ver), fromProcNo_(fromProcNo), externalBuf_(externalBuf), externalBufPosition_(externalBufPosition), @@ -88,8 +89,7 @@ Foam::label Foam::UIPstream::read ) { NotImplemented; - - return 0; + return 0; } diff --git a/src/Pstream/mpi/UIPread.C b/src/Pstream/mpi/UIPread.C index 5fed1729e34..6b04ff48b65 100644 --- a/src/Pstream/mpi/UIPread.C +++ b/src/Pstream/mpi/UIPread.C @@ -47,12 +47,12 @@ Foam::UIPstream::UIPstream const int tag, const label comm, const bool clearAtEnd, - streamFormat format, - versionNumber version + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver ) : UPstream(commsType), - Istream(format, version), + Istream(fmt, ver), fromProcNo_(fromProcNo), externalBuf_(externalBuf), externalBufPosition_(externalBufPosition), diff --git a/src/conversion/ccm/reader/ccmReader.C b/src/conversion/ccm/reader/ccmReader.C index 4a36f839210..838b5d234f1 100644 --- a/src/conversion/ccm/reader/ccmReader.C +++ b/src/conversion/ccm/reader/ccmReader.C @@ -579,17 +579,13 @@ bool Foam::ccm::reader::hasSolution() void Foam::ccm::reader::writeMesh ( const polyMesh& mesh, - IOstream::streamFormat fmt + IOstreamOption streamOpt ) const { mesh.removeFiles(); Info<< "Writing polyMesh" << endl; - mesh.writeObject - ( - IOstreamOption(fmt), - true - ); + mesh.writeObject(streamOpt, true); writeAux(mesh); } diff --git a/src/conversion/ccm/reader/ccmReader.H b/src/conversion/ccm/reader/ccmReader.H index f84425911df..283005fd6dc 100644 --- a/src/conversion/ccm/reader/ccmReader.H +++ b/src/conversion/ccm/reader/ccmReader.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -161,7 +161,6 @@ SourceFiles #include "ccmInterfaceDefinitions.H" #include "ccmSolutionTable.H" - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam @@ -395,7 +394,7 @@ private: const objectRegistry& registry, const word& propertyName, const labelList& list, - IOstream::streamFormat fmt = IOstream::ASCII + IOstreamOption streamOpt ) const; // polyMesh Friend Functions @@ -493,7 +492,7 @@ public: void writeMesh ( const polyMesh& mesh, - IOstream::streamFormat fmt = IOstream::BINARY + IOstreamOption streamOpt = IOstreamOption(IOstreamOption::BINARY) ) const; //- Write cellTable, boundaryRegion and interface information diff --git a/src/conversion/ccm/reader/ccmReaderAux.C b/src/conversion/ccm/reader/ccmReaderAux.C index 8853d2a642c..3031b000d63 100644 --- a/src/conversion/ccm/reader/ccmReaderAux.C +++ b/src/conversion/ccm/reader/ccmReaderAux.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -146,7 +146,7 @@ void Foam::ccm::reader::writeMeshLabelList const objectRegistry& registry, const word& propertyName, const labelList& list, - IOstream::streamFormat fmt + IOstreamOption streamOpt ) const { // Write constant/polyMesh/propertyName @@ -171,12 +171,8 @@ void Foam::ccm::reader::writeMeshLabelList // NOTE: // The cellTableId is an integer and almost always < 1000, thus ASCII // will be compacter than binary and makes external scripting easier - // - ioObj.writeObject - ( - IOstreamOption(fmt), - true - ); + + ioObj.writeObject(streamOpt, true); } @@ -197,7 +193,7 @@ void Foam::ccm::reader::writeAux registry, "origCellId", origCellId_, - IOstream::BINARY + IOstreamOption(IOstreamOption::BINARY) ); // Write cellTableId as List<label> @@ -207,7 +203,7 @@ void Foam::ccm::reader::writeAux registry, "cellTableId", cellTableId_, - IOstream::ASCII + IOstreamOption(IOstreamOption::ASCII) ); } diff --git a/src/conversion/common/reader/meshReader.C b/src/conversion/common/reader/meshReader.C index 5db5fb6b0d0..0c8e96e71f2 100644 --- a/src/conversion/common/reader/meshReader.C +++ b/src/conversion/common/reader/meshReader.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -124,17 +124,13 @@ Foam::autoPtr<Foam::polyMesh> Foam::meshReader::mesh void Foam::meshReader::writeMesh ( const polyMesh& mesh, - IOstream::streamFormat fmt + IOstreamOption streamOpt ) const { mesh.removeFiles(); Info<< "Writing polyMesh" << endl; - mesh.writeObject - ( - IOstreamOption(fmt), - true - ); + mesh.writeObject(streamOpt, true); writeAux(mesh); } diff --git a/src/conversion/common/reader/meshReader.H b/src/conversion/common/reader/meshReader.H index aed1acadf6d..d584a02b761 100644 --- a/src/conversion/common/reader/meshReader.H +++ b/src/conversion/common/reader/meshReader.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -193,7 +193,7 @@ private: const objectRegistry& registry, const word& propertyName, const labelList& list, - IOstream::streamFormat fmt = IOstream::ASCII + IOstreamOption streamOpt ) const; //- Return list of faces for every cell @@ -291,7 +291,7 @@ public: void writeMesh ( const polyMesh&, - IOstream::streamFormat fmt = IOstream::BINARY + IOstreamOption streamOpt = IOstreamOption(IOstreamOption::BINARY) ) const; }; diff --git a/src/conversion/common/reader/meshReaderAux.C b/src/conversion/common/reader/meshReaderAux.C index 0503737b2a2..dbe35efb534 100644 --- a/src/conversion/common/reader/meshReaderAux.C +++ b/src/conversion/common/reader/meshReaderAux.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -109,7 +109,7 @@ void Foam::meshReader::writeMeshLabelList const objectRegistry& registry, const word& propertyName, const labelList& list, - IOstream::streamFormat fmt + IOstreamOption streamOpt ) const { // write constant/polyMesh/propertyName @@ -129,14 +129,14 @@ void Foam::meshReader::writeMeshLabelList ); - ioObj.note() = "persistent data for star-cd <-> foam translation"; + ioObj.note() = "persistent data for STARCD <-> OPENFOAM translation"; Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl; // NOTE: // the cellTableId is an integer and almost always < 1000, thus ASCII // will be compacter than binary and makes external scripting easier - ioObj.writeObject(IOstreamOption(fmt), true); + ioObj.writeObject(streamOpt, true); } @@ -153,7 +153,7 @@ void Foam::meshReader::writeAux(const objectRegistry& registry) const registry, "origCellId", origCellId_, - IOstream::BINARY + IOstreamOption(IOstreamOption::BINARY) ); // write cellTableId as List<label> @@ -163,7 +163,7 @@ void Foam::meshReader::writeAux(const objectRegistry& registry) const registry, "cellTableId", cellTableId_, - IOstream::ASCII + IOstreamOption(IOstreamOption::ASCII) ); } diff --git a/src/conversion/fire/FIREMeshReader.C b/src/conversion/fire/FIREMeshReader.C index 88e9e26b980..f6285521d08 100644 --- a/src/conversion/fire/FIREMeshReader.C +++ b/src/conversion/fire/FIREMeshReader.C @@ -376,7 +376,7 @@ void Foam::fileFormats::FIREMeshReader::addPatches(polyMesh& mesh) const bool Foam::fileFormats::FIREMeshReader::readGeometry(const scalar scaleFactor) { - IOstream::streamFormat fmt = IOstream::ASCII; + IOstreamOption::streamFormat fmt = IOstream::ASCII; const word ext(geometryFile_.ext()); diff --git a/src/fileFormats/ensight/read/ensightReadFile.C b/src/fileFormats/ensight/read/ensightReadFile.C index 22c7a2bae8a..1697fdea018 100644 --- a/src/fileFormats/ensight/read/ensightReadFile.C +++ b/src/fileFormats/ensight/read/ensightReadFile.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,10 +32,10 @@ License Foam::ensightReadFile::ensightReadFile ( const fileName& pathname, - IOstream::streamFormat format + IOstreamOption::streamFormat fmt ) : - IFstream(pathname, format) + IFstream(pathname, fmt) {} diff --git a/src/fileFormats/ensight/read/ensightReadFile.H b/src/fileFormats/ensight/read/ensightReadFile.H index d456c3e0321..a19e3103a84 100644 --- a/src/fileFormats/ensight/read/ensightReadFile.H +++ b/src/fileFormats/ensight/read/ensightReadFile.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -65,10 +65,10 @@ public: // Constructors //- Construct from pathname. Default format is binary. - ensightReadFile + explicit ensightReadFile ( const fileName& pathname, - IOstream::streamFormat format=IOstream::BINARY + IOstreamOption::streamFormat fmt = IOstreamOption::BINARY ); diff --git a/src/fileFormats/fire/FIRECore.C b/src/fileFormats/fire/FIRECore.C index d16be2cb484..1fa596f139c 100644 --- a/src/fileFormats/fire/FIRECore.C +++ b/src/fileFormats/fire/FIRECore.C @@ -204,7 +204,7 @@ void Foam::fileFormats::FIRECore::putFireLabel const label value ) { - if (os.format() == Foam::IOstream::BINARY) + if (os.format() == IOstream::BINARY) { fireInt_t ivalue(value); diff --git a/src/fileFormats/obj/OBJstream.H b/src/fileFormats/obj/OBJstream.H index bfba6324946..2b319aedf35 100644 --- a/src/fileFormats/obj/OBJstream.H +++ b/src/fileFormats/obj/OBJstream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2015 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -90,12 +90,12 @@ public: OBJstream ( const fileName& pathname, - streamFormat fmt, - versionNumber ver = currentVersion, - compressionType comp = compressionType::UNCOMPRESSED + IOstreamOption::streamFormat fmt, + IOstreamOption::versionNumber ver = IOstreamOption::currentVersion, + IOstreamOption::compressionType cmp = IOstreamOption::UNCOMPRESSED ) : - OBJstream(pathname, IOstreamOption(fmt, ver, comp)) + OBJstream(pathname, IOstreamOption(fmt, ver, cmp)) {} diff --git a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H index ec120d79230..20eae6f21a4 100644 --- a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H +++ b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -69,7 +69,7 @@ protected: }; //- Format flag - IOstream::streamFormat streamFormat_; + IOstreamOption::streamFormat streamFormat_; //- Base directory fileName baseDir_; diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C index e002ea79d46..6bc87cd8aed 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -204,7 +204,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii ( const fileName& filename, const MeshedSurfaceProxy<Face>& surf, - IOstream::compressionType comp + IOstreamOption::compressionType comp ) { OFstream os(filename, IOstreamOption(IOstream::ASCII, comp)); @@ -303,7 +303,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii ( const fileName& filename, const UnsortedMeshedSurface<Face>& surf, - IOstream::compressionType comp + IOstreamOption::compressionType comp ) { const pointField& pointLst = surf.points(); @@ -416,7 +416,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write const fileName& filename, const MeshedSurfaceProxy<Face>& surf, const STLFormat format, - IOstream::compressionType comp + IOstreamOption::compressionType comp ) { if (STLCore::isBinaryName(filename, format)) @@ -461,7 +461,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write const fileName& filename, const UnsortedMeshedSurface<Face>& surf, const STLFormat format, - IOstream::compressionType comp + IOstreamOption::compressionType comp ) { if (STLCore::isBinaryName(filename, format)) diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.H b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.H index 4167afdb88f..b91bb1e849c 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.H +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -108,7 +108,7 @@ public: ( const fileName& filename, const MeshedSurfaceProxy<Face>& surf, - IOstream::compressionType comp = IOstream::UNCOMPRESSED + IOstreamOption::compressionType comp = IOstreamOption::UNCOMPRESSED ); //- Write surface mesh components by proxy (as BINARY) @@ -123,7 +123,7 @@ public: ( const fileName& filename, const UnsortedMeshedSurface<Face>& surf, - IOstream::compressionType comp = IOstream::UNCOMPRESSED + IOstreamOption::compressionType comp = IOstreamOption::UNCOMPRESSED ); //- Write UnsortedMeshedSurface (as BINARY) unsorted by zone @@ -140,7 +140,7 @@ public: const fileName& filename, const MeshedSurfaceProxy<Face>& surf, const STLFormat format, - IOstream::compressionType comp = IOstream::UNCOMPRESSED + IOstreamOption::compressionType comp = IOstreamOption::UNCOMPRESSED ); //- Write UnsortedMeshedSurface @@ -150,7 +150,7 @@ public: const fileName& filename, const UnsortedMeshedSurface<Face>& surf, const STLFormat format, - IOstream::compressionType comp = IOstream::UNCOMPRESSED + IOstreamOption::compressionType comp = IOstreamOption::UNCOMPRESSED ); -- GitLab