ENH: support scalar tokens when testing #if, #ifeq

- this allows use of #eval results in the tests
This commit is contained in:
Mark Olesen
2019-11-19 09:00:00 +01:00
committed by Andrew Heather
parent 0838d121c6
commit a5a222f7cf
6 changed files with 71 additions and 16 deletions

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -51,6 +52,24 @@ namespace functionEntries
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionEntries::ifEntry::isTrue(ITstream& its)
{
Switch logic;
if (its.size() && its.first().isScalar())
{
// Use default rounding tolerance
logic = Switch(its.first().scalarToken());
}
else
{
its >> logic;
}
return logic;
}
bool Foam::functionEntries::ifEntry::execute
(
DynamicList<filePos>& stack,
@ -68,13 +87,14 @@ bool Foam::functionEntries::ifEntry::execute
line += ';';
IStringStream lineStream(line);
const primitiveEntry e("ifEntry", parentDict, lineStream);
const Switch doIf(e.stream());
// Info<< "Using #" << typeName << " " << doIf
const bool doIf = ifEntry::isTrue(e.stream());
// Info<< "Using #" << typeName << " " << Switch::name(doIf)
// << " at line " << stack.last().second()
// << " in file " << stack.last().first() << endl;
bool ok = ifeqEntry::execute(doIf, stack, parentDict, is);
const bool ok = ifeqEntry::execute(doIf, stack, parentDict, is);
if (stack.size() != nNested)
{

View File

@ -43,7 +43,7 @@ Description
Note:
- only supports single line, '\' is not supported
- condition should be readable as a \c Switch
(supports 0,1, true, false, etc.)
(0,1, true, false, etc.) or a scalar (0.0, ...)
See also
Foam::functionEntries::ifeqEntry
@ -78,6 +78,9 @@ class ifEntry
// Private Member Functions
//- Test first token (label, scalar, word) for true/false
static bool isTrue(ITstream& is);
//- Execute the functionEntry in a sub-dict context
static bool execute
(

View File

@ -27,9 +27,8 @@ License
\*---------------------------------------------------------------------------*/
#include "ifeqEntry.H"
#include "stringOps.H"
#include "ifEntry.H"
#include "Switch.H"
#include "stringOps.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -367,9 +366,8 @@ bool Foam::functionEntries::ifeqEntry::execute
line += ';';
IStringStream lineStream(line);
const primitiveEntry e("ifEntry", parentDict, lineStream);
const Switch doIf(e.stream());
if (doIf)
if (ifEntry::isTrue(e.stream()))
{
// Info<< "Using #elif " << doIf << " at line " << lineNo
// << " in file " << is.name() << endl;

View File

@ -139,7 +139,7 @@ protected:
);
//- Main driver: depending on 'equal' starts evaluating or
// skips forward to #else
//- skips forward to #else
static bool execute
(
const bool equal,
@ -149,7 +149,7 @@ protected:
);
//- Main driver: depending on 'equal' starts evaluating or
// skips forward to #else
//- skips forward to #else
static bool execute
(
DynamicList<filePos>& stack,