mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add construct dimensionedType from primitiveEntry
- allows direct reading of a single entry with token checking
This commit is contained in:
committed by
Andrew Heather
parent
3e9562f781
commit
07fb19e9d8
@ -26,6 +26,8 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
|
#include "primitiveEntry.H"
|
||||||
|
#include "dimensionedScalar.H"
|
||||||
#include "dimensionedTensor.H"
|
#include "dimensionedTensor.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
@ -161,7 +163,24 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Info<< nl << "Dictionary is now: " << dict << nl;
|
Info<< nl << "Dictionary is now: " << dict << nl;
|
||||||
|
|
||||||
Info<< "End\n" << endl;
|
|
||||||
|
{
|
||||||
|
primitiveEntry entry1("scalar1", token(15.0));
|
||||||
|
|
||||||
|
// The same:
|
||||||
|
// primitiveEntry entry1("scalar1", ITstream::parse(" 15.0 "));
|
||||||
|
|
||||||
|
// This fails (as it should):
|
||||||
|
// primitiveEntry entry1("scalar1", ITstream::parse(" 15.0 25.0 "));
|
||||||
|
|
||||||
|
dimensionedScalar ds1(entry1);
|
||||||
|
|
||||||
|
Info<< "construct from entry: "
|
||||||
|
<< entry1 << nl
|
||||||
|
<< " = " << ds1 << nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< "\nEnd\n" << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -162,6 +162,45 @@ Foam::dimensioned<Type>::dimensioned
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::dimensioned<Type>::dimensioned
|
||||||
|
(
|
||||||
|
const primitiveEntry& e
|
||||||
|
)
|
||||||
|
:
|
||||||
|
name_(e.name()),
|
||||||
|
dimensions_(),
|
||||||
|
value_(Zero)
|
||||||
|
{
|
||||||
|
ITstream& is = e.stream();
|
||||||
|
|
||||||
|
// no checkDims
|
||||||
|
initialize(is, false);
|
||||||
|
|
||||||
|
e.checkITstream(is);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::dimensioned<Type>::dimensioned
|
||||||
|
(
|
||||||
|
const primitiveEntry& e,
|
||||||
|
const dimensionSet& dims
|
||||||
|
)
|
||||||
|
:
|
||||||
|
name_(e.name()),
|
||||||
|
dimensions_(dims),
|
||||||
|
value_(Zero)
|
||||||
|
{
|
||||||
|
ITstream& is = e.stream();
|
||||||
|
|
||||||
|
// checkDims
|
||||||
|
initialize(is, true);
|
||||||
|
|
||||||
|
e.checkITstream(is);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
Foam::dimensioned<Type>::dimensioned
|
Foam::dimensioned<Type>::dimensioned
|
||||||
(
|
(
|
||||||
|
|||||||
@ -50,6 +50,7 @@ namespace Foam
|
|||||||
// Forward declarations
|
// Forward declarations
|
||||||
class zero;
|
class zero;
|
||||||
class dictionary;
|
class dictionary;
|
||||||
|
class primitiveEntry;
|
||||||
|
|
||||||
template<class Type> class dimensioned;
|
template<class Type> class dimensioned;
|
||||||
|
|
||||||
@ -146,8 +147,31 @@ public:
|
|||||||
const Type& val
|
const Type& val
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Construct from primitive entry with given name.
|
||||||
|
// The entry may contain optional name and dimensions.
|
||||||
|
// \verbatim
|
||||||
|
// [name] [dims] value
|
||||||
|
// \endverbatim
|
||||||
|
// If the optional name is found, it is used for renaming.
|
||||||
|
// If the optional dimensions are present, they are read and
|
||||||
|
// used without further verification.
|
||||||
|
// If no dimensions are found, the quantity is dimensionless.
|
||||||
|
// Fatal if not a primitiveEntry or if the number of tokens is incorrect.
|
||||||
|
explicit dimensioned(const primitiveEntry& e);
|
||||||
|
|
||||||
|
//- Construct from primitive entry with given name and dimensions.
|
||||||
|
// The entry may contain optional name and dimensions.
|
||||||
|
// \verbatim
|
||||||
|
// [name] [dims] value
|
||||||
|
// \endverbatim
|
||||||
|
// If the optional name is found, it is used for renaming.
|
||||||
|
// If the optional dimensions are present, they are read and
|
||||||
|
// verified against the expected dimensions.
|
||||||
|
// Fatal if not a primitiveEntry or if the number of tokens is incorrect.
|
||||||
|
explicit dimensioned(const primitiveEntry& e, const dimensionSet& dims);
|
||||||
|
|
||||||
//- Construct from dictionary lookup with a given name.
|
//- Construct from dictionary lookup with a given name.
|
||||||
// The dictionary entry may contain optional name and dimensions.
|
// The entry may contain optional name and dimensions.
|
||||||
// \verbatim
|
// \verbatim
|
||||||
// [name] [dims] value
|
// [name] [dims] value
|
||||||
// \endverbatim
|
// \endverbatim
|
||||||
@ -158,7 +182,7 @@ public:
|
|||||||
dimensioned(const word& name, const dictionary& dict);
|
dimensioned(const word& name, const dictionary& dict);
|
||||||
|
|
||||||
//- Construct from dictionary lookup with a given name and dimensions.
|
//- Construct from dictionary lookup with a given name and dimensions.
|
||||||
// The dictionary entry may contain optional name and dimensions.
|
// The entry may contain optional name and dimensions.
|
||||||
// \verbatim
|
// \verbatim
|
||||||
// [name] [dims] value
|
// [name] [dims] value
|
||||||
// \endverbatim
|
// \endverbatim
|
||||||
@ -173,7 +197,7 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
//- Construct from dictionary lookup with a given name and dimensions.
|
//- Construct from dictionary lookup with a given name and dimensions.
|
||||||
// The dictionary entry may contain optional name and dimensions.
|
// The entry may contain optional name and dimensions.
|
||||||
// \verbatim
|
// \verbatim
|
||||||
// [name] [dims] value
|
// [name] [dims] value
|
||||||
// \endverbatim
|
// \endverbatim
|
||||||
@ -190,7 +214,7 @@ public:
|
|||||||
|
|
||||||
//- Construct from components (name, dimensions, value) with
|
//- Construct from components (name, dimensions, value) with
|
||||||
//- optional dictionary override.
|
//- optional dictionary override.
|
||||||
// The dictionary entry may contain optional name and dimensions.
|
// The entry may contain optional name and dimensions.
|
||||||
// \verbatim
|
// \verbatim
|
||||||
// [name] [dims] value
|
// [name] [dims] value
|
||||||
// \endverbatim
|
// \endverbatim
|
||||||
@ -341,14 +365,16 @@ public:
|
|||||||
//- Deprecated(2018-11) Construct from Istream
|
//- Deprecated(2018-11) Construct from Istream
|
||||||
//- (expects name, dimensions, value)
|
//- (expects name, dimensions, value)
|
||||||
// \deprecated(2018-11) - should generally use construct from
|
// \deprecated(2018-11) - should generally use construct from
|
||||||
// dictionary instead (additional checks on the input stream).
|
// dictionary or primitiveEntry instead
|
||||||
|
// (additional checks on the input stream).
|
||||||
explicit dimensioned(Istream& is)
|
explicit dimensioned(Istream& is)
|
||||||
FOAM_DEPRECATED(2018-11);
|
FOAM_DEPRECATED(2018-11);
|
||||||
|
|
||||||
//- Deprecated(2018-11) Construct from Istream with given name
|
//- Deprecated(2018-11) Construct from Istream with given name
|
||||||
//- (expects dimensions, value)
|
//- (expects dimensions, value)
|
||||||
// \deprecated(2018-11) - should generally use construct from
|
// \deprecated(2018-11) - should generally use construct from
|
||||||
// dictionary instead (additional checks on the input stream).
|
// dictionary or primitiveEntry instead
|
||||||
|
// (additional checks on the input stream).
|
||||||
dimensioned(const word& name, Istream& is)
|
dimensioned(const word& name, Istream& is)
|
||||||
FOAM_DEPRECATED(2018-11);
|
FOAM_DEPRECATED(2018-11);
|
||||||
|
|
||||||
@ -358,7 +384,8 @@ public:
|
|||||||
// If the optional dimensions are present, they are read and
|
// If the optional dimensions are present, they are read and
|
||||||
// verified against the expected dimensions.
|
// verified against the expected dimensions.
|
||||||
// \deprecated(2018-11) - should generally use construct from
|
// \deprecated(2018-11) - should generally use construct from
|
||||||
// dictionary instead (additional checks on the input stream).
|
// dictionary or primitiveEntry instead
|
||||||
|
// (additional checks on the input stream).
|
||||||
dimensioned(const word& name, const dimensionSet& dims, Istream& is)
|
dimensioned(const word& name, const dimensionSet& dims, Istream& is)
|
||||||
FOAM_DEPRECATED(2018-11);
|
FOAM_DEPRECATED(2018-11);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user