From e8cf2a2c623ed31a30332de0e714906fb417e180 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 19 Feb 2021 12:18:19 +0100 Subject: [PATCH] ENH: more consistent use of IOstreamOption - improves interface and data consistency. Older signatures are still active (via the Foam_IOstream_extras define). - refine internals for IOstreamOption streamFormat, versionNumber ENH: improve data alignment for IOstream and IOobject - fit sizeof label/scalar into unsigned char STYLE: remove dead code --- .../test/primitives/Test-primitives.C | 4 +- applications/test/sizeof/Test-sizeof.C | 4 +- src/OpenFOAM/db/IOobject/IOobject.C | 44 +++--- src/OpenFOAM/db/IOobject/IOobject.H | 29 ++-- src/OpenFOAM/db/IOobject/IOobjectI.H | 10 +- src/OpenFOAM/db/IOobject/IOobjectReadHeader.C | 12 +- .../decomposedBlockData/decomposedBlockData.C | 49 +++--- .../decomposedBlockData/decomposedBlockData.H | 5 +- src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C | 4 +- src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H | 4 +- src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H | 8 +- .../db/IOstreams/Fstreams/masterOFstream.C | 8 +- .../db/IOstreams/Fstreams/masterOFstream.H | 12 +- .../db/IOstreams/IOstreams/IOstream.H | 142 +++++++++--------- .../db/IOstreams/IOstreams/IOstreamOption.H | 57 +++---- src/OpenFOAM/db/IOstreams/IOstreams/Istream.H | 10 +- src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H | 8 +- src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C | 9 +- src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H | 8 +- src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C | 7 +- src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H | 9 +- .../db/IOstreams/Pstreams/PstreamBuffers.C | 9 +- .../db/IOstreams/Pstreams/PstreamBuffers.H | 9 +- .../db/IOstreams/Pstreams/UIPstream.H | 6 +- .../db/IOstreams/Pstreams/UOPstream.C | 6 +- .../db/IOstreams/Pstreams/UOPstream.H | 4 +- src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H | 10 +- src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H | 10 +- .../db/IOstreams/Sstreams/prefixOSstream.H | 12 +- .../db/IOstreams/StringStreams/StringStream.H | 91 ++++++++--- src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C | 39 ++--- src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H | 132 +++++++++++++--- src/OpenFOAM/db/IOstreams/Tstreams/OTstream.C | 6 +- src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H | 28 ++-- .../db/IOstreams/hashes/OSHA1stream.H | 42 +++--- .../db/IOstreams/memory/IListStream.H | 64 ++++++-- .../db/IOstreams/memory/OCountStream.H | 24 ++- .../db/IOstreams/memory/OListStream.H | 72 +++++++-- .../db/IOstreams/memory/UIListStream.H | 102 +++++++++---- .../db/IOstreams/memory/UOListStream.H | 111 ++++++++++---- src/OpenFOAM/db/Time/TimeIO.C | 2 +- .../primitiveEntry/primitiveEntryIO.C | 5 +- src/OpenFOAM/db/regIOobject/regIOobject.H | 10 +- src/OpenFOAM/db/regIOobject/regIOobjectRead.C | 6 +- .../db/regIOobject/regIOobjectWrite.C | 47 +----- .../global/debug/simpleObjectRegistry.C | 4 +- .../collatedFileOperation/OFstreamCollator.C | 55 ++----- .../collatedFileOperation/OFstreamCollator.H | 51 +++---- .../collatedFileOperation.C | 30 ++-- .../collatedFileOperation.H | 14 +- .../hostCollatedFileOperation.H | 5 +- .../threadedCollatedOFstream.C | 8 +- .../threadedCollatedOFstream.H | 27 ++-- .../fileOperation/fileOperation.H | 4 +- .../masterUncollatedFileOperation.C | 10 +- .../masterUncollatedFileOperation.H | 12 +- .../uncollatedFileOperation.C | 4 +- .../uncollatedFileOperation.H | 6 +- .../tableReaders/csv/csvTableReader.C | 7 +- .../polyBoundaryMesh/polyBoundaryMesh.C | 2 +- .../primitives/functions/Function1/CSV/CSV.C | 7 +- src/Pstream/dummy/UIPread.C | 10 +- src/Pstream/mpi/UIPread.C | 6 +- src/conversion/ccm/reader/ccmReader.C | 8 +- src/conversion/ccm/reader/ccmReader.H | 7 +- src/conversion/ccm/reader/ccmReaderAux.C | 16 +- src/conversion/common/reader/meshReader.C | 10 +- src/conversion/common/reader/meshReader.H | 6 +- src/conversion/common/reader/meshReaderAux.C | 12 +- src/conversion/fire/FIREMeshReader.C | 2 +- .../ensight/read/ensightReadFile.C | 6 +- .../ensight/read/ensightReadFile.H | 6 +- src/fileFormats/fire/FIRECore.C | 2 +- src/fileFormats/obj/OBJstream.H | 10 +- .../readers/ensight/ensightSurfaceReader.H | 4 +- .../surfaceFormats/stl/STLsurfaceFormat.C | 10 +- .../surfaceFormats/stl/STLsurfaceFormat.H | 10 +- 77 files changed, 972 insertions(+), 689 deletions(-) diff --git a/applications/test/primitives/Test-primitives.C b/applications/test/primitives/Test-primitives.C index 0064400290..1fe56e2ae9 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()) << nl; diff --git a/applications/test/sizeof/Test-sizeof.C b/applications/test/sizeof/Test-sizeof.C index 78423b0e04..692531acab 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 e25418fef3..7b0928ebe6 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(sizeof(label))), + sizeofScalar_(static_cast(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(sizeof(label))), + sizeofScalar_(static_cast(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(sizeof(label))), + sizeofScalar_(static_cast(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 e8f35947f7..409c503690 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 scalar byte-size (could also be stored as byte) - unsigned short scalarByteSize_; + //- The sizeof (scalar) in bytes, possibly read from the header + unsigned char sizeofScalar_; + + //- 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 2c4f7a84f2..345ca59dd6 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(sizeofLabel_); } -inline unsigned Foam::IOobject::scalarByteSize() const +inline unsigned Foam::IOobject::scalarByteSize() const noexcept { - return scalarByteSize_; + return static_cast(sizeofScalar_); } diff --git a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C index 7726a6d76a..ed0ea688a4 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(val); val = foamVersion::scalarByteSize(arch); - if (val) scalarByteSize_ = val; + if (val) sizeofScalar_ = static_cast(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 b4388efb1c..89affe61e0 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::decomposedBlockData::readBlock List 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::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