diff --git a/applications/test/primitives/Test-primitives.C b/applications/test/primitives/Test-primitives.C index 0064400290e46464bcf6c92dd448c5d492ede2fd..1fe56e2ae9f7896ec41b634ae469c687f482cae4 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 78423b0e049c9dadc77682585343fa977d570d62..692531acab9b3f17ba9d826e35f4a403b13ca0fe 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 e25418fef3b5cea2e6d2ecb3bc6ec650940cb2fb..7b0928ebe6b1a4652db257057cb8cdfbabb84904 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 e8f35947f7eecb70c868d9bada14e1d64eac63a1..409c50369088939ffdbd6479a666fcb3d6718ced 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 2c4f7a84f2e77535e546c8843a3f84ea020066a9..345ca59dd6e449ec92268bf3ff90d38344d8ede5 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 7726a6d76a605dde2cbeb1c536ed56e4ff578920..ed0ea688a48c160d5de590515de7fcfca9bc4860 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 b4388efb1c693caebcbcd82be78dc47d85868bf3..89affe61e0ca8b79dce9d7c77382e89551bf9f87 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 8e790bbc6bb8cf83cb78b3cf8e87113e255e31db..e56059b1a212d872d7948cd9b1840986829a7870 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 59e20b3530ec4a5c97df565b512f5d592f7ee019..6e2916411bb280d4a9986a3466075526afe9248d 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 1361725ec2bb8975d7a0059c8e10a95c8eb5bf6a..d28d09d0305f18150e217e1b89e8c20283632bcd 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 a9a7629d1a891b16a55991a863e9b29e563f5141..53b9689b4553ea8127789b2ff4a2ffa4d8d25ff9 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 d9a9e7a9d266d218846446bc5e852b7cb9c9b5be..f6608a5b7c463244418fdb285a28a23dbff4e39b 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 cfe0b868d74251682ef8b7803d8c81a581bbe6ae..85be1c4715b9dfeaf49a9e6ff25468d905ae534e 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 796cdf6d7cdc2895e74ee6f52b5e3f016f0795d3..1ae6996c4a19b3a7222f9e5234221740a57fec34 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 84b7df0036d1ddc8438209150913ba0f508064c9..b1ae05ac4fa2d2b78797fc6ce624de7c3ed322de 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 b01dec6bff8ce3b082b0e1f7b3acca667f33622d..051db3781e49fb7ac6d455000ab0be5c5d6a6d09 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 e27dcc0c6adcaca510f4a92a153d317223ea2fc6..6f0b87e6271e3e855672c2e34258d2b90f119730 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 ef0fd33d6089216b74cae451297ab9972fbbd0d7..db80b49e8ad44b939cd7bc052e5bb2360cff9483 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 dd1b0909194cd9a1fcd0bdf351423ff3241f58fc..fe42f3c2a252040f5bdf23d0bbf76d9a066be628 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 c27649d77c68eaf512247b8525fab8eb18ac5418..ee1322fdc09a37515f83804f4a69b2eeddc7e04c 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 52d297a69a560b1f697c2aef8f58a043cdcccd3a..575cb048bac5985b1a739c793791e737be466813 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 cd5cb39a85c015756b81fb323d23c7238a59fb7f..117e7f505d78f4e4c2f2b949601709f4462afdf5 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 df574758242c294ddc8140b8a11def8f919954cd..072ce891da8109eb817dda2c2e623258a194da12 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 508e3e8eb00096353bfbc7f27cdb3ab11a670d4c..9a6b8e7ae8146c27649cb1f3cf2c88f61ff174d9 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 82f72e866b45fa866898da557f8462dd2c2587bb..f550056ca065999e3d831ea0d3d89ccd7d4093e5 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 590a58b92badf07e06a36584ee79bc7f0598bc1f..68393e97be43b7629488d56021669e20d50879c0 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 eaa2a92420d2cbeca29be9f02dc41ea00d1b717d..60206a4db5711a193d52b2985b58e04816555f70 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 20793f82cd184806447c22e6806f40fb4742f23f..1efaeca724d033b1bea59889a10901d46b526950 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 fea59bc2aa3a34f7c794dd0fcf218fbe9ce5aac9..1cdf23ec0efee9ec0812f457d47193ed3f2287a9 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 49e23bc9b026a4c37375b2b0e5171fcf2079e811..e27e2d7a06e40c2540b2d9773dfadb2e2a28b96e 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 4736a1eb46340dcc0b1b87ba7fd9220f6eac65ed..41876f5e2ae39170291325879ed0aceafdbda2d5 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 923d7512f3798e35c762d838eadf3451df5bcd8a..394e1df42800a7c9b7d5b1f43328c3a930459793 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 159c31ee4e637c0bd3d99716036d0d38827b764e..7dc51413e5019a30eb116ac743c6d0215794ff9d 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 b7b56ecaf311307dc968bf4f7283e44d4297ee48..de56b330ba150245c08b4a02b65cb43725d1e61e 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 3336941f46a12bdc7c14844f2fab6634505a8837..763745aa25bebf105632e5b639d4a9de62609f82 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 260ea509abde74dbe9b0c16f52c1e1c608291b5c..d641da05875aa6af8a2a8dddb37b53516a2cc8a9 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 162a9df9416b359f68a8117233f8eaaf73b47d8f..971856d92c69ad023b075271f365895a8b9d232f 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 c556e3ebd3055f74b796d15e77c346cfe9180320..f02b5ef7f1fe7e67d6083fc68e20c1cf1b123448 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 3a6c6e98aad6a06a34aab1b340197c7458f8963d..9e3c93f5b0cd9a9fd5d94039671b78b4f9019df2 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 34487f262065e2634543a56df65d5286c9f7e77c..3e8c78226ae7972740cf9878110a4f3b7f1e06c1 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 1a57de375c9182ba49d4aec4961ccd1fdd535d82..dfe975357db612f9b9c070c416fa4cccf066e898 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 5b1cd5f8cd777d77a2271abdc37c257a3932f9a9..eb1f21d22497cfcd75050f6ff4366da5b6e4721b 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 d1ed8278727ac6e519829b4c3e14dbfd363ac799..262122f8bf5a0102238f3030750755463070ef6d 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 01b67843c4ecb71485d093d0f909219f4aa13de0..f987de06340e7bebff1be61f824726c65dba5fd3 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 c913550406c20f818475a1d2e6bbca6825d0fa58..867aff11cfc98a125bb219170cdc8004f19f6e4b 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 1f20f10b295d7a923003465d99b4b3f66f47e540..445b3f0b813b6961b4e0323d8f89d48b14acc2e4 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 2f146ea2ebb9cfa6dcfb45221548424b0330874d..3ecbd4d1ca051116d35f3426e0f6a7a3dcd4c34e 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 ee48b60429054f48d4e0f23603067fc2ba1a4c82..636a0309b7721286b747ba2f9ed5048aab96ab9d 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 a984a57b387ed96e06059283f50a21f6a435c656..1fd1bd0ecddb121772cb128e44b2b7018b470ab7 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 7876080e84d3577c4362ef908171eb8ab1c53967..fd421743fe0dd56f435ac0cc0e90909307f4f449 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 f1b5dc58c6275fc9bed58b16bd55aab113ca5c23..5927583cc30d10ebc5392c27a706e91d9874d24d 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 e3c7cc20edf0f3ac430207bb0c12bc4472333a9a..07d1ffc14678b23846ec52a499dcf4847683f109 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 87990ec39a0a85f35ab3d630ffc5d47e329ddf8c..fabc873f5ea8467ad609f9657bf37a044135a4f4 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 412c22ef8660d7c69eb5c667806821cce9f4a723..ac3ce897a75ea3f406134ea77bad7e56d37c150a 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 2dc64cb0399ef576ede9d00160e764436ec97a1f..69a078a22e5edb214b31fe6dda91f7d60b20359c 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 03ccd0fd61657c543483b330dc63cc25970cd753..661f07759c2ab273cad3d042b84b922487f79dc3 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 b930c685fe0aaf58d23d9a67cf291e29df35b818..d54f983e835e65f587e2be0e5043fff766abd62b 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 3e2ec313e4bdeb120533f0b0c975fd5ef906f079..fc5d7b1b8deba9ddc2e2ab700c0930e7befd5031 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 bc09a69dde6626c7965c1c500bf519bda0fe691c..4e2ebaab6d1724bf6442e2e4847b320d18294938 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 81bf9400b3a0b652630466594c48aefbf3590a4a..001b19df7ba4b3955a3b4ef3ec9bb05715faa124 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 1aaedfa1d59f0bbe81a3f11303a8e808a0d5ff17..03fb6b86c0c2ec9679481f7c89b81e5732315d0c 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 2817f74ac51b7aab0d2b4c734b44e05d3830d38f..3663e35f59448df15cee99cc86f265ec6d45dc4e 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 5fed1729e341239956394ba4bcb121ea8cc890d1..6b04ff48b6534eeca6f0dddf0227dca0a2c782fb 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 4a36f839210c078eafb14a27f847a7e0a0b68735..838b5d234f1635939deeac6aa662b96ac925f255 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 f84425911dfb9df7534308c2926fa6373eeb7666..283005fd6dc1e49a7ad4de1a7e718227a5414fd7 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 8853d2a642cb890b083ceea8509adadefbdc3bf2..3031b000d631f80a444420cbf470b62db5d5cb8c 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 5db5fb6b0d01853b0ce10836feaf00d7875713be..0c8e96e71f2c96ef0ab86232cf19f52eafbc5805 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 aed1acadf6d91a094593df767508c4ead8fff080..d584a02b7611c11288554dc06d4fa57cd0619b44 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 0503737b2a2e29c2b0a6626c11cf27bd305a09b1..dbe35efb5342257fc348b61beb429dca114023e9 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 88e9e26b980662cd0dc67789837be7e88a3fa44a..f6285521d08f1e95b86de69057fd542a88b90516 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 22c7a2bae8a750e62ca1e474b930de0091afdce9..1697fdea018e88a638339008a8499a1115cfdaa4 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 d456c3e032123072e550d0fa550f46df185696e8..a19e3103a84962921a6acd410396534ef6aca774 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 d16be2cb484c4c4707425e09ff78b48157177e0b..1fa596f139c91161a307f14ba6e9b3e9756f9c7d 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 bfba6324946cb0840eb30fd0e3ddaca341a6af6c..2b319aedf35bf9aec0b2bf0985539b886a168c2f 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 ec120d79230d03d2cd140cbaefcb9cb0518002cc..20eae6f21a43e77c715f68e5d098027e5132a3d6 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 e002ea79d46a28523aa4f7fdf8f94d0fc7a46969..6bc87cd8aeda65ec6a9adc893b218028c71d23c1 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 4167afdb88faea570b3477629fba9573bb3ab02c..b91bb1e849cc3ab5b0423df1fc80c235f5d26d49 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 );