ENH: use dictionary::get<> instead of pTraits (#762)

- check Istream in readBool in operator>> variant (#1033)
This commit is contained in:
Mark Olesen
2018-11-20 10:10:39 +01:00
parent b9b8c523f2
commit efdbeae27e
4 changed files with 14 additions and 19 deletions

View File

@ -74,7 +74,7 @@ CONSTRUCT
: :
PARENT(p, iF), PARENT(p, iF),
scalarData_(dict.get<scalar>("scalarData")), scalarData_(dict.get<scalar>("scalarData")),
data_(pTraits<TYPE>(dict.lookup("data"))), data_(dict.get<TYPE>("data")),
fieldData_("fieldData", dict, p.size()), fieldData_("fieldData", dict, p.size()),
timeVsData_(Function1<TYPE>::New("timeVsData", dict)), timeVsData_(Function1<TYPE>::New("timeVsData", dict)),
wordData_(dict.lookupOrDefault<word>("wordName", "wordDefault")), wordData_(dict.lookupOrDefault<word>("wordName", "wordDefault")),

View File

@ -72,9 +72,13 @@ T dimensionedConstant
if (unitDict.found(group)) if (unitDict.found(group))
{ {
dictionary& groupDict = unitDict.subDict(group); dictionary& groupDict = unitDict.subDict(group);
// Leaner version of dictionary lookupOrAddDefault()
// without writeOptionalEntries
if (groupDict.found(varName)) if (groupDict.found(varName))
{ {
return pTraits<T>(groupDict.lookup(varName)); return groupDict.get<T>(varName);
} }
else else
{ {
@ -113,15 +117,14 @@ T dimensionedConstant
Name \ Name \
) \ ) \
); \ ); \
Foam::dimensionedScalar& s = const_cast<Foam::dimensionedScalar&> \ Foam::dimensionedScalar& s = const_cast<Foam::dimensionedScalar&> \
( \ ( \
Switch \ Switch \
); \ ); \
s.dimensions().reset(ds.dimensions()); \ s.dimensions().reset(ds.dimensions()); \
s = ds; \ s = ds; \
} \ } \
virtual ~add##Tag##ToDimensionedConstant() \ virtual ~add##Tag##ToDimensionedConstant() = default; \
{} \
virtual void readData(Foam::Istream& is) \ virtual void readData(Foam::Istream& is) \
{ \ { \
const_cast<Foam::dimensionedScalar&>(Switch) = \ const_cast<Foam::dimensionedScalar&>(Switch) = \
@ -162,15 +165,14 @@ T dimensionedConstant
Foam::dimensionedScalar(Name,DefaultExpr) \ Foam::dimensionedScalar(Name,DefaultExpr) \
) \ ) \
); \ ); \
Foam::dimensionedScalar& s = const_cast<Foam::dimensionedScalar&> \ Foam::dimensionedScalar& s = const_cast<Foam::dimensionedScalar&> \
( \ ( \
Switch \ Switch \
); \ ); \
s.dimensions().reset(ds.dimensions()); \ s.dimensions().reset(ds.dimensions()); \
s = ds; \ s = ds; \
} \ } \
virtual ~add##Tag##ToDimensionedConstantWithDefault() \ virtual ~add##Tag##ToDimensionedConstantWithDefault() = default; \
{} \
virtual void readData(Foam::Istream& is) \ virtual void readData(Foam::Istream& is) \
{ \ { \
const_cast<Foam::dimensionedScalar&>(Switch) = \ const_cast<Foam::dimensionedScalar&>(Switch) = \

View File

@ -3,7 +3,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) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -50,11 +50,7 @@ Foam::pTraits<bool>::pTraits(Istream& is)
Foam::Istream& Foam::operator>>(Istream& is, bool& b) Foam::Istream& Foam::operator>>(Istream& is, bool& b)
{ {
if (is.good()) b = static_cast<bool>(Switch(is));
{
b = Switch(is);
}
return is; return is;
} }
@ -70,10 +66,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const bool b)
bool Foam::readBool(Istream& is) bool Foam::readBool(Istream& is)
{ {
bool b; return static_cast<bool>(Switch(is));
is >> b;
return b;
} }

View File

@ -53,7 +53,7 @@ Foam::turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
: :
fixedValueFvPatchField<Type>(p, iF, dict, false), fixedValueFvPatchField<Type>(p, iF, dict, false),
ranGen_(label(0)), ranGen_(label(0)),
fluctuationScale_(pTraits<Type>(dict.lookup("fluctuationScale"))), fluctuationScale_(dict.get<Type>("fluctuationScale")),
referenceField_("referenceField", dict, p.size()), referenceField_("referenceField", dict, p.size()),
alpha_(dict.lookupOrDefault<scalar>("alpha", 0.1)), alpha_(dict.lookupOrDefault<scalar>("alpha", 0.1)),
curTimeIndex_(-1) curTimeIndex_(-1)