Skip to content
Snippets Groups Projects
Commit efdbeae2 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

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

- check Istream in readBool in operator>> variant (#1033)
parent b9b8c523
Branches
Tags
No related merge requests found
......@@ -74,7 +74,7 @@ CONSTRUCT
:
PARENT(p, iF),
scalarData_(dict.get<scalar>("scalarData")),
data_(pTraits<TYPE>(dict.lookup("data"))),
data_(dict.get<TYPE>("data")),
fieldData_("fieldData", dict, p.size()),
timeVsData_(Function1<TYPE>::New("timeVsData", dict)),
wordData_(dict.lookupOrDefault<word>("wordName", "wordDefault")),
......
......@@ -72,9 +72,13 @@ T dimensionedConstant
if (unitDict.found(group))
{
dictionary& groupDict = unitDict.subDict(group);
// Leaner version of dictionary lookupOrAddDefault()
// without writeOptionalEntries
if (groupDict.found(varName))
{
return pTraits<T>(groupDict.lookup(varName));
return groupDict.get<T>(varName);
}
else
{
......@@ -113,15 +117,14 @@ T dimensionedConstant
Name \
) \
); \
Foam::dimensionedScalar& s = const_cast<Foam::dimensionedScalar&> \
Foam::dimensionedScalar& s = const_cast<Foam::dimensionedScalar&> \
( \
Switch \
); \
s.dimensions().reset(ds.dimensions()); \
s = ds; \
} \
virtual ~add##Tag##ToDimensionedConstant() \
{} \
virtual ~add##Tag##ToDimensionedConstant() = default; \
virtual void readData(Foam::Istream& is) \
{ \
const_cast<Foam::dimensionedScalar&>(Switch) = \
......@@ -162,15 +165,14 @@ T dimensionedConstant
Foam::dimensionedScalar(Name,DefaultExpr) \
) \
); \
Foam::dimensionedScalar& s = const_cast<Foam::dimensionedScalar&> \
Foam::dimensionedScalar& s = const_cast<Foam::dimensionedScalar&> \
( \
Switch \
); \
s.dimensions().reset(ds.dimensions()); \
s = ds; \
} \
virtual ~add##Tag##ToDimensionedConstantWithDefault() \
{} \
virtual ~add##Tag##ToDimensionedConstantWithDefault() = default; \
virtual void readData(Foam::Istream& is) \
{ \
const_cast<Foam::dimensionedScalar&>(Switch) = \
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -50,11 +50,7 @@ Foam::pTraits<bool>::pTraits(Istream& is)
Foam::Istream& Foam::operator>>(Istream& is, bool& b)
{
if (is.good())
{
b = Switch(is);
}
b = static_cast<bool>(Switch(is));
return is;
}
......@@ -70,10 +66,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const bool b)
bool Foam::readBool(Istream& is)
{
bool b;
is >> b;
return b;
return static_cast<bool>(Switch(is));
}
......
......@@ -53,7 +53,7 @@ Foam::turbulentInletFvPatchField<Type>::turbulentInletFvPatchField
:
fixedValueFvPatchField<Type>(p, iF, dict, false),
ranGen_(label(0)),
fluctuationScale_(pTraits<Type>(dict.lookup("fluctuationScale"))),
fluctuationScale_(dict.get<Type>("fluctuationScale")),
referenceField_("referenceField", dict, p.size()),
alpha_(dict.lookupOrDefault<scalar>("alpha", 0.1)),
curTimeIndex_(-1)
......
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