diff --git a/applications/test/foamVersion/Test-foamVersion.C b/applications/test/foamVersion/Test-foamVersion.C index fc8490df3425e707ecf617f5ec7962a67e4b21bb..3029ac0cf059a4f4b9a2adcba1b47de9d0a64053 100644 --- a/applications/test/foamVersion/Test-foamVersion.C +++ b/applications/test/foamVersion/Test-foamVersion.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,6 +36,17 @@ Description using namespace Foam; + +// Test extraction +void testExtraction(const std::string& str) +{ + Info<< "Extract: " << str << " =>" + << " label: " << foamVersion::labelByteSize(str) << " bytes" + << " scalar: " << foamVersion::scalarByteSize(str) << " bytes" + << nl; +} + + int main() { Info @@ -70,6 +81,29 @@ int main() << "macro " << long(Foam::FOAMversion) << nl << "namespace " << long(&(foamVersion::version[0])) << nl; + + // Test extraction + { + Info<< "\nTest size extraction routines" << nl; + + for + ( + const std::string& str : + { + "MSB;label=32;scalar=64", + "LSB;label=64;scalar=32", + "LSB;label=;scalar=junk", + "LSB;label==;scalar=128", + "", + "LSB;label;scalar", + "LSB label=32 scalar=64", + } + ) + { + testExtraction(str); + } + } + Info << "\nEnd\n" << endl; diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index 14c3eba99ec834382a43b72ff97accba63107709..f6354f2a5dc383c319e4af09352f16da5db36a0e 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -267,7 +267,9 @@ Foam::IOobject::IOobject wOpt_(wo), registerObject_(registerObject), globalObject_(false), - objState_(GOOD) + objState_(GOOD), + labelByteSize_(sizeof(Foam::label)), + scalarByteSize_(sizeof(Foam::scalar)) { if (objectRegistry::debug) { @@ -301,7 +303,9 @@ Foam::IOobject::IOobject wOpt_(wo), registerObject_(registerObject), globalObject_(globalObject), - objState_(GOOD) + objState_(GOOD), + labelByteSize_(sizeof(Foam::label)), + scalarByteSize_(sizeof(Foam::scalar)) { if (objectRegistry::debug) { @@ -333,7 +337,9 @@ Foam::IOobject::IOobject wOpt_(wo), registerObject_(registerObject), globalObject_(globalObject), - objState_(GOOD) + objState_(GOOD), + labelByteSize_(sizeof(Foam::label)), + scalarByteSize_(sizeof(Foam::scalar)) { if (!fileNameComponents(path, instance_, local_, name_)) { @@ -368,7 +374,9 @@ Foam::IOobject::IOobject wOpt_(io.wOpt_), registerObject_(io.registerObject_), globalObject_(io.globalObject_), - objState_(io.objState_) + objState_(io.objState_), + labelByteSize_(io.labelByteSize_), + scalarByteSize_(io.scalarByteSize_) {} @@ -388,7 +396,9 @@ Foam::IOobject::IOobject wOpt_(io.wOpt_), registerObject_(io.registerObject_), globalObject_(io.globalObject_), - objState_(io.objState_) + objState_(io.objState_), + labelByteSize_(io.labelByteSize_), + scalarByteSize_(io.scalarByteSize_) {} diff --git a/src/OpenFOAM/db/IOobject/IOobject.H b/src/OpenFOAM/db/IOobject/IOobject.H index 46a4b1791f2c784db3d61a9c8c2b4bfa373935e4..be81dcf4ef6599de3b128e15489cfb0b632def62 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.H +++ b/src/OpenFOAM/db/IOobject/IOobject.H @@ -101,14 +101,14 @@ public: // Public data types //- Enumeration defining the valid states of an IOobject - enum objectState + enum objectState : char { GOOD, BAD }; //- Enumeration defining the read options - enum readOption + enum readOption : char { MUST_READ, MUST_READ_IF_MODIFIED, @@ -117,14 +117,14 @@ public: }; //- Enumeration defining the write options - enum writeOption + enum writeOption : char { AUTO_WRITE = 0, NO_WRITE = 1 }; //- Enumeration defining the file checking options - enum fileCheckTypes + enum fileCheckTypes : char { timeStamp, timeStampMaster, @@ -132,12 +132,13 @@ public: inotifyMaster }; + //- Names for the fileCheckTypes static const Enum<fileCheckTypes> fileCheckTypesNames; private: - // Private data + // Private Data //- Name word name_; @@ -172,6 +173,12 @@ private: //- IOobject state objectState objState_; + //- The label byte-size (could also be stored as byte) + unsigned short labelByteSize_; + + //- The scalar byte-size (could also be stored as byte) + unsigned short scalarByteSize_; + protected: @@ -360,6 +367,12 @@ public: //- Is object same for all processors inline bool& globalObject(); + //- The label byte-size, possibly read from the header + inline unsigned labelByteSize() const; + + //- The scalar byte-size, possibly read from the header + inline unsigned scalarByteSize() const; + // Checks diff --git a/src/OpenFOAM/db/IOobject/IOobjectI.H b/src/OpenFOAM/db/IOobject/IOobjectI.H index 7d040c32c0f37ed31786182f378a65020ca4bb80..92e157e1d454e50130a09eec4564c4454dbd7b70 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectI.H +++ b/src/OpenFOAM/db/IOobject/IOobjectI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -107,6 +107,18 @@ inline bool& Foam::IOobject::globalObject() } +inline unsigned Foam::IOobject::labelByteSize() const +{ + return labelByteSize_; +} + + +inline unsigned Foam::IOobject::scalarByteSize() const +{ + return scalarByteSize_; +} + + // Checks inline bool Foam::IOobject::isHeaderClassName(const word& clsName) const diff --git a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C index c4ec29725293d2c2e771f32007c8a42f74043e57..50a2b380202c2f4c3f6832af69290bd5da1ad98f 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -27,6 +27,7 @@ License #include "IOobject.H" #include "dictionary.H" +#include "foamVersion.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -93,6 +94,20 @@ bool Foam::IOobject::readHeader(Istream& is) // The note entry is optional headerDict.readIfPresent("note", note_); + + labelByteSize_ = sizeof(Foam::label); + scalarByteSize_ = sizeof(Foam::scalar); + + // The arch information is optional + string arch; + if (headerDict.readIfPresent("arch", arch)) + { + unsigned val = foamVersion::labelByteSize(arch); + if (val) labelByteSize_ = val; + + val = foamVersion::scalarByteSize(arch); + if (val) scalarByteSize_ = val; + } } else { diff --git a/src/OpenFOAM/global/global.Cver b/src/OpenFOAM/global/global.Cver index 0076c9dc45cbf7d7986c7ae4d026cb736a49bdc8..cf03f6aad4d8ec80035e6e555d35e6efb1ac5ad1 100644 --- a/src/OpenFOAM/global/global.Cver +++ b/src/OpenFOAM/global/global.Cver @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011 OpenFOAM Foundation @@ -38,9 +38,34 @@ Description #include "label.H" #include "scalar.H" +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +namespace +{ + +// Extract value from "tag=<digits>", eg "LSB;label=32;scalar=64" +// Return 0 on any errors +static inline unsigned getTaggedSize(const char* tag, const std::string& s) +{ + auto first = s.find(tag); + if (first == std::string::npos) return 0; + + first = s.find('=', first); + if (first == std::string::npos) return 0; + ++first; + + auto last = s.find_first_not_of("0123456789", first); + if (last == first) return 0; + + return std::stoul(s.substr(first, last)); +} + +} // End namespace anonymous + + // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -// Value from OPENFOAM, defined in wmake rules +// Value of OPENFOAM defined in wmake rules const int Foam::foamVersion::api ( OPENFOAM @@ -54,7 +79,7 @@ const std::string Foam::foamVersion::patch ); -// Value of the BUILD generated by the build-script +// Value of BUILD generated by the build-script const std::string Foam::foamVersion::build ( "@BUILD@" @@ -84,6 +109,18 @@ const std::string Foam::foamVersion::version ); +unsigned Foam::foamVersion::labelByteSize(const std::string& str) +{ + return getTaggedSize("label=", str) / 8; +} + + +unsigned Foam::foamVersion::scalarByteSize(const std::string& str) +{ + return getTaggedSize("scalar=", str) / 8; +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Setup an error handler for the global new operator diff --git a/src/OpenFOAM/include/foamVersion.H b/src/OpenFOAM/include/foamVersion.H index 80c730f84073e03783100928605d75cb812de9ec..9ee531157681185a8f481158a6b4f60db27e5947 100644 --- a/src/OpenFOAM/include/foamVersion.H +++ b/src/OpenFOAM/include/foamVersion.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -100,6 +100,12 @@ namespace Foam //- which is when it is defined (non-zero). bool patched(); + //- Extract label size (in bytes) from "label=" tag in string + unsigned labelByteSize(const std::string& str); + + //- Extract scalar size (in bytes) from "scalar=" tag in string + unsigned scalarByteSize(const std::string& str); + //- Print information about version, build, arch to Info // // Eg,