Commit b0fb84b7 authored by Mark Olesen's avatar Mark Olesen

ENH: add tracking of label/scalar size when reading IOobject header

- extracts values from the arch "LSB;label=32;scalar=64" header entry
  to provision for managing dissimilar primitive sizes.

  Compensate for the additional IOobject members by narrowing the types
  for the (objectState, readOption, writeOption) enumerations
parent 8413f620
......@@ -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;
......
......@@ -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_)
{}
......
......@@ -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
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010, 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2010, 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
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2010, 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
{
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011, 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011, 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
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010, 2017-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2010, 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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment