mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support scalar tokens when testing #if, #ifeq
- this allows use of #eval results in the tests
This commit is contained in:
committed by
Andrew Heather
parent
0838d121c6
commit
a5a222f7cf
@ -6,6 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2018 OpenFOAM Foundation
|
Copyright (C) 2018 OpenFOAM Foundation
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -51,6 +52,24 @@ namespace functionEntries
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * 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
|
bool Foam::functionEntries::ifEntry::execute
|
||||||
(
|
(
|
||||||
DynamicList<filePos>& stack,
|
DynamicList<filePos>& stack,
|
||||||
@ -68,13 +87,14 @@ bool Foam::functionEntries::ifEntry::execute
|
|||||||
line += ';';
|
line += ';';
|
||||||
IStringStream lineStream(line);
|
IStringStream lineStream(line);
|
||||||
const primitiveEntry e("ifEntry", parentDict, lineStream);
|
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()
|
// << " at line " << stack.last().second()
|
||||||
// << " in file " << stack.last().first() << endl;
|
// << " 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)
|
if (stack.size() != nNested)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -43,7 +43,7 @@ Description
|
|||||||
Note:
|
Note:
|
||||||
- only supports single line, '\' is not supported
|
- only supports single line, '\' is not supported
|
||||||
- condition should be readable as a \c Switch
|
- 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
|
See also
|
||||||
Foam::functionEntries::ifeqEntry
|
Foam::functionEntries::ifeqEntry
|
||||||
@ -78,6 +78,9 @@ class ifEntry
|
|||||||
|
|
||||||
// Private Member Functions
|
// 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
|
//- Execute the functionEntry in a sub-dict context
|
||||||
static bool execute
|
static bool execute
|
||||||
(
|
(
|
||||||
|
|||||||
@ -27,9 +27,8 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "ifeqEntry.H"
|
#include "ifeqEntry.H"
|
||||||
#include "stringOps.H"
|
|
||||||
#include "ifEntry.H"
|
#include "ifEntry.H"
|
||||||
#include "Switch.H"
|
#include "stringOps.H"
|
||||||
#include "addToMemberFunctionSelectionTable.H"
|
#include "addToMemberFunctionSelectionTable.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
@ -367,9 +366,8 @@ bool Foam::functionEntries::ifeqEntry::execute
|
|||||||
line += ';';
|
line += ';';
|
||||||
IStringStream lineStream(line);
|
IStringStream lineStream(line);
|
||||||
const primitiveEntry e("ifEntry", parentDict, lineStream);
|
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
|
// Info<< "Using #elif " << doIf << " at line " << lineNo
|
||||||
// << " in file " << is.name() << endl;
|
// << " in file " << is.name() << endl;
|
||||||
|
|||||||
@ -139,7 +139,7 @@ protected:
|
|||||||
);
|
);
|
||||||
|
|
||||||
//- Main driver: depending on 'equal' starts evaluating or
|
//- Main driver: depending on 'equal' starts evaluating or
|
||||||
// skips forward to #else
|
//- skips forward to #else
|
||||||
static bool execute
|
static bool execute
|
||||||
(
|
(
|
||||||
const bool equal,
|
const bool equal,
|
||||||
@ -149,7 +149,7 @@ protected:
|
|||||||
);
|
);
|
||||||
|
|
||||||
//- Main driver: depending on 'equal' starts evaluating or
|
//- Main driver: depending on 'equal' starts evaluating or
|
||||||
// skips forward to #else
|
//- skips forward to #else
|
||||||
static bool execute
|
static bool execute
|
||||||
(
|
(
|
||||||
DynamicList<filePos>& stack,
|
DynamicList<filePos>& stack,
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
/*--------------------------------*- C++ -*----------------------------------*\
|
/*--------------------------------*- C++ -*----------------------------------*\
|
||||||
| ========= | |
|
| ========= | |
|
||||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||||
| \\ / O peration | Version: v1906 |
|
| \\ / O peration | Version: v1912 |
|
||||||
| \\ / A nd | Web: www.OpenFOAM.com |
|
| \\ / A nd | Website: www.openfoam.com |
|
||||||
| \\/ M anipulation | |
|
| \\/ M anipulation | |
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
FoamFile
|
FoamFile
|
||||||
{
|
{
|
||||||
version 2;
|
version 2.0;
|
||||||
format ascii;
|
format ascii;
|
||||||
class dictionary;
|
class dictionary;
|
||||||
object dictionary;
|
object dictionary;
|
||||||
}
|
}
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -26,3 +26,5 @@ FoamFile
|
|||||||
#else
|
#else
|
||||||
version "other";
|
version "other";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
|
|||||||
32
tutorials/IO/dictionary/good-if2.dict
Normal file
32
tutorials/IO/dictionary/good-if2.dict
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*--------------------------------*- C++ -*----------------------------------*\
|
||||||
|
| ========= | |
|
||||||
|
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||||
|
| \\ / O peration | Version: v1912 |
|
||||||
|
| \\ / A nd | Website: www.openfoam.com |
|
||||||
|
| \\/ M anipulation | |
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
FoamFile
|
||||||
|
{
|
||||||
|
version 2.0;
|
||||||
|
format ascii;
|
||||||
|
class dictionary;
|
||||||
|
object dictionary;
|
||||||
|
}
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
// Do comparison
|
||||||
|
|
||||||
|
#if #eval "${FOAM_API:-0}"
|
||||||
|
foamApi nonZero;
|
||||||
|
#else
|
||||||
|
foamApi zeroValue;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if #eval "${XX_XXX_FOAM_API:-1000}"
|
||||||
|
other "some entry";
|
||||||
|
#else
|
||||||
|
other "unexpected";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
Reference in New Issue
Block a user