mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -36,6 +36,17 @@ Description
|
|||||||
|
|
||||||
using namespace Foam;
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
Info
|
Info
|
||||||
@ -70,6 +81,29 @@ int main()
|
|||||||
<< "macro " << long(Foam::FOAMversion) << nl
|
<< "macro " << long(Foam::FOAMversion) << nl
|
||||||
<< "namespace " << long(&(foamVersion::version[0])) << 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
|
Info
|
||||||
<< "\nEnd\n" << endl;
|
<< "\nEnd\n" << endl;
|
||||||
|
|
||||||
|
|||||||
@ -267,7 +267,9 @@ Foam::IOobject::IOobject
|
|||||||
wOpt_(wo),
|
wOpt_(wo),
|
||||||
registerObject_(registerObject),
|
registerObject_(registerObject),
|
||||||
globalObject_(false),
|
globalObject_(false),
|
||||||
objState_(GOOD)
|
objState_(GOOD),
|
||||||
|
labelByteSize_(sizeof(Foam::label)),
|
||||||
|
scalarByteSize_(sizeof(Foam::scalar))
|
||||||
{
|
{
|
||||||
if (objectRegistry::debug)
|
if (objectRegistry::debug)
|
||||||
{
|
{
|
||||||
@ -301,7 +303,9 @@ Foam::IOobject::IOobject
|
|||||||
wOpt_(wo),
|
wOpt_(wo),
|
||||||
registerObject_(registerObject),
|
registerObject_(registerObject),
|
||||||
globalObject_(globalObject),
|
globalObject_(globalObject),
|
||||||
objState_(GOOD)
|
objState_(GOOD),
|
||||||
|
labelByteSize_(sizeof(Foam::label)),
|
||||||
|
scalarByteSize_(sizeof(Foam::scalar))
|
||||||
{
|
{
|
||||||
if (objectRegistry::debug)
|
if (objectRegistry::debug)
|
||||||
{
|
{
|
||||||
@ -333,7 +337,9 @@ Foam::IOobject::IOobject
|
|||||||
wOpt_(wo),
|
wOpt_(wo),
|
||||||
registerObject_(registerObject),
|
registerObject_(registerObject),
|
||||||
globalObject_(globalObject),
|
globalObject_(globalObject),
|
||||||
objState_(GOOD)
|
objState_(GOOD),
|
||||||
|
labelByteSize_(sizeof(Foam::label)),
|
||||||
|
scalarByteSize_(sizeof(Foam::scalar))
|
||||||
{
|
{
|
||||||
if (!fileNameComponents(path, instance_, local_, name_))
|
if (!fileNameComponents(path, instance_, local_, name_))
|
||||||
{
|
{
|
||||||
@ -368,7 +374,9 @@ Foam::IOobject::IOobject
|
|||||||
wOpt_(io.wOpt_),
|
wOpt_(io.wOpt_),
|
||||||
registerObject_(io.registerObject_),
|
registerObject_(io.registerObject_),
|
||||||
globalObject_(io.globalObject_),
|
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_),
|
wOpt_(io.wOpt_),
|
||||||
registerObject_(io.registerObject_),
|
registerObject_(io.registerObject_),
|
||||||
globalObject_(io.globalObject_),
|
globalObject_(io.globalObject_),
|
||||||
objState_(io.objState_)
|
objState_(io.objState_),
|
||||||
|
labelByteSize_(io.labelByteSize_),
|
||||||
|
scalarByteSize_(io.scalarByteSize_)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -101,14 +101,14 @@ public:
|
|||||||
// Public data types
|
// Public data types
|
||||||
|
|
||||||
//- Enumeration defining the valid states of an IOobject
|
//- Enumeration defining the valid states of an IOobject
|
||||||
enum objectState
|
enum objectState : char
|
||||||
{
|
{
|
||||||
GOOD,
|
GOOD,
|
||||||
BAD
|
BAD
|
||||||
};
|
};
|
||||||
|
|
||||||
//- Enumeration defining the read options
|
//- Enumeration defining the read options
|
||||||
enum readOption
|
enum readOption : char
|
||||||
{
|
{
|
||||||
MUST_READ,
|
MUST_READ,
|
||||||
MUST_READ_IF_MODIFIED,
|
MUST_READ_IF_MODIFIED,
|
||||||
@ -117,14 +117,14 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
//- Enumeration defining the write options
|
//- Enumeration defining the write options
|
||||||
enum writeOption
|
enum writeOption : char
|
||||||
{
|
{
|
||||||
AUTO_WRITE = 0,
|
AUTO_WRITE = 0,
|
||||||
NO_WRITE = 1
|
NO_WRITE = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
//- Enumeration defining the file checking options
|
//- Enumeration defining the file checking options
|
||||||
enum fileCheckTypes
|
enum fileCheckTypes : char
|
||||||
{
|
{
|
||||||
timeStamp,
|
timeStamp,
|
||||||
timeStampMaster,
|
timeStampMaster,
|
||||||
@ -132,12 +132,13 @@ public:
|
|||||||
inotifyMaster
|
inotifyMaster
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//- Names for the fileCheckTypes
|
||||||
static const Enum<fileCheckTypes> fileCheckTypesNames;
|
static const Enum<fileCheckTypes> fileCheckTypesNames;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Private data
|
// Private Data
|
||||||
|
|
||||||
//- Name
|
//- Name
|
||||||
word name_;
|
word name_;
|
||||||
@ -172,6 +173,12 @@ private:
|
|||||||
//- IOobject state
|
//- IOobject state
|
||||||
objectState objState_;
|
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:
|
protected:
|
||||||
|
|
||||||
@ -360,6 +367,12 @@ public:
|
|||||||
//- Is object same for all processors
|
//- Is object same for all processors
|
||||||
inline bool& globalObject();
|
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
|
// Checks
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2004-2010, 2017 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2004-2010, 2017-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
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
|
// Checks
|
||||||
|
|
||||||
inline bool Foam::IOobject::isHeaderClassName(const word& clsName) const
|
inline bool Foam::IOobject::isHeaderClassName(const word& clsName) const
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2004-2010, 2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
@ -27,6 +27,7 @@ License
|
|||||||
|
|
||||||
#include "IOobject.H"
|
#include "IOobject.H"
|
||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
|
#include "foamVersion.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -93,6 +94,20 @@ bool Foam::IOobject::readHeader(Istream& is)
|
|||||||
|
|
||||||
// The note entry is optional
|
// The note entry is optional
|
||||||
headerDict.readIfPresent("note", note_);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2004-2011, 2018 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2004-2011, 2018-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2011 OpenFOAM Foundation
|
| Copyright (C) 2011 OpenFOAM Foundation
|
||||||
@ -38,9 +38,34 @@ Description
|
|||||||
#include "label.H"
|
#include "label.H"
|
||||||
#include "scalar.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 * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
// Value from OPENFOAM, defined in wmake rules
|
// Value of OPENFOAM defined in wmake rules
|
||||||
const int Foam::foamVersion::api
|
const int Foam::foamVersion::api
|
||||||
(
|
(
|
||||||
OPENFOAM
|
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
|
const std::string Foam::foamVersion::build
|
||||||
(
|
(
|
||||||
"@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
|
// Setup an error handler for the global new operator
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2004-2010, 2017-2018 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2004-2010, 2017-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -100,6 +100,12 @@ namespace Foam
|
|||||||
//- which is when it is defined (non-zero).
|
//- which is when it is defined (non-zero).
|
||||||
bool patched();
|
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
|
//- Print information about version, build, arch to Info
|
||||||
//
|
//
|
||||||
// Eg,
|
// Eg,
|
||||||
|
|||||||
Reference in New Issue
Block a user