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