Commit cc962c65 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: construct string types from Istream now explicit (#1033)

- this helps for trapping unguarded dictionary lookups.
parent 2d8c5247
......@@ -53,13 +53,7 @@ Foam::surfaceTensionModels::liquidProperties::liquidProperties
)
:
surfaceTensionModel(mesh),
phaseName_(dict.lookup("phase"))
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::surfaceTensionModels::liquidProperties::~liquidProperties()
phaseName_(dict.get<word>("phase"))
{}
......
......@@ -95,7 +95,7 @@ public:
//- Destructor
virtual ~liquidProperties();
virtual ~liquidProperties() = default;
// Member Functions
......
......@@ -98,7 +98,7 @@ public:
autoPtr<phaseModel> operator()(Istream& is) const
{
return autoPtr<phaseModel>::New(is, p_, T_);
return autoPtr<phaseModel>::New(word(is), p_, T_);
}
};
......
......@@ -72,7 +72,7 @@ MultiComponentPhaseModel
species_ = thermoPtr_->composition().species();
inertIndex_ = species_[thermoPtr_().lookup("inertSpecie")];
inertIndex_ = species_[thermoPtr_->getWord("inertSpecie")];
X_.setSize(thermoPtr_->composition().species().size());
......@@ -104,7 +104,6 @@ MultiComponentPhaseModel
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class BasePhaseModel, class phaseThermo>
void Foam::MultiComponentPhaseModel<BasePhaseModel, phaseThermo>
::calculateVolumeFractions()
......
......@@ -53,7 +53,7 @@ Foam::phaseModel::phaseModel
IOobject::AUTO_WRITE
),
fluid.mesh(),
dimensionedScalar("alpha", dimless, 0)
dimensionedScalar(dimless, Zero)
),
fluid_(fluid),
name_(phaseName)
......
......@@ -122,46 +122,29 @@ int main(int argc, char *argv[])
{
if (nameMap.found(starFieldNames[i]))
{
IOobject io
(
nameMap.get<word>(starFieldNames[i]),
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
);
if (starFieldNames[i] == "SU")
{
vFields[i] =
new volVectorField
(
IOobject
(
nameMap.lookup(starFieldNames[i]),
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);
vFields[i] = new volVectorField(io, mesh);
i += 3;
}
else
{
sFields[i] =
new volScalarField
(
IOobject
(
nameMap.lookup(starFieldNames[i]),
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);
i++;
sFields[i] = new volScalarField(io, mesh);
++i;
}
}
else
{
i++;
++i;
}
}
......
......@@ -1297,6 +1297,7 @@ public:
defineDictionaryGetter(getBool, bool);
defineDictionaryGetter(getLabel, label);
defineDictionaryGetter(getScalar, scalar);
defineDictionaryGetter(getString, string);
defineDictionaryGetter(getWord, word);
defineDictionaryGetter(getFileName, fileName);
......
......@@ -48,7 +48,7 @@ Foam::fixedNormalSlipPointPatchField<Type>::fixedNormalSlipPointPatchField
)
:
slipPointPatchField<Type>(p, iF, dict),
n_(dict.lookup("n"))
n_(dict.get<vector>("n"))
{}
......
......@@ -53,7 +53,7 @@ Foam::PBiCCCG<Type, DType, LUType>::solve
Field<Type>& psi
) const
{
word preconditionerName(this->controlDict_.lookup("preconditioner"));
const word preconditionerName(this->controlDict_.getWord("preconditioner"));
// --- Setup class containing solver performance data
SolverPerformance<Type> solverPerf
......
......@@ -50,7 +50,7 @@ template<class Type, class DType, class LUType>
Foam::SolverPerformance<Type>
Foam::PBiCICG<Type, DType, LUType>::solve(Field<Type>& psi) const
{
word preconditionerName(this->controlDict_.lookup("preconditioner"));
const word preconditionerName(this->controlDict_.getWord("preconditioner"));
// --- Setup class containing solver performance data
SolverPerformance<Type> solverPerf
......
......@@ -50,7 +50,7 @@ template<class Type, class DType, class LUType>
typename Foam::SolverPerformance<Type>
Foam::PCICG<Type, DType, LUType>::solve(Field<Type>& psi) const
{
word preconditionerName(this->controlDict_.lookup("preconditioner"));
const word preconditionerName(this->controlDict_.getWord("preconditioner"));
// --- Setup class containing solver performance data
SolverPerformance<Type> solverPerf
......
......@@ -248,7 +248,7 @@ Foam::GAMGAgglomeration::GAMGAgglomeration
)
? GAMGProcAgglomeration::New
(
controlDict.lookup("processorAgglomerator"),
controlDict.get<word>("processorAgglomerator"),
*this,
controlDict
)
......
......@@ -77,7 +77,7 @@ public:
inline Pair(const FixedList<T, 2>& lst, const bool doSort);
//- Construct from Istream
inline Pair(Istream& is);
inline explicit Pair(Istream& is);
// Member Functions
......
......@@ -44,7 +44,7 @@ See also
namespace Foam
{
// Forward declaration of friend functions and operators
// Forward declarations
template<class Type1, class Type2>
class Tuple2;
......@@ -93,7 +93,7 @@ public:
{}
//- Construct from Istream
inline Tuple2(Istream& is)
inline explicit Tuple2(Istream& is)
{
is >> *this;
}
......
......@@ -153,7 +153,7 @@ public:
{}
//- Construct from Istream
Switch(Istream& is);
explicit Switch(Istream& is);
// Helpers
......
......@@ -137,9 +137,8 @@ public:
//- Construct by concatenating words separated by '/'
explicit fileName(std::initializer_list<word> list);
//- Construct from Istream
fileName(Istream& is);
explicit fileName(Istream& is);
// Member Functions
......
......@@ -130,7 +130,7 @@ public:
//- Construct from Istream
// Treat as regular expression if surrounded by quotation marks.
keyType(Istream& is);
explicit keyType(Istream& is);
// Member Functions
......
......@@ -49,8 +49,6 @@ namespace Foam
namespace parsing
{
// Enumerations
//- Enumeration for possible parsing error
enum class errorType
{
......
......@@ -182,7 +182,7 @@ public:
inline string(const size_type len, const char c);
//- Construct from Istream
string(Istream& is);
explicit string(Istream& is);
// Member Functions
......
......@@ -109,7 +109,7 @@ public:
inline word(const char* s, size_type len, bool doStrip);
//- Construct from Istream
word(Istream& is);
explicit word(Istream& is);
// Member Functions
......
......@@ -162,7 +162,7 @@ public:
//- Construct from Istream
// Words are treated as literals, strings with an auto-test
wordRe(Istream& is);
explicit wordRe(Istream& is);
// Member Functions
......
......@@ -69,7 +69,7 @@ outletMachNumberPressureFvPatchScalarField
phiName_(dict.lookupOrDefault<word>("phi", "phi")),
rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
UName_(dict.lookupOrDefault<word>("U", "U")),
choked_(dict.lookup("choked")),
choked_(dict.get<Switch>("choked")),
relax_(dict.lookupOrDefault<scalar>("relax", 0))
{}
......
......@@ -74,7 +74,7 @@ outletMappedUniformInletHeatAdditionFvPatchField
)
:
fixedValueFvPatchScalarField(p, iF, dict),
outletPatchName_(dict.lookup("outletPatch")),
outletPatchName_(dict.get<word>("outletPatch")),
phiName_(dict.lookupOrDefault<word>("phi", "phi")),
Q_(dict.get<scalar>("Q")),
TMin_(dict.lookupOrDefault<scalar>("TMin", 0)),
......
......@@ -86,7 +86,7 @@ turbulentTemperatureCoupledBaffleMixedFvPatchScalarField
:
mixedFvPatchScalarField(p, iF),
temperatureCoupledBase(patch(), dict),
TnbrName_(dict.lookup("Tnbr")),
TnbrName_(dict.get<word>("Tnbr")),
thicknessLayers_(0),
kappaLayers_(0),
contactRes_(0.0)
......
......@@ -65,7 +65,7 @@ Foam::LESModel<BasicTurbulenceModel>::LESModel
),
LESDict_(this->subOrEmptyDict("LES")),
turbulence_(LESDict_.lookup("turbulence")),
turbulence_(LESDict_.get<Switch>("turbulence")),
printCoeffs_(LESDict_.lookupOrDefault<Switch>("printCoeffs", false)),
coeffDict_(LESDict_.optionalSubDict(type + "Coeffs")),
......
......@@ -93,11 +93,6 @@ protected:
//- Print model coefficients
virtual void printCoeffs(const word& type);
private:
// Private Member Functions
//- No copy construct
LESModel(const LESModel&) = delete;
......@@ -168,8 +163,7 @@ public:
//- Destructor
virtual ~LESModel()
{}
virtual ~LESModel() = default;
// Member Functions
......
......@@ -65,7 +65,7 @@ Foam::RASModel<BasicTurbulenceModel>::RASModel
),
RASDict_(this->subOrEmptyDict("RAS")),
turbulence_(RASDict_.lookup("turbulence")),
turbulence_(RASDict_.get<Switch>("turbulence")),
printCoeffs_(RASDict_.lookupOrDefault<Switch>("printCoeffs", false)),
coeffDict_(RASDict_.optionalSubDict(type + "Coeffs")),
......
......@@ -83,11 +83,6 @@ protected:
//- Print model coefficients
virtual void printCoeffs(const word& type);
private:
// Private Member Functions
//- No copy construct
RASModel(const RASModel&) = delete;
......@@ -158,8 +153,7 @@ public:
//- Destructor
virtual ~RASModel()
{}
virtual ~RASModel() = default;
// Member Functions
......
......@@ -100,7 +100,7 @@ Foam::TurbulenceModel<Alpha, Rho, BasicTurbulenceModel, TransportModel>::New
IOobject::NO_WRITE,
false
)
).lookup("simulationType")
).get<word>("simulationType")
);
Info<< "Selecting turbulence model type " << modelType << endl;
......
......@@ -75,9 +75,7 @@ protected:
const transportModel& transport_;
private:
// Private Member Functions
// Protected Member Functions
//- No copy construct
TurbulenceModel(const TurbulenceModel&) = delete;
......@@ -139,8 +137,7 @@ public:
//- Destructor
virtual ~TurbulenceModel()
{}
virtual ~TurbulenceModel() = default;
// Member Functions
......
......@@ -134,7 +134,7 @@ nutUTabulatedWallFunctionFvPatchScalarField
)
:
nutWallFunctionFvPatchScalarField(p, iF, dict),
uPlusTableName_(dict.lookup("uPlusTable")),
uPlusTableName_(dict.get<word>("uPlusTable")),
uPlusTable_
(
IOobject
......
......@@ -109,7 +109,7 @@ Foam::laminarModel<BasicTurbulenceModel>::New
// otherwise it is registered in the database twice
const word modelType
(
modelDict.subDict("laminar").lookup("laminarModel")
modelDict.subDict("laminar").get<word>("laminarModel")
);
Info<< "Selecting laminar stress model " << modelType << endl;
......
......@@ -71,11 +71,6 @@ protected:
//- Print model coefficients
virtual void printCoeffs(const word& type);
private:
// Private Member Functions
//- No copy construct
laminarModel(const laminarModel&) = delete;
......@@ -146,8 +141,7 @@ public:
//- Destructor
virtual ~laminarModel()
{}
virtual ~laminarModel() = default;
// Member Functions
......
......@@ -98,7 +98,7 @@ Foam::velocityDisplacementMotionSolver::velocityDisplacementMotionSolver
(
displacementMotionSolver::New
(
coeffDict().lookup("solver"),
coeffDict().get<word>("solver"),
mesh,
IOdictionary
(
......
......@@ -50,6 +50,7 @@ namespace functionObjects
}
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::codedFunctionObject::prepare
......@@ -194,9 +195,10 @@ bool Foam::functionObjects::codedFunctionObject::read(const dictionary& dict)
dict.readCompat<word>("name", {{"redirectType", 1706}}, name_);
const entry* dataPtr = dict.findEntry("codeData", keyType::LITERAL);
if (dataPtr)
{
codeData_ = stringOps::trim(dataPtr->stream());
dataPtr->readEntry(codeData_);
stringOps::inplaceExpand(codeData_, dict);
dynamicCodeContext::addLineDirective
(
......@@ -207,9 +209,10 @@ bool Foam::functionObjects::codedFunctionObject::read(const dictionary& dict)
}
const entry* readPtr = dict.findEntry("codeRead", keyType::LITERAL);
if (readPtr)
{
codeRead_ = stringOps::trim(readPtr->stream());
readPtr->readEntry(codeRead_);
stringOps::inplaceExpand(codeRead_, dict);
dynamicCodeContext::addLineDirective
(
......@@ -220,9 +223,10 @@ bool Foam::functionObjects::codedFunctionObject::read(const dictionary& dict)
}
const entry* execPtr = dict.findEntry("codeExecute", keyType::LITERAL);
if (execPtr)
{
codeExecute_ = stringOps::trim(execPtr->stream());
execPtr->readEntry(codeExecute_);
stringOps::inplaceExpand(codeExecute_, dict);
dynamicCodeContext::addLineDirective
(
......@@ -233,9 +237,10 @@ bool Foam::functionObjects::codedFunctionObject::read(const dictionary& dict)
}
const entry* writePtr = dict.findEntry("codeWrite", keyType::LITERAL);
if (writePtr)
{
codeWrite_ = stringOps::trim(writePtr->stream());
writePtr->readEntry(codeWrite_);
stringOps::inplaceExpand(codeWrite_, dict);
dynamicCodeContext::addLineDirective
(
......@@ -246,9 +251,10 @@ bool Foam::functionObjects::codedFunctionObject::read(const dictionary& dict)
}
const entry* endPtr = dict.findEntry("codeEnd", keyType::LITERAL);
if (endPtr)
{
codeEnd_ = stringOps::trim(endPtr->stream());
endPtr->readEntry(codeEnd_);
stringOps::inplaceExpand(codeEnd_, dict);
dynamicCodeContext::addLineDirective
(
......@@ -260,10 +266,8 @@ bool Foam::functionObjects::codedFunctionObject::read(const dictionary& dict)
if (!dataPtr && !readPtr && !execPtr && !writePtr && !endPtr)
{
IOWarningInFunction
(
dict
) << "No critical \"code\" prefixed keywords were found."
IOWarningInFunction(dict)
<< "No critical \"code\" prefixed keywords were found."
<< " Please check the code documentation for more details."
<< nl << endl;
}
......
......@@ -134,8 +134,6 @@ protected:
virtual const dictionary& codeDict() const;
private:
//- No copy construct
codedFunctionObject(const codedFunctionObject&) = delete;
......
......@@ -85,20 +85,14 @@ displacementComponentLaplacianFvMotionSolver
frozenPointsZone_
(
coeffDict().found("frozenPointsZone")