Commit 1e8d4b2a authored by Mark Olesen's avatar Mark Olesen
Browse files

dictionary functionEntries cleanup

  * added '#remove' function
  * changed insert() method name to more general execute()
  * using #inputMode or #remove within a primitiveEntry now provokes an error
  * adjusted the dictionaryTest accordingly
parent 64d00dc2
......@@ -42,24 +42,17 @@ namespace functionEntries
(
functionEntry,
calcEntry,
insert,
execute,
primitiveEntryIstream
);
addToMemberFunctionSelectionTable
(
functionEntry,
calcEntry,
insert,
dictionaryIstream
);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionEntries::calcEntry::insert
bool Foam::functionEntries::calcEntry::execute
(
const dictionary& parentDict,
primitiveEntry& entry,
......@@ -75,14 +68,4 @@ bool Foam::functionEntries::calcEntry::insert
}
bool Foam::functionEntries::calcEntry::insert
(
dictionary& parentDict,
Istream& is
)
{
return true;
}
// ************************************************************************* //
......@@ -69,18 +69,13 @@ public:
// Member Functions
static bool insert
static bool execute
(
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
);
static bool insert
(
dictionary& parentDict,
Istream& is
);
};
......
/*-------------------------------*- C++ -*---------------------------------*\
| ========= |
| \\ / OpenFOAM |
| \\ / |
| \\ / The Open Source CFD Toolbox |
| \\/ http://www.OpenFOAM.org |
\*-------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
root "";
case "";
instance "";
local "";
class dictionary;
object testDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#inputMode merge
dimensions [ 0 2 -2 0 0 0 0 ];
internalField uniform 1;
......@@ -29,7 +31,6 @@ inactive
type zeroGradient;
}
boundaryField
{
Default_Boundary_Region
......@@ -40,6 +41,12 @@ boundaryField
inlet_1 { $active }
inlet_2 { $inactive }
inlet_3 { $inactive }
inlet_4 { $inactive }
inlet_5 "a primitiveEntry is squashed by a directory entry";
inlet_5 { $inactive }
inlet_6 { $inactive }
inlet_7 { $inactive }
inlet_8 { $inactive }
#include "testDictInc"
......@@ -48,8 +55,44 @@ boundaryField
type inletOutlet;
inletValue $internalField;
value #include "value";
// error #remove self;
x 5;
y 6;
another #calc{x $x; y $y;};
}
// this should have no effect
#remove inactive
inlet_7 { $active }
#inputMode overwrite
inlet_8 { $active }
}
// NB: the inputMode has a global scope
#inputMode merge
#include "testDict2"
foo
{
$active
}
bar
{
$active
}
baz
{
$active
}
// this should work
#remove active
// this should work too
#remove ( bar baz )
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
/*-------------------------------*- C++ -*---------------------------------*\
| ========= |
| \\ / OpenFOAM |
| \\ / |
| \\ / The Open Source CFD Toolbox |
| \\/ http://www.OpenFOAM.org |
\*-------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object testDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
boundaryField
{
Default_Boundary_Region
{
value $internalField;
note "actually a noslip wall";
}
inlet_3 "a primitiveEntry squashes directory entry";
}
#inputMode overwrite
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
uniform 2
// the trailing ';' shouldn't actually be there, but shouldn't cause problems
uniform 2;
......@@ -122,6 +122,7 @@ functionEntries = $(dictionary)/functionEntries
$(functionEntries)/functionEntry/functionEntry.C
$(functionEntries)/includeEntry/includeEntry.C
$(functionEntries)/inputModeEntry/inputModeEntry.C
$(functionEntries)/removeEntry/removeEntry.C
IOdictionary = db/IOobjects/IOdictionary
$(IOdictionary)/IOdictionary.C
......
......@@ -96,7 +96,7 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
if (keyword[0] == '#') // ... Function entry
{
word functionName = keyword(1, keyword.size()-1);
return functionEntry::insert(functionName, parentDict, is);
return functionEntry::execute(functionName, parentDict, is);
}
else if (keyword[0] == '$') // ... Substitution entry
{
......@@ -105,7 +105,7 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
}
else if (keyword == "include") // ... For backward compatibility
{
return functionEntries::includeEntry::insert(parentDict, is);
return functionEntries::includeEntry::execute(parentDict, is);
}
else // ... Data entries
{
......@@ -114,12 +114,18 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
// Deal with duplicate entries
bool mergeEntry = false;
if (parentDict.found(keyword))
entry* existingPtr = parentDict.lookupEntryPtr(keyword);
if (existingPtr)
{
if (functionEntries::inputModeEntry::overwrite())
{
// silently drop previous entries
parentDict.remove(keyword);
// clear dictionary so merge acts like overwrite
if (existingPtr->isDict())
{
existingPtr->dict().clear();
}
mergeEntry = true;
}
else if (functionEntries::inputModeEntry::merge())
{
......
......@@ -33,110 +33,109 @@ namespace Foam
defineMemberFunctionSelectionTable
(
functionEntry,
insert,
primitiveEntryIstream
execute,
dictionaryIstream
);
defineMemberFunctionSelectionTable
(
functionEntry,
insert,
dictionaryIstream
execute,
primitiveEntryIstream
);
}
// * * * * * * * * * * * * Member Function Selectors * * * * * * * * * * * * //
bool Foam::functionEntry::insert
bool Foam::functionEntry::execute
(
const word& functionName,
const dictionary& parentDict,
primitiveEntry& entry,
dictionary& parentDict,
Istream& is
)
{
is.fatalCheck
(
"functionEntry::insert"
"(const word& functionName, const dictionary& parentDict, "
"primitiveEntry& entry, Istream& is)"
"functionEntry::execute"
"(const word& functionName, dictionary& parentDict, Istream& is)"
);
if (!insertprimitiveEntryIstreamMemberFunctionTablePtr_)
if (!executedictionaryIstreamMemberFunctionTablePtr_)
{
cerr<<"functionEntry::insert"
<< "(const word&, dictionary&, primitiveEntry&, Istream&)"
cerr<<"functionEntry::execute"
<< "(const word&, dictionary&, Istream&)"
<< " not yet initialized, function = "
<< functionName.c_str() << std::endl;
// return true to keep reading anyhow
// Return true to keep reading
return true;
}
insertprimitiveEntryIstreamMemberFunctionTable::iterator mfIter =
insertprimitiveEntryIstreamMemberFunctionTablePtr_->find(functionName);
executedictionaryIstreamMemberFunctionTable::iterator mfIter =
executedictionaryIstreamMemberFunctionTablePtr_->find(functionName);
if (mfIter == insertprimitiveEntryIstreamMemberFunctionTablePtr_->end())
if (mfIter == executedictionaryIstreamMemberFunctionTablePtr_->end())
{
FatalErrorIn
(
"functionEntry::insert"
"(const word& functionName, const dictionary& parentDict, "
"primitiveEntry& entry, Istream& is)"
"functionEntry::execute"
"(const word& functionName, dictionary& parentDict, Istream&)"
) << "Unknown functionEntry " << functionName
<< endl << endl
<< "Valid functionEntries are :" << endl
<< insertprimitiveEntryIstreamMemberFunctionTablePtr_->toc()
<< executedictionaryIstreamMemberFunctionTablePtr_->toc()
<< exit(FatalError);
}
return mfIter()(parentDict, entry, is);
return mfIter()(parentDict, is);
}
bool Foam::functionEntry::insert
bool Foam::functionEntry::execute
(
const word& functionName,
dictionary& parentDict,
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
)
{
is.fatalCheck
(
"functionEntry::insert"
"(const word& functionName, dictionary& parentDict, Istream& is)"
"functionEntry::execute"
"(const word& functionName, const dictionary& parentDict, "
"primitiveEntry&, Istream&)"
);
if (!insertdictionaryIstreamMemberFunctionTablePtr_)
if (!executeprimitiveEntryIstreamMemberFunctionTablePtr_)
{
cerr<<"functionEntry::insert"
<< "(const word&, dictionary&, Istream&)"
cerr<<"functionEntry::execute"
<< "(const word&, dictionary&, primitiveEntry&, Istream&)"
<< " not yet initialized, function = "
<< functionName.c_str() << std::endl;
// Return true to keep reading
// return true to keep reading anyhow
return true;
}
insertdictionaryIstreamMemberFunctionTable::iterator mfIter =
insertdictionaryIstreamMemberFunctionTablePtr_->find(functionName);
executeprimitiveEntryIstreamMemberFunctionTable::iterator mfIter =
executeprimitiveEntryIstreamMemberFunctionTablePtr_->find(functionName);
if (mfIter == insertdictionaryIstreamMemberFunctionTablePtr_->end())
if (mfIter == executeprimitiveEntryIstreamMemberFunctionTablePtr_->end())
{
FatalErrorIn
(
"functionEntry::insert"
"(const word& functionName, dictionary& parentDict, Istream& is)"
"functionEntry::execute"
"(const word& functionName, const dictionary& parentDict, "
"primitiveEntry&, Istream&)"
) << "Unknown functionEntry " << functionName
<< endl << endl
<< "Valid functionEntries are :" << endl
<< insertdictionaryIstreamMemberFunctionTablePtr_->toc()
<< executeprimitiveEntryIstreamMemberFunctionTablePtr_->toc()
<< exit(FatalError);
}
return mfIter()(parentDict, is);
return mfIter()(parentDict, entry, is);
}
// ************************************************************************* //
......@@ -33,13 +33,10 @@ Class
Foam::functionEntry
Description
A function entry causes entries to be added/manipulated on the specified
A functionEntry causes entries to be added/manipulated on the specified
dictionary given an input stream.
In dictionaries, a @c \# sigil is typically used for a functionEntry.
See Also
functionEntries::includeEntry and functionEntries::inputModeEntry
In dictionaries, a @c '\#' sigil is typically used for a functionEntry.
SourceFiles
functionEntry.C
......@@ -84,44 +81,47 @@ public:
(
bool,
functionEntry,
insert,
primitiveEntryIstream,
execute,
dictionaryIstream,
(
const dictionary& parentDict,
primitiveEntry& entry,
dictionary& parentDict,
Istream& is
),
(parentDict, entry, is)
(parentDict, is)
);
static bool insert
//- Execute the functionEntry in a sub-dict context
static bool execute
(
const word& functionName,
const dictionary& parentDict,
primitiveEntry& entry,
dictionary& parentDict,
Istream& is
);
declareMemberFunctionSelectionTable
(
bool,
functionEntry,
insert,
dictionaryIstream,
execute,
primitiveEntryIstream,
(
dictionary& parentDict,
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
),
(parentDict, is)
(parentDict, entry, is)
);
static bool insert
//- Execute the functionEntry in a primitiveEntry context
static bool execute
(
const word& functionName,
dictionary& parentDict,
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
);
};
......
......@@ -48,16 +48,16 @@ namespace functionEntries
(
functionEntry,
includeEntry,
insert,
primitiveEntryIstream
execute,
dictionaryIstream
);
addToMemberFunctionSelectionTable
(
functionEntry,
includeEntry,
insert,
dictionaryIstream
execute,
primitiveEntryIstream
);
}
}
......@@ -82,10 +82,9 @@ Foam::fileName Foam::functionEntries::includeEntry::includeFileName
}
bool Foam::functionEntries::includeEntry::insert
bool Foam::functionEntries::includeEntry::execute
(
const dictionary& parentDict,
primitiveEntry& entry,
dictionary& parentDict,
Istream& is
)
{
......@@ -93,7 +92,7 @@ bool Foam::functionEntries::includeEntry::insert
if (fileStream)
{
entry.read(parentDict, fileStream);
parentDict.read(fileStream);
return true;
}
else
......@@ -101,7 +100,7 @@ bool Foam::functionEntries::includeEntry::insert
FatalIOErrorIn
(
"functionEntries::includeEntry::includeEntry"
"(dictionary& parentDict, primitiveEntry& entry, Istream& is)",
"(dictionary& parentDict,Istream& is)",
is
) << "Cannot open include file " << fileStream.name()
<< " while reading dictionary " << parentDict.name()
......@@ -111,10 +110,10 @@ bool Foam::functionEntries::includeEntry::insert
}
}
bool Foam::functionEntries::includeEntry::insert
bool Foam::functionEntries::includeEntry::execute
(
dictionary& parentDict,
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
)
{
......@@ -122,7 +121,7 @@ bool Foam::functionEntries::includeEntry::insert
if (fileStream)
{
parentDict.read(fileStream);
entry.read(parentDict, fileStream);
return true;
}
else
......@@ -130,7 +129,7 @@ bool Foam::functionEntries::includeEntry::insert
FatalIOErrorIn
(
"functionEntries::includeEntry::includeEntry"
"(dictionary& parentDict,Istream& is)",
"(dictionary& parentDict, primitiveEntry& entry, Istream& is)",
is
) << "Cannot open include file " << fileStream.name()
<< " while reading dictionary " << parentDict.name()
......@@ -140,5 +139,4 @@ bool Foam::functionEntries::includeEntry::insert
}
}
// ************************************************************************* //
......@@ -29,9 +29,9 @@ Description
Specify an include file when reading dictionaries, expects a
single string to follow.
An example of @c \#include directive:
An example of the @c \#include directive:
@verbatim
\#include "includefile"
#include "includeFile"
@endverbatim
The usual expansion of environment variables and other constructs (eg,
......@@ -85,18 +85,21 @@ public:
// Member Functions
static bool insert
//- Execute the functionEntry in a sub-dict context
static bool execute
(
const dictionary& parentDict,
primitiveEntry& entry,
dictionary& parentDict,
Istream& is
);
static bool insert
//- Execute the functionEntry in a primitiveEntry context
static bool execute
(
dictionary& parentDict,
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
);
};
......
......@@ -47,15 +47,7 @@ namespace functionEntries
(
functionEntry,
inputModeEntry,
insert,
primitiveEntryIstream
);
addToMemberFunctionSelectionTable
(
functionEntry,
inputModeEntry,
insert,
execute,
dictionaryIstream
);
}
......@@ -63,7 +55,7 @@ namespace functionEntries
// * * * * * * * * * * * * * * * * Private Data * * * * * * * * * * * * * * //
Foam::label Foam::functionEntries::inputModeEntry::inputMode_ = imError;
Foam::label Foam::functionEntries::inputModeEntry::mode_ = imError;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //