mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: code reduction, improvements for expressions
- literal lookups only for expression strings - code reduction for setExprFields. - changed keyword "condition" to "fieldMask" (option -field-mask). This is a better description of its purpose and avoids possible naming ambiguities with functionObject triggers (for example) if we apply similar syntax elsewhere. BUG: erroneous check in volumeExpr::parseDriver::isResultType() - not triggered since this method is not used anywhere (may remove in future version)
This commit is contained in:
committed by
Andrew Heather
parent
39f6618d3a
commit
510ffb3322
@ -48,20 +48,30 @@ void Foam::expressions::exprString::inplaceExpand
|
||||
|
||||
|
||||
Foam::expressions::exprString
|
||||
Foam::expressions::exprString::getExpression
|
||||
Foam::expressions::exprString::getEntry
|
||||
(
|
||||
const word& name,
|
||||
const word& key,
|
||||
const dictionary& dict,
|
||||
const bool stripComments
|
||||
)
|
||||
{
|
||||
string orig(dict.get<string>(name));
|
||||
exprString expr;
|
||||
expr.readEntry(key, dict, true, stripComments); // mandatory
|
||||
|
||||
// No validation
|
||||
expressions::exprString expr;
|
||||
expr.assign(std::move(orig));
|
||||
return expr;
|
||||
}
|
||||
|
||||
inplaceExpand(expr, dict, stripComments);
|
||||
|
||||
Foam::expressions::exprString
|
||||
Foam::expressions::exprString::getOptional
|
||||
(
|
||||
const word& key,
|
||||
const dictionary& dict,
|
||||
const bool stripComments
|
||||
)
|
||||
{
|
||||
exprString expr;
|
||||
expr.readEntry(key, dict, false, stripComments); // optional
|
||||
|
||||
return expr;
|
||||
}
|
||||
@ -69,8 +79,7 @@ Foam::expressions::exprString::getExpression
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::expressions::exprString&
|
||||
Foam::expressions::exprString::expand
|
||||
void Foam::expressions::exprString::expand
|
||||
(
|
||||
const dictionary& dict,
|
||||
const bool stripComments
|
||||
@ -81,8 +90,35 @@ Foam::expressions::exprString::expand
|
||||
#ifdef FULLDEBUG
|
||||
(void)valid();
|
||||
#endif
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
||||
void Foam::expressions::exprString::trim()
|
||||
{
|
||||
stringOps::inplaceTrim(*this);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::expressions::exprString::readEntry
|
||||
(
|
||||
const word& keyword,
|
||||
const dictionary& dict,
|
||||
bool mandatory,
|
||||
const bool stripComments
|
||||
)
|
||||
{
|
||||
const bool ok = dict.readEntry(keyword, *this, keyType::LITERAL, mandatory);
|
||||
|
||||
if (ok && !empty())
|
||||
{
|
||||
this->expand(dict, stripComments); // strip comments
|
||||
}
|
||||
else
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -135,13 +135,22 @@ public:
|
||||
|
||||
//- Get and expand expression with dictionary entries,
|
||||
//- optionally strip C/C++ comments from the input.
|
||||
//
|
||||
// Expansion behaviour as per inplaceExpand
|
||||
static exprString getExpression
|
||||
static exprString getEntry
|
||||
(
|
||||
const word& name,
|
||||
const word& keyword, //!< Lookup key. Uses LITERAL (not REGEX)
|
||||
const dictionary& dict,
|
||||
const bool stripComments = false
|
||||
const bool stripComments = true
|
||||
);
|
||||
|
||||
//- Get and expand expression with dictionary entries,
|
||||
//- optionally strip C/C++ comments from the input.
|
||||
// Expansion behaviour as per inplaceExpand
|
||||
static exprString getOptional
|
||||
(
|
||||
const word& keyword, //!< Lookup key. Uses LITERAL (not REGEX)
|
||||
const dictionary& dict,
|
||||
const bool stripComments = true
|
||||
);
|
||||
|
||||
//- Copy convert string to exprString.
|
||||
@ -155,17 +164,26 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Inplace expansion with dictionary variables,
|
||||
//- and strip C/C++ comments from the input
|
||||
exprString& expand
|
||||
(
|
||||
const dictionary& dict,
|
||||
const bool stripComments = true
|
||||
);
|
||||
|
||||
//- Check for unexpanded '$' entries. Fatal if any exist.
|
||||
inline bool valid() const;
|
||||
|
||||
//- Inplace expansion with dictionary variables,
|
||||
//- and strip C/C++ comments from the input
|
||||
void expand(const dictionary& dict, const bool stripComments = true);
|
||||
|
||||
//- Inplace trim leading and trailing whitespace
|
||||
void trim();
|
||||
|
||||
//- Read/expand entry with dictionary variables,
|
||||
//- and strip C/C++ comments from the input
|
||||
bool readEntry
|
||||
(
|
||||
const word& keyword, //!< Lookup key. Uses LITERAL (not REGEX)
|
||||
const dictionary& dict,
|
||||
bool mandatory = true,
|
||||
const bool stripComments = true
|
||||
);
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
|
||||
Reference in New Issue
Block a user