STYLE: manage dictionary inputMode directly within entry class

- The logic for switching input-mode was previously completely
  encapsulated within the #inputMode directive, but without any
  programming equivalent. Furthermore, the encapsulation in inputMode
  made the logic less clear in other places.

  Exposing the inputMode as an enum with direct access from entry
  simplifies things a fair bit.

- eliminate one level of else/if nesting in entryIO.C for clearer logic

- for dictionary function entries, simply use
  addNamedToMemberFunctionSelectionTable() and avoid defining a type()
  as a static. For most function entries the information is only used
  to get a name for the selection table lookup anyhow.
This commit is contained in:
Mark Olesen
2017-08-03 07:14:17 +02:00
parent c2a0663cc7
commit 5148e4f860
23 changed files with 399 additions and 556 deletions

View File

@ -64,7 +64,8 @@ boundaryField
inlet_4 { $inactive }
inlet_5 "a primitiveEntry is squashed by a directory entry";
inlet_5 { $inactive }
inlet_6 { $.inactive } // Test scoping
inlet_6a { $...inactive } // Relative scoping - fairly horrible to use
inlet_6b { $^inactive } // Absolute scoping
inlet_7 { ${inactive}} // Test variable expansion
inlet_8 { $inactive }
${key} { $inactive }

View File

@ -211,7 +211,7 @@ $(functionEntries)/includeEntry/includeEntry.C
$(functionEntries)/includeEtcEntry/includeEtcEntry.C
$(functionEntries)/includeFuncEntry/includeFuncEntry.C
$(functionEntries)/includeIfPresentEntry/includeIfPresentEntry.C
$(functionEntries)/inputModeEntry/inputModeEntry.C
$(functionEntries)/inputMode/inputMode.C
$(functionEntries)/removeEntry/removeEntry.C
IOdictionary = db/IOobjects/IOdictionary

View File

@ -25,7 +25,6 @@ License
#include "dictionary.H"
#include "IFstream.H"
#include "inputModeEntry.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -49,7 +48,7 @@ Foam::dictionary::dictionary(Istream& is)
parent_(dictionary::null)
{
// Reset input mode as this is a "top-level" dictionary
functionEntries::inputModeEntry::clear();
entry::resetInputMode();
read(is);
}
@ -61,7 +60,7 @@ Foam::dictionary::dictionary(Istream& is, const bool keepHeader)
parent_(dictionary::null)
{
// Reset input mode as this is a "top-level" dictionary
functionEntries::inputModeEntry::clear();
entry::resetInputMode();
read(is, keepHeader);
}
@ -157,7 +156,7 @@ bool Foam::dictionary::substituteKeyword(const word& keyword, bool mergeEntry)
Foam::Istream& Foam::operator>>(Istream& is, dictionary& dict)
{
// Reset input mode assuming this is a "top-level" dictionary
functionEntries::inputModeEntry::clear();
entry::resetInputMode();
dict.clear();
dict.name() = is.name();

View File

@ -35,6 +35,17 @@ int Foam::entry::disableFunctionEntries
);
Foam::entry::inputMode Foam::entry::globalInputMode = inputMode::MERGE;
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
void Foam::entry::resetInputMode()
{
globalInputMode = inputMode::MERGE;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::entry::entry(const keyType& keyword)

View File

@ -67,6 +67,24 @@ class entry
:
public IDLList<entry>::link
{
public:
// Enums/Typedefs
//- The input mode options
enum class inputMode
{
MERGE, //!< Merge sub-dictionaries when possible
OVERWRITE, //!< Keep last entry. Silently remove previous ones
PROTECT, //!< Keep initial entry. Silently ignore subsequent ones
WARN, //!< Keep initial entry. Warn about subsequent ones.
ERROR, //!< FatalError for duplicate entries
GLOBAL //!< Use global value from #globalInputMode variable
};
private:
// Private data
//- Keyword of entry
@ -93,8 +111,12 @@ class entry
public:
//- Enable or disable use of function entries and variable expansions.
static int disableFunctionEntries;
//- The current global input-mode.
static inputMode globalInputMode;
// Constructors
@ -116,11 +138,19 @@ public:
virtual autoPtr<entry> clone() const;
//- Construct from Istream and insert into dictionary
static bool New(dictionary& parentDict, Istream& is);
static bool New
(
dictionary& parentDict,
Istream& is,
const inputMode inMode = inputMode::GLOBAL
);
//- Construct on freestore from Istream and return
static autoPtr<entry> New(Istream& is);
//- Reset the #globalInputMode to %merge
static void resetInputMode();
//- Destructor
virtual ~entry()

View File

@ -28,7 +28,6 @@ License
#include "dictionaryEntry.H"
#include "functionEntry.H"
#include "includeEntry.H"
#include "inputModeEntry.H"
#include "stringOps.H"
#include "dictionaryListEntry.H"
@ -88,13 +87,13 @@ bool Foam::entry::getKeyword(keyType& keyword, Istream& is)
else
{
// Otherwise the token is invalid
cerr<< "--> FOAM Warning : " << std::endl
cerr<< "--> FOAM Warning :" << nl
<< " From function "
<< FUNCTION_NAME << std::endl
<< FUNCTION_NAME << nl
<< " in file " << __FILE__
<< " at line " << __LINE__ << std::endl
<< " Reading " << is.name().c_str() << std::endl
<< " found " << keyToken << std::endl
<< " at line " << __LINE__ << nl
<< " Reading " << is.name().c_str() << nl
<< " found " << keyToken << nl
<< " expected either " << token::END_BLOCK << " or EOF"
<< std::endl;
return false;
@ -102,8 +101,31 @@ bool Foam::entry::getKeyword(keyType& keyword, Istream& is)
}
bool Foam::entry::New(dictionary& parentDict, Istream& is)
bool Foam::entry::New
(
dictionary& parentDict,
Istream& is,
const entry::inputMode inMode
)
{
// The inputMode for dealing with duplicate entries
const entry::inputMode mode =
(
inMode == inputMode::GLOBAL
? globalInputMode
: inMode
);
// If somehow the global itself is 'global' - this is a severe logic error.
if (mode == inputMode::GLOBAL)
{
FatalIOErrorInFunction
(
is
) << "Cannot use 'GLOBAL' as an inputMode"
<< exit(FatalIOError);
}
is.fatalCheck(FUNCTION_NAME);
keyType keyword;
@ -135,197 +157,201 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
else
{
// Otherwise the token is invalid
cerr<< "--> FOAM Warning : " << std::endl
cerr<< "--> FOAM Warning :" << nl
<< " From function "
<< FUNCTION_NAME << std::endl
<< FUNCTION_NAME << nl
<< " in file " << __FILE__
<< " at line " << __LINE__ << std::endl
<< " Reading " << is.name().c_str() << std::endl
<< " found " << keyToken << std::endl
<< " at line " << __LINE__ << nl
<< " Reading " << is.name().c_str() << nl
<< " found " << keyToken << nl
<< " expected either " << token::END_BLOCK << " or EOF"
<< std::endl;
return false;
}
}
else // Keyword starts entry ...
else if (keyword[0] == '#')
{
if (keyword[0] == '#') // ... Function entry
// Function entry
if (disableFunctionEntries)
{
if (disableFunctionEntries)
return parentDict.add
(
new functionEntry
(
keyword,
parentDict,
is
),
false
);
}
else
{
const word functionName(keyword.substr(1), false);
return functionEntry::execute(functionName, parentDict, is);
}
}
else if
(
!disableFunctionEntries
&& keyword[0] == '$'
)
{
// Substitution entry
token nextToken(is);
is.putBack(nextToken);
if (keyword.size() > 2 && keyword[1] == token::BEGIN_BLOCK)
{
// Recursive substitution mode.
// Content between {} is replaced with expansion.
// Then let standard variable expansion deal with rest.
string expanded = keyword.substr(2, keyword.size()-3);
// Substitute dictionary and environment variables.
// Do not allow empty substitutions.
stringOps::inplaceExpand(expanded, parentDict, true, false);
// Restore the '$' prefix.
// Use replace since operator= is private
keyword.std::string::replace(1, keyword.size()-1, expanded);
}
if (nextToken == token::BEGIN_BLOCK)
{
const word varName = keyword.substr(1);
// Lookup the variable name in the given dictionary
const entry* ePtr = parentDict.lookupScopedEntryPtr
(
varName,
true,
true
);
if (ePtr)
{
// Read as primitiveEntry
const keyType newKeyword(ePtr->stream());
return parentDict.add
(
new functionEntry
(
keyword,
parentDict,
is
),
new dictionaryEntry(newKeyword, parentDict, is),
false
);
}
else
{
const word functionName(keyword.substr(1), false);
return functionEntry::execute(functionName, parentDict, is);
}
}
else if
(
!disableFunctionEntries
&& keyword[0] == '$'
) // ... Substitution entry
{
token nextToken(is);
is.putBack(nextToken);
if (keyword.size() > 2 && keyword[1] == token::BEGIN_BLOCK)
{
// Recursive substitution mode.
// Content between {} is replaced with expansion.
// Then let standard variable expansion deal with rest.
string expanded = keyword.substr(2, keyword.size()-3);
// Substitute dictionary and environment variables.
// Do not allow empty substitutions.
stringOps::inplaceExpand(expanded, parentDict, true, false);
// Restore the '$' prefix.
// Use replace since operator= is private
keyword.std::string::replace(1, keyword.size()-1, expanded);
}
if (nextToken == token::BEGIN_BLOCK)
{
const word varName = keyword.substr(1);
// lookup the variable name in the given dictionary
const entry* ePtr = parentDict.lookupScopedEntryPtr
(
varName,
true,
true
);
if (ePtr)
{
// Read as primitiveEntry
const keyType newKeyword(ePtr->stream());
return parentDict.add
(
new dictionaryEntry(newKeyword, parentDict, is),
false
);
}
else
{
FatalIOErrorInFunction(is)
<< "Attempt to use undefined variable " << varName
<< " as keyword"
<< exit(FatalIOError);
return false;
}
}
else
{
// Deal with duplicate entries (at least partially)
const bool mergeEntry =
(
functionEntries::inputModeEntry::merge()
|| functionEntries::inputModeEntry::overwrite()
);
parentDict.substituteScopedKeyword(keyword, mergeEntry);
}
return true;
}
else // ... Data entries
{
token nextToken(is);
is.putBack(nextToken);
if (nextToken == token::END_LIST)
{
FatalIOErrorInFunction(is)
<< "Unexpected token encountered for "
<< keyword << " - " << nextToken.info()
<< "Attempt to use undefined variable " << varName
<< " as keyword"
<< exit(FatalIOError);
return false;
}
// Deal with duplicate entries
bool mergeEntry = false;
// See (using exact match) if entry already present
entry* existingPtr = parentDict.lookupEntryPtr
}
else
{
// Deal with duplicate entries (at least partially)
const bool mergeEntry =
(
keyword,
false,
false
mode == inputMode::MERGE
|| mode == inputMode::OVERWRITE
);
if (existingPtr)
parentDict.substituteScopedKeyword(keyword, mergeEntry);
}
return true;
}
else
{
// Normal entry
token nextToken(is);
is.putBack(nextToken);
if (nextToken == token::END_LIST)
{
FatalIOErrorInFunction(is)
<< "Unexpected token encountered for "
<< keyword << " - " << nextToken.info()
<< exit(FatalIOError);
return false;
}
// How to manage duplicate entries
bool mergeEntry = false;
// See (using exact match) if entry already present
entry* existingPtr = parentDict.lookupEntryPtr
(
keyword,
false,
false
);
if (existingPtr)
{
if (mode == inputMode::MERGE)
{
if (functionEntries::inputModeEntry::merge())
{
mergeEntry = true;
}
else if (functionEntries::inputModeEntry::overwrite())
{
// clear dictionary so merge acts like overwrite
if (existingPtr->isDict())
{
existingPtr->dict().clear();
}
mergeEntry = true;
}
else if (functionEntries::inputModeEntry::protect())
{
// Read and discard the entry.
// Disable function/variable expansion to avoid side-effects
const int oldFlag = entry::disableFunctionEntries;
entry::disableFunctionEntries = 1;
if (nextToken == token::BEGIN_BLOCK)
{
dictionaryEntry dummy("dummy", parentDict, is);
}
else
{
primitiveEntry dummy("dummy", parentDict, is);
}
entry::disableFunctionEntries = oldFlag;
return true;
}
else if (functionEntries::inputModeEntry::error())
{
FatalIOErrorInFunction(is)
<< "duplicate entry: " << keyword
<< exit(FatalIOError);
return false;
}
mergeEntry = true;
}
if (nextToken == token::BEGIN_BLOCK)
else if (mode == inputMode::OVERWRITE)
{
return parentDict.add
(
new dictionaryEntry(keyword, parentDict, is),
mergeEntry
);
// Clear existing dictionary so merge acts like overwrite
if (existingPtr->isDict())
{
existingPtr->dict().clear();
}
mergeEntry = true;
}
else
else if (mode == inputMode::PROTECT)
{
return parentDict.add
(
new primitiveEntry(keyword, parentDict, is),
mergeEntry
);
// Read and discard the entry.
// Disable function/variable expansion to avoid side-effects
const int oldFlag = entry::disableFunctionEntries;
entry::disableFunctionEntries = 1;
if (nextToken == token::BEGIN_BLOCK)
{
dictionaryEntry dummy("dummy", parentDict, is);
}
else
{
primitiveEntry dummy("dummy", parentDict, is);
}
entry::disableFunctionEntries = oldFlag;
return true;
}
else if (mode == inputMode::ERROR)
{
FatalIOErrorInFunction(is)
<< "duplicate entry: " << keyword
<< exit(FatalIOError);
return false;
}
}
if (nextToken == token::BEGIN_BLOCK)
{
return parentDict.add
(
new dictionaryEntry(keyword, parentDict, is),
mergeEntry
);
}
else
{
return parentDict.add
(
new primitiveEntry(keyword, parentDict, is),
mergeEntry
);
}
}
}

View File

@ -35,22 +35,22 @@ namespace Foam
{
namespace functionEntries
{
defineTypeNameAndDebug(calcEntry, 0);
addToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable
(
functionEntry,
calcEntry,
execute,
dictionaryIstream
dictionaryIstream,
calc
);
addToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable
(
functionEntry,
calcEntry,
execute,
primitiveEntryIstream
primitiveEntryIstream,
calc
);
}

View File

@ -70,34 +70,18 @@ class calcEntry
:
public functionEntry
{
// Private Member Functions
//- Disallow default bitwise copy construct
calcEntry(const calcEntry&);
//- Disallow default bitwise assignment
void operator=(const calcEntry&);
public:
//- Runtime type information
ClassName("calc");
//- Execute in a primitiveEntry context
static bool execute
(
const dictionary& parentDict,
primitiveEntry& thisEntry,
Istream& is
);
// Member Functions
//- Execute the functionEntry in a sub-dict context
static bool execute(dictionary& parentDict, Istream&);
//- Execute the functionEntry in a primitiveEntry context
static bool execute
(
const dictionary& parentDict,
primitiveEntry&,
Istream&
);
//- Execute in a sub-dict context
static bool execute(dictionary& parentDict, Istream& is);
};

View File

@ -38,22 +38,23 @@ namespace functionEntries
{
defineTypeNameAndDebug(codeStream, 0);
addToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable
(
functionEntry,
codeStream,
execute,
dictionaryIstream
dictionaryIstream,
codeStream
);
addToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable
(
functionEntry,
codeStream,
execute,
primitiveEntryIstream
primitiveEntryIstream,
codeStream
);
}
}
@ -175,7 +176,7 @@ Foam::functionEntries::codeStream::getFunction
// create library if required
if (!lib)
{
bool create =
const bool create =
Pstream::master()
|| (regIOobject::fileModificationSkew <= 0); // not NFS

View File

@ -118,10 +118,8 @@ class codeStream
//- Interpreter function type
typedef void (*streamingFunctionType)(Ostream&, const dictionary&);
// Private Member Functions
//- Helper function: parent (of parent etc.) of dictionary up to the top
static const dictionary& topDict(const dictionary&);
// Private Member Functions
//- Helper function: access IOobject for master-only-reading
// functionality
@ -139,10 +137,10 @@ class codeStream
//- Disallow default bitwise copy construct
codeStream(const codeStream&);
codeStream(const codeStream&) = delete;
//- Disallow default bitwise assignment
void operator=(const codeStream&);
void operator=(const codeStream&) = delete;
public:
@ -165,14 +163,14 @@ public:
// Member Functions
//- Execute the functionEntry in a sub-dict context
static bool execute(dictionary& parentDict, Istream&);
static bool execute(dictionary& parentDict, Istream& is);
//- Execute the functionEntry in a primitiveEntry context
static bool execute
(
const dictionary& parentDict,
primitiveEntry&,
Istream&
primitiveEntry& entry,
Istream& is
);
};

View File

@ -58,7 +58,7 @@ namespace Foam
class dictionary;
/*---------------------------------------------------------------------------*\
Class functionEntry Declaration
Class functionEntry Declaration
\*---------------------------------------------------------------------------*/
class functionEntry
@ -71,10 +71,10 @@ class functionEntry
static token readLine(const word& key, Istream& is);
//- Disallow default bitwise copy construct
functionEntry(const functionEntry&);
functionEntry(const functionEntry&) = delete;
//- Disallow default bitwise assignment
void operator=(const functionEntry&);
void operator=(const functionEntry&) = delete;
public:
@ -82,7 +82,7 @@ public:
// Constructors
//- Construct from keyword, parent dictionary and Istream
functionEntry(const word&, const dictionary&, Istream&);
functionEntry(const word& key, const dictionary& dict, Istream& is);
// Member Function Selectors
@ -105,7 +105,7 @@ public:
(
const word& functionName,
dictionary& parentDict,
Istream&
Istream& is
);
declareMemberFunctionSelectionTable
@ -127,12 +127,12 @@ public:
(
const word& functionName,
const dictionary& parentDict,
primitiveEntry&,
Istream&
primitiveEntry& entry,
Istream& is
);
//- Write
virtual void write(Ostream&) const;
virtual void write(Ostream& os) const;
};

View File

@ -31,15 +31,6 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::word Foam::functionEntries::includeEntry::typeName
(
Foam::functionEntries::includeEntry::typeName_()
);
// Don't lookup the debug switch here as the debug switch dictionary
// might include includeEntry
int Foam::functionEntries::includeEntry::debug(0);
bool Foam::functionEntries::includeEntry::log(false);
@ -47,50 +38,50 @@ namespace Foam
{
namespace functionEntries
{
addToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable
(
functionEntry,
includeEntry,
execute,
dictionaryIstream
dictionaryIstream,
include
);
addToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable
(
functionEntry,
includeEntry,
execute,
primitiveEntryIstream
primitiveEntryIstream,
include
);
}
}
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
Foam::fileName Foam::functionEntries::includeEntry::includeFileName
Foam::fileName Foam::functionEntries::includeEntry::resolveFile
(
Istream& is,
const dictionary& dict
)
{
fileName fName(is);
// Substitute dictionary and environment variables. Allow empty
// substitutions.
// Substitute dictionary and environment variables.
// Allow empty substitutions.
stringOps::inplaceExpand(fName, dict, true, true);
if (fName.empty() || fName.isAbsolute())
{
return fName;
}
else
{
// relative name
return fileName(is.name()).path()/fName;
}
// Relative name
return fileName(is.name()).path()/fName;
}
Foam::fileName Foam::functionEntries::includeEntry::includeFileName
Foam::fileName Foam::functionEntries::includeEntry::resolveFile
(
const fileName& dir,
const fileName& f,
@ -98,19 +89,17 @@ Foam::fileName Foam::functionEntries::includeEntry::includeFileName
)
{
fileName fName(f);
// Substitute dictionary and environment variables. Allow empty
// substitutions.
// Substitute dictionary and environment variables.
// Allow empty substitutions.
stringOps::inplaceExpand(fName, dict, true, true);
if (fName.empty() || fName.isAbsolute())
{
return fName;
}
else
{
// relative name
return dir/fName;
}
// Relative name
return dir/fName;
}
@ -122,11 +111,8 @@ bool Foam::functionEntries::includeEntry::execute
Istream& is
)
{
const fileName rawFName(is);
const fileName fName
(
includeFileName(is.name().path(), rawFName, parentDict)
);
const fileName rawName(is);
const fileName fName = resolveFile(is.name().path(), rawName, parentDict);
// Read contents of file into parentDict
@ -147,7 +133,7 @@ bool Foam::functionEntries::includeEntry::execute
(
dynamic_cast<const regIOobject&>(top)
);
//Info<< rio.name() << " : adding depenency on included file "
//Info<< rio.name() << " : adding dependency on included file "
// << fName << endl;
rio.addWatch(fName);
@ -162,7 +148,7 @@ bool Foam::functionEntries::includeEntry::execute
(
is
) << "Cannot open include file "
<< (ifs.name().size() ? ifs.name() : rawFName)
<< (ifs.name().size() ? ifs.name() : rawName)
<< " while reading dictionary " << parentDict.name()
<< exit(FatalIOError);
@ -178,12 +164,8 @@ bool Foam::functionEntries::includeEntry::execute
Istream& is
)
{
const fileName rawFName(is);
const fileName fName
(
includeFileName(is.name().path(), rawFName, parentDict)
);
const fileName rawName(is);
const fileName fName = resolveFile(is.name().path(), rawName, parentDict);
// Read contents of file into parentDict
IFstream ifs(fName);
@ -203,7 +185,7 @@ bool Foam::functionEntries::includeEntry::execute
(
dynamic_cast<const regIOobject&>(top)
);
//Info<< rio.name() << " : adding depenency on included file "
//Info<< rio.name() << " : adding dependency on included file "
// << fName << endl;
rio.addWatch(fName);
@ -218,7 +200,7 @@ bool Foam::functionEntries::includeEntry::execute
(
is
) << "Cannot open include file "
<< (ifs.name().size() ? ifs.name() : rawFName)
<< (ifs.name().size() ? ifs.name() : rawName)
<< " while reading dictionary " << parentDict.name()
<< exit(FatalIOError);

View File

@ -64,52 +64,40 @@ class includeEntry
:
public functionEntry
{
// Private Member Functions
//- Disallow default bitwise copy construct
includeEntry(const includeEntry&);
//- Disallow default bitwise assignment
void operator=(const includeEntry&);
protected:
// Protected Member Functions
//- Read the include fileName from Istream, expand and return
static fileName includeFileName(Istream&, const dictionary&);
static fileName resolveFile(Istream& is, const dictionary& dict);
//- Expand include fileName and return
static fileName includeFileName
static fileName resolveFile
(
const fileName& dir,
const fileName&,
const dictionary&
const fileName& f,
const dictionary& dict
);
public:
// Static data members
//- Report which file is included to stdout
//- Report to stdout which file is included
static bool log;
//- Runtime type information
ClassName("include");
// Member Functions
//- Execute the functionEntry in a sub-dict context
static bool execute(dictionary& parentDict, Istream&);
//- Include file in a sub-dict context
static bool execute(dictionary& parentDict, Istream& is);
//- Execute the functionEntry in a primitiveEntry context
//- Include file in a primitiveEntry context
static bool execute
(
const dictionary& parentDict,
primitiveEntry&,
Istream&
primitiveEntry& entry,
Istream& is
);
};

View File

@ -31,15 +31,6 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::word Foam::functionEntries::includeEtcEntry::typeName
(
Foam::functionEntries::includeEtcEntry::typeName_()
);
// Don't lookup the debug switch here as the debug switch dictionary
// might include includeEtcEntry
int Foam::functionEntries::includeEtcEntry::debug(0);
bool Foam::functionEntries::includeEtcEntry::log(false);
@ -47,27 +38,29 @@ namespace Foam
{
namespace functionEntries
{
addToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable
(
functionEntry,
includeEtcEntry,
execute,
dictionaryIstream
dictionaryIstream,
includeEtc
);
addToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable
(
functionEntry,
includeEtcEntry,
execute,
primitiveEntryIstream
primitiveEntryIstream,
includeEtc
);
}
}
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
Foam::fileName Foam::functionEntries::includeEtcEntry::includeEtcFileName
Foam::fileName Foam::functionEntries::includeEtcEntry::resolveFile
(
const fileName& f,
const dictionary& dict
@ -83,11 +76,9 @@ Foam::fileName Foam::functionEntries::includeEtcEntry::includeEtcFileName
{
return fName;
}
else
{
// Search the etc directories for the file
return findEtcFile(fName);
}
// Search the etc directories for the file
return Foam::findEtcFile(fName);
}
@ -99,11 +90,8 @@ bool Foam::functionEntries::includeEtcEntry::execute
Istream& is
)
{
const fileName rawFName(is);
const fileName fName
(
includeEtcFileName(rawFName, parentDict)
);
const fileName rawName(is);
const fileName fName(resolveFile(rawName, parentDict));
IFstream ifs(fName);
if (ifs)
@ -121,7 +109,7 @@ bool Foam::functionEntries::includeEtcEntry::execute
(
is
) << "Cannot open etc file "
<< (ifs.name().size() ? ifs.name() : rawFName)
<< (ifs.name().size() ? ifs.name() : rawName)
<< " while reading dictionary " << parentDict.name()
<< exit(FatalIOError);
@ -137,11 +125,8 @@ bool Foam::functionEntries::includeEtcEntry::execute
Istream& is
)
{
const fileName rawFName(is);
const fileName fName
(
includeEtcFileName(rawFName, parentDict)
);
const fileName rawName(is);
const fileName fName(resolveFile(rawName, parentDict));
IFstream ifs(fName);
if (ifs)
@ -159,7 +144,7 @@ bool Foam::functionEntries::includeEtcEntry::execute
(
is
) << "Cannot open etc file "
<< (ifs.name().size() ? ifs.name() : rawFName)
<< (ifs.name().size() ? ifs.name() : rawName)
<< " while reading dictionary " << parentDict.name()
<< exit(FatalIOError);

View File

@ -79,45 +79,29 @@ class includeEtcEntry
:
public functionEntry
{
// Private Member Functions
//- Disallow default bitwise copy construct
includeEtcEntry(const includeEtcEntry&);
//- Disallow default bitwise assignment
void operator=(const includeEtcEntry&);
//- Expand include fileName and return
static fileName includeEtcFileName
(
const fileName&,
const dictionary&
);
//- Expand include fileName and return
static fileName resolveFile(const fileName& f, const dictionary& dict);
public:
// Static data members
//- Report which file is included to stdout
//- Report to stdout which file is included
static bool log;
//- Runtime type information
ClassName("includeEtc");
// Member Functions
//- Execute the functionEntry in a sub-dict context
static bool execute(dictionary& parentDict, Istream&);
//- Include file in a sub-dict context
static bool execute(dictionary& parentDict, Istream& is);
//- Execute the functionEntry in a primitiveEntry context
//- Include file in a primitiveEntry context
static bool execute
(
const dictionary& parentDict,
primitiveEntry&,
Istream&
primitiveEntry& entry,
Istream& is
);
};

View File

@ -33,14 +33,13 @@ namespace Foam
{
namespace functionEntries
{
defineTypeNameAndDebug(includeFuncEntry, 0);
addToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable
(
functionEntry,
includeFuncEntry,
execute,
dictionaryIstream
dictionaryIstream,
includeFunc
);
}
}

View File

@ -83,17 +83,10 @@ class includeFuncEntry
:
public functionEntry
{
public:
//- Runtime type information
ClassName("includeFunc");
// Member Functions
//- Execute the functionEntry in a sub-dict context
static bool execute(dictionary& parentDict, Istream&);
//- Run function in a sub-dict context
static bool execute(dictionary& parentDict, Istream& is);
};

View File

@ -31,33 +31,26 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::word Foam::functionEntries::includeIfPresentEntry::typeName
(
Foam::functionEntries::includeIfPresentEntry::typeName_()
);
// Don't lookup the debug switch here as the debug switch dictionary
// might include includeIfPresentEntry
int Foam::functionEntries::includeIfPresentEntry::debug(0);
namespace Foam
{
namespace functionEntries
{
addToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable
(
functionEntry,
includeIfPresentEntry,
execute,
dictionaryIstream
dictionaryIstream,
includeIfPresent
);
addToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable
(
functionEntry,
includeIfPresentEntry,
execute,
primitiveEntryIstream
primitiveEntryIstream,
includeIfPresent
);
}
}
@ -70,7 +63,7 @@ bool Foam::functionEntries::includeIfPresentEntry::execute
Istream& is
)
{
const fileName fName(includeFileName(is, parentDict));
const fileName fName(resolveFile(is, parentDict));
IFstream ifs(fName);
if (ifs)
@ -105,7 +98,7 @@ bool Foam::functionEntries::includeIfPresentEntry::execute
Istream& is
)
{
const fileName fName(includeFileName(is, parentDict));
const fileName fName(resolveFile(is, parentDict));
IFstream ifs(fName);
if (ifs)

View File

@ -58,32 +58,18 @@ class includeIfPresentEntry
:
public includeEntry
{
// Private Member Functions
//- Disallow default bitwise copy construct
includeIfPresentEntry(const includeIfPresentEntry&);
//- Disallow default bitwise assignment
void operator=(const includeIfPresentEntry&);
public:
//- Runtime type information
ClassName("includeIfPresent");
//- Include (if present) in a sub-dict context
static bool execute(dictionary& parentDict, Istream& is);
// Member Functions
//- Execute the functionEntry in a sub-dict context
static bool execute(dictionary& parentDict, Istream&);
//- Execute the functionEntry in a primitiveEntry context
static bool execute
(
const dictionary& parentDict,
primitiveEntry&,
Istream&
);
//- Include (if present) in a primitiveEntry context
static bool execute
(
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
);
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -23,34 +23,23 @@ License
\*---------------------------------------------------------------------------*/
#include "inputModeEntry.H"
#include "inputMode.H"
#include "dictionary.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::word Foam::functionEntries::inputModeEntry::typeName
(
Foam::functionEntries::inputModeEntry::typeName_()
);
// Don't lookup the debug switch here as the debug switch dictionary
// might include inputModeEntries
int Foam::functionEntries::inputModeEntry::debug(0);
Foam::functionEntries::inputModeEntry::inputMode
Foam::functionEntries::inputModeEntry::mode_(MERGE);
namespace Foam
{
namespace functionEntries
{
addToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable
(
functionEntry,
inputModeEntry,
inputMode,
execute,
dictionaryIstream
dictionaryIstream,
inputMode
);
}
}
@ -58,23 +47,23 @@ namespace functionEntries
const Foam::Enum
<
Foam::functionEntries::inputModeEntry::inputMode
Foam::entry::inputMode
>
Foam::functionEntries::inputModeEntry::inputModeNames
Foam::functionEntries::inputMode::selectableNames
{
{ inputMode::MERGE, "merge" },
{ inputMode::OVERWRITE, "overwrite" },
{ inputMode::PROTECT, "protect" },
{ inputMode::WARN, "warn" },
{ inputMode::ERROR, "error" },
{ entry::inputMode::MERGE, "merge" },
{ entry::inputMode::OVERWRITE, "overwrite" },
{ entry::inputMode::PROTECT, "protect" },
{ entry::inputMode::WARN, "warn" },
{ entry::inputMode::ERROR, "error" },
// Aliases
{ inputMode::MERGE, "default" },
{ entry::inputMode::MERGE, "default" },
};
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
bool Foam::functionEntries::inputModeEntry::execute
bool Foam::functionEntries::inputMode::execute
(
dictionary& unused,
Istream& is
@ -82,10 +71,10 @@ bool Foam::functionEntries::inputModeEntry::execute
{
const word modeName(is);
// Bheaviour like Enum lookupOrFailsafe()
if (inputModeNames.hasEnum(modeName))
// Behaviour like Enum lookupOrFailsafe()
if (selectableNames.hasEnum(modeName))
{
mode_ = inputModeNames[modeName];
entry::globalInputMode = selectableNames[modeName];
}
else
{
@ -94,46 +83,11 @@ bool Foam::functionEntries::inputModeEntry::execute
<< "' ... defaulting to 'merge'"
<< endl;
reset();
entry::resetInputMode();
}
return true;
}
void Foam::functionEntries::inputModeEntry::reset()
{
mode_ = MERGE;
}
void Foam::functionEntries::inputModeEntry::clear()
{
reset();
}
bool Foam::functionEntries::inputModeEntry::merge()
{
return mode_ == MERGE;
}
bool Foam::functionEntries::inputModeEntry::overwrite()
{
return mode_ == OVERWRITE;
}
bool Foam::functionEntries::inputModeEntry::protect()
{
return mode_ == PROTECT;
}
bool Foam::functionEntries::inputModeEntry::error()
{
return mode_ == ERROR;
}
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -22,11 +22,11 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::functionEntries::inputModeEntry
Foam::functionEntries::inputMode
Description
Specify the input mode when reading dictionaries, expects
a single word to follow.
Specify the global input mode when reading further dictionaries,
expects a single word to follow.
An example of \c \#inputMode directive:
\verbatim
@ -47,16 +47,15 @@ Description
- \par default
The default treatment - currently identical to \b merge.
Note that the clear() method resets to the default mode (merge).
SourceFiles
inputModeEntry.C
inputMode.C
\*---------------------------------------------------------------------------*/
#ifndef inputModeEntry_H
#define inputModeEntry_H
#ifndef inputMode_H
#define inputMode_H
#include "entry.H"
#include "functionEntry.H"
#include "Enum.H"
@ -68,67 +67,20 @@ namespace functionEntries
{
/*---------------------------------------------------------------------------*\
Class inputModeEntry Declaration
Class inputMode Declaration
\*---------------------------------------------------------------------------*/
class inputModeEntry
class inputMode
:
public functionEntry
{
//- The input mode options
enum inputMode
{
MERGE,
OVERWRITE,
PROTECT,
WARN,
ERROR
};
//- Text representations of the input modes
const static Enum<inputMode> inputModeNames;
//- The current input mode
static inputMode mode_;
// Private Member Functions
//- Disallow default bitwise copy construct
inputModeEntry(const inputModeEntry&) = delete;
//- Disallow default bitwise assignment
void operator=(const inputModeEntry&) = delete;
public:
//- Runtime type information
ClassName("inputMode");
//- Text representations of the selectable input modes
static const Enum<entry::inputMode> selectableNames;
// Member Functions
//- Execute the functionEntry in a sub-dict context
static bool execute(dictionary& parentDict, Istream& is);
//- Reset the inputMode to %default (ie, %merge)
static void reset();
//- Identical to reset.
static void clear();
//- Return true if the inputMode is %merge
static bool merge();
//- Return true if the inputMode is %overwrite
static bool overwrite();
//- Return true if the inputMode is %protect
static bool protect();
//- Return true if the inputMode is %error
static bool error();
//- Change the global input-mode.
static bool execute(dictionary& unused, Istream& is);
};

View File

@ -31,25 +31,17 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::word Foam::functionEntries::removeEntry::typeName
(
Foam::functionEntries::removeEntry::typeName_()
);
// Don't lookup the debug switch here as the debug switch dictionary
// might include removeEntry
int Foam::functionEntries::removeEntry::debug(0);
namespace Foam
{
namespace functionEntries
{
addToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable
(
functionEntry,
removeEntry,
execute,
dictionaryIstream
dictionaryIstream,
remove
);
}
}

View File

@ -64,25 +64,10 @@ class removeEntry
:
public functionEntry
{
// Private Member Functions
//- Disallow default bitwise copy construct
removeEntry(const removeEntry&) = delete;
//- Disallow default bitwise assignment
void operator=(const removeEntry&) = delete;
public:
//- Runtime type information
ClassName("remove");
// Member Functions
//- Execute the functionEntry in a sub-dict context
static bool execute(dictionary& parentDict, Istream& is);
//- Remove entries from the current sub-dict context
static bool execute(dictionary& parentDict, Istream& is);
};