Files
OpenFOAM-12/src/OpenFOAM/db/dictionary/functionEntries/inputSyntaxEntry/inputSyntaxEntry.C
Henry Weller 6c8732df5b dictionary: Set the default scoping syntax to 'slash'
The new optional 'slash' scoping syntax is now the default and provides a more
intuitive and flexible syntax than the previous 'dot' syntax, corresponding to
the common directory/file access syntax used in UNIX, providing support for
reading entries from other dictionary files.

In the 'slash' syntax
    '/' is the scope operator
    '../' is the parent dictionary scope operator
    '!' is the top-level dictionary scope operator

Examples:

    internalField 3.4;

    active
    {
        type            fixedValue;
        value.air       $internalField;
    }

    inactive
    {
        type            anotherFixedValue;

        value           $../active/value.air;
        anotherValue    $!active/value.air;

        sub
        {
            value           $../../active/value.air;
            anotherValue    $!active/value.air;
        }
    }

    "U.*"
    {
        solver GAMG;
    }

    e.air
    {
        $U.air;
    }

    external
    {
        value $testSlashDict2!active/value.air;
    }

    active2
    {
        $testSlashDict2!active;
    }

If there is a part of the keyword before the '!' then this is taken to be the
file name of the dictionary from which the entry will be looked-up using the
part of the keyword after the '!'.  For example given a file testSlashDict containing

    internalField 5.6;

    active
    {
        type            fixedValue;
        value.air       $internalField;
    }

entries from it can be read directly from another file, e.g.

    external
    {
        value $testSlashDict2!active/value.air;
    }

    active2
    {
        $testSlashDict2!active;
    }

    which expands to

    external
    {
        value           5.6;
    }

    active2
    {
        type            fixedValue;
        value.air       5.6;
    }

These examples are provided in applications/test/dictionary.

The the default syntax can be changed from 'slash' to 'dot' in etc/controlDict
to revert to the previous behaviour:

OptimisationSwitches
{
.
.
.
    // Default dictionary scoping syntax
    inputSyntax slash;  // Change to dot for previous behaviour
}

or within a specific dictionary by adding the entry

See applications/test/dictionary/testDotDict.
2020-07-23 20:36:51 +01:00

145 lines
3.6 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2019-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "inputSyntaxEntry.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::word Foam::functionEntries::inputSyntaxEntry::typeName
(
Foam::functionEntries::inputSyntaxEntry::typeName_()
);
// Don't lookup the debug switch here as the debug switch dictionary
// might include inputSyntax entries
int Foam::functionEntries::inputSyntaxEntry::debug(0);
// Read the default dictionary syntax from etc/controlDict if specified
Foam::functionEntries::inputSyntaxEntry::inputSyntax
Foam::functionEntries::inputSyntaxEntry::defaultSyntax_
(
Foam::debug::optimisationSwitches().found("inputSyntax")
? Foam::functionEntries::inputSyntaxEntry::syntax
(
Foam::debug::optimisationSwitches().lookup
(
"inputSyntax"
)
)
: SLASH
);
// Initialise the current dictionary syntax to the default
Foam::functionEntries::inputSyntaxEntry::inputSyntax
Foam::functionEntries::inputSyntaxEntry::syntax_
(
Foam::functionEntries::inputSyntaxEntry::defaultSyntax_
);
namespace Foam
{
namespace functionEntries
{
addToMemberFunctionSelectionTable
(
functionEntry,
inputSyntaxEntry,
execute,
dictionaryIstream
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::functionEntries::inputSyntaxEntry::inputSyntax
Foam::functionEntries::inputSyntaxEntry::syntax
(
Istream& is
)
{
word syntax(is);
if (syntax == "slash")
{
return SLASH;
}
else if (syntax == "dot")
{
return DOT;
}
else
{
WarningInFunction
<< "unsupported input syntax'" << syntax
<< ", setting to default"
<< endl;
return defaultSyntax_;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionEntries::inputSyntaxEntry::execute
(
dictionary& parentDict,
Istream& is
)
{
syntax_ = syntax(is);
return true;
}
void Foam::functionEntries::inputSyntaxEntry::clear()
{
syntax_ = defaultSyntax_;
}
bool Foam::functionEntries::inputSyntaxEntry::slash()
{
return syntax_ == SLASH;
}
bool Foam::functionEntries::inputSyntaxEntry::dot()
{
return syntax_ == DOT;
}
char Foam::functionEntries::inputSyntaxEntry::scopeChar()
{
return syntax_ == SLASH ? '/' : '.';
}
// ************************************************************************* //