dictionary: Removed support for the deprecated "dot" syntax

to simplify maintenance and extension of the current "slash" syntax.
This commit is contained in:
Henry Weller
2023-07-11 15:22:44 +01:00
parent bc34024bd6
commit 805a7de6d9
10 changed files with 173 additions and 689 deletions

View File

@ -155,7 +155,6 @@ Usage
#include "IFstream.H"
#include "OFstream.H"
#include "includeEntry.H"
#include "inputSyntaxEntry.H"
using namespace Foam;
@ -214,31 +213,6 @@ IOstream::streamFormat readDict(dictionary& dict, const fileName& dictFileName)
}
//- Convert keyword syntax to "dot" if the dictionary is "dot" syntax
word dotToSlash(const fileName& entryName)
{
if
(
functionEntries::inputSyntaxEntry::dot()
&& entryName.find('/') != string::npos
)
{
wordList entryNames(entryName.components('/'));
word entry(entryNames[0]);
for (label i = 1; i < entryNames.size(); i++)
{
entry += word('.') + entryNames[i];
}
return entry;
}
else
{
return entryName;
}
}
void remove(dictionary& dict, const dictionary& removeDict)
{
forAllConstIter(dictionary, removeDict, iter)
@ -285,7 +259,7 @@ void substitute(dictionary& dict, string substitutions)
forAll(namedArgs, i)
{
const Pair<word> dAk(dictAndKeyword(dotToSlash(namedArgs[i].first())));
const Pair<word> dAk(dictAndKeyword(namedArgs[i].first()));
dictionary& subDict(dict.scopedDict(dAk.first()));
IStringStream entryStream
(
@ -491,7 +465,7 @@ int main(int argc, char *argv[])
word entryName;
if (args.optionReadIfPresent("entry", entryName))
{
const word scopedName(dotToSlash(entryName));
const word scopedName(entryName);
string newValue;
if

View File

@ -78,9 +78,6 @@ OptimisationSwitches
// Force dumping and exit (at next timestep) upon signal (-1 to disable)
stopAtWriteNowSignal -1; // 12; // SIGUSR2
// Default dictionary scoping syntax
inputSyntax slash;
}

View File

@ -235,7 +235,6 @@ $(functionEntries)/includeEntry/includeEntry.C
$(functionEntries)/includeEtcEntry/includeEtcEntry.C
$(functionEntries)/includeFuncEntry/includeFuncEntry.C
$(functionEntries)/includeIfPresentEntry/includeIfPresentEntry.C
$(functionEntries)/inputSyntaxEntry/inputSyntaxEntry.C
$(functionEntries)/inputModeEntry/inputModeEntry.C
$(functionEntries)/removeEntry/removeEntry.C
$(functionEntries)/ifeqEntry/ifeqEntry.C

View File

@ -27,7 +27,6 @@ License
#include "dictionaryEntry.H"
#include "regExp.H"
#include "OSHA1stream.H"
#include "inputSyntaxEntry.H"
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
@ -46,251 +45,6 @@ bool Foam::dictionary::writeOptionalEntries
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
const Foam::entry* Foam::dictionary::lookupDotScopedSubEntryPtr
(
const word& keyword,
bool recursive,
bool patternMatch
) const
{
string::size_type dotPos = keyword.find('.');
if (dotPos == string::npos)
{
// Non-scoped lookup
return lookupEntryPtr(keyword, recursive, patternMatch);
}
else
{
if (dotPos == 0)
{
// Starting with a '.'. Go up for every 2nd '.' found
const dictionary* dictPtr = this;
string::size_type begVar = dotPos + 1;
string::const_iterator iter = keyword.begin() + begVar;
string::size_type endVar = begVar;
while (iter != keyword.end() && *iter == '.')
{
++iter;
++endVar;
// Go to parent
if (&dictPtr->parent_ == &dictionary::null)
{
FatalIOErrorInFunction(*this)
<< "No parent of current dictionary"
<< " when searching for "
<< keyword.substr(begVar, keyword.size() - begVar)
<< exit(FatalIOError);
}
dictPtr = &dictPtr->parent_;
}
return dictPtr->lookupScopedSubEntryPtr
(
keyword.substr(endVar),
false,
patternMatch
);
}
else
{
// Extract the first word
word firstWord = keyword.substr(0, dotPos);
const entry* entPtr = lookupDotScopedSubEntryPtr
(
firstWord,
false, // recursive
patternMatch
);
if (!entPtr)
{
// Fall back to finding key with '.' so e.g. if keyword is
// a.b.c.d it would try
// a.b, a.b.c, a.b.c.d
string::size_type nextDotPos = keyword.find
(
'.',
dotPos + 1
);
while (true)
{
const entry* subEntPtr = lookupEntryPtr
(
keyword.substr(0, nextDotPos),
false, // recursive,
patternMatch
);
if (nextDotPos == string::npos)
{
// Parsed the whole word. Return entry or null.
return subEntPtr;
}
if (subEntPtr && subEntPtr->isDict())
{
return subEntPtr->dict().lookupDotScopedSubEntryPtr
(
keyword.substr
(
nextDotPos,
keyword.size() - nextDotPos
),
false,
patternMatch
);
}
nextDotPos = keyword.find('.', nextDotPos + 1);
}
}
if (entPtr->isDict())
{
return entPtr->dict().lookupDotScopedSubEntryPtr
(
keyword.substr(dotPos, keyword.size() - dotPos),
false,
patternMatch
);
}
else
{
return nullptr;
}
}
}
}
const Foam::entry* Foam::dictionary::lookupSlashScopedSubEntryPtr
(
const word& keyword,
bool recursive,
bool patternMatch
) const
{
string::size_type slashPos = keyword.find('/');
if (slashPos == string::npos)
{
// Non-scoped lookup
return lookupEntryPtr(keyword, recursive, patternMatch);
}
else
{
// Extract the first word
word firstWord = keyword.substr(0, slashPos);
slashPos++;
if (firstWord == ".")
{
return lookupScopedSubEntryPtr
(
keyword.substr(slashPos),
false,
patternMatch
);
}
else if (firstWord == "..")
{
// Go to parent
if (&parent_ == &dictionary::null)
{
FatalIOErrorInFunction(*this)
<< "No parent of current dictionary"
<< " when searching for "
<< keyword.substr(slashPos, keyword.size() - slashPos)
<< exit(FatalIOError);
}
return parent_.lookupScopedSubEntryPtr
(
keyword.substr(slashPos),
false,
patternMatch
);
}
else
{
const entry* entPtr = lookupScopedSubEntryPtr
(
firstWord,
false, // recursive
patternMatch
);
if (!entPtr)
{
// Fall back to finding key with '/' so e.g. if keyword is
// a/b/c/d it would try
// a/b, a/b/c, a/b/c/d
string::size_type nextSlashPos = keyword.find
(
'/',
slashPos
);
while (true)
{
const entry* subEntPtr = lookupEntryPtr
(
keyword.substr(0, nextSlashPos),
false, // recursive,
patternMatch
);
if (nextSlashPos == string::npos)
{
// Parsed the whole word. Return entry or null.
return subEntPtr;
}
nextSlashPos++;
if (subEntPtr && subEntPtr->isDict())
{
return subEntPtr->dict().lookupScopedSubEntryPtr
(
keyword.substr
(
nextSlashPos,
keyword.size() - nextSlashPos
),
false,
patternMatch
);
}
nextSlashPos = keyword.find('/', nextSlashPos);
}
}
if (entPtr->isDict())
{
return entPtr->dict().lookupScopedSubEntryPtr
(
keyword.substr(slashPos, keyword.size() - slashPos),
false,
patternMatch
);
}
else
{
return nullptr;
}
}
}
}
const Foam::entry* Foam::dictionary::lookupScopedSubEntryPtr
(
const word& keyword,
@ -298,74 +52,173 @@ const Foam::entry* Foam::dictionary::lookupScopedSubEntryPtr
bool patternMatch
) const
{
if (functionEntries::inputSyntaxEntry::dot())
{
return lookupDotScopedSubEntryPtr(keyword, recursive, patternMatch);
}
else
{
// Check for the dictionary boundary marker
const string::size_type emarkPos = keyword.find('!');
// Check for the dictionary boundary marker
const string::size_type emarkPos = keyword.find('!');
if (emarkPos == string::npos || emarkPos == 0)
if (emarkPos == string::npos || emarkPos == 0)
{
// Lookup in this dictionary
string::size_type slashPos = keyword.find('/');
if (slashPos == string::npos)
{
// Lookup in this dictionary
return lookupSlashScopedSubEntryPtr
(
keyword,
recursive,
patternMatch
);
// Non-scoped lookup
return lookupEntryPtr(keyword, recursive, patternMatch);
}
else
{
// Lookup in the dictionary specified by file name
// created from the part of the keyword before the '!'
// Extract the first word
word firstWord = keyword.substr(0, slashPos);
slashPos++;
fileName fName = keyword.substr(0, emarkPos);
if (!fName.isAbsolute())
if (firstWord == ".")
{
fName = topDict().name().path()/fName;
return lookupScopedSubEntryPtr
(
keyword.substr(slashPos),
false,
patternMatch
);
}
if (fName == topDict().name())
else if (firstWord == "..")
{
FatalIOErrorInFunction(*this)
<< "Attempt to re-read current dictionary " << fName
<< " for keyword "
<< keyword
<< exit(FatalIOError);
// Go to parent
if (&parent_ == &dictionary::null)
{
FatalIOErrorInFunction(*this)
<< "No parent of current dictionary"
<< " when searching for "
<< keyword.substr(slashPos, keyword.size() - slashPos)
<< exit(FatalIOError);
}
return parent_.lookupScopedSubEntryPtr
(
keyword.substr(slashPos),
false,
patternMatch
);
}
const word localKeyword = keyword.substr
(
emarkPos + 1,
keyword.size() - emarkPos - 1
);
includedDictionary dict(fName, *this);
const Foam::entry* entryPtr = dict.lookupScopedEntryPtr
(
localKeyword,
recursive,
patternMatch
);
if (!entryPtr)
else
{
FatalIOErrorInFunction(dict)
<< "keyword " << localKeyword
<< " is undefined in dictionary "
<< dict.name()
<< exit(FatalIOError);
}
const entry* entPtr = lookupScopedSubEntryPtr
(
firstWord,
false, // recursive
patternMatch
);
return entryPtr->clone(*this).ptr();
if (!entPtr)
{
// Fall back to finding key with '/' so e.g. if keyword is
// a/b/c/d it would try
// a/b, a/b/c, a/b/c/d
string::size_type nextSlashPos = keyword.find
(
'/',
slashPos
);
while (true)
{
const entry* subEntPtr = lookupEntryPtr
(
keyword.substr(0, nextSlashPos),
false, // recursive,
patternMatch
);
if (nextSlashPos == string::npos)
{
// Parsed the whole word. Return entry or null.
return subEntPtr;
}
nextSlashPos++;
if (subEntPtr && subEntPtr->isDict())
{
return subEntPtr->dict().lookupScopedSubEntryPtr
(
keyword.substr
(
nextSlashPos,
keyword.size() - nextSlashPos
),
false,
patternMatch
);
}
nextSlashPos = keyword.find('/', nextSlashPos);
}
}
if (entPtr->isDict())
{
return entPtr->dict().lookupScopedSubEntryPtr
(
keyword.substr(slashPos, keyword.size() - slashPos),
false,
patternMatch
);
}
else
{
return nullptr;
}
}
}
}
else
{
// Lookup in the dictionary specified by file name
// created from the part of the keyword before the '!'
fileName fName = keyword.substr(0, emarkPos);
if (!fName.isAbsolute())
{
fName = topDict().name().path()/fName;
}
if (fName == topDict().name())
{
FatalIOErrorInFunction(*this)
<< "Attempt to re-read current dictionary " << fName
<< " for keyword "
<< keyword
<< exit(FatalIOError);
}
const word localKeyword = keyword.substr
(
emarkPos + 1,
keyword.size() - emarkPos - 1
);
includedDictionary dict(fName, *this);
const Foam::entry* entryPtr = dict.lookupScopedEntryPtr
(
localKeyword,
recursive,
patternMatch
);
if (!entryPtr)
{
FatalIOErrorInFunction(dict)
<< "keyword " << localKeyword
<< " is undefined in dictionary "
<< dict.name()
<< exit(FatalIOError);
}
return entryPtr->clone(*this).ptr();
}
}
@ -583,7 +436,7 @@ Foam::word Foam::dictionary::topDictKeyword() const
if (&p != this && !p.name().empty())
{
const word pKeyword = p.topDictKeyword();
const char pSeparator = functionEntries::inputSyntaxEntry::scopeChar();
const char pSeparator = '/';
return
pKeyword == word::null
? dictName()
@ -890,13 +743,8 @@ const Foam::entry* Foam::dictionary::lookupScopedEntryPtr
bool patternMatch
) const
{
// '!' indicates the top-level directory in the "slash" syntax
// ':' indicates the top-level directory in the "dot" syntax
if
(
(functionEntries::inputSyntaxEntry::slash() && keyword[0] == '!')
|| (functionEntries::inputSyntaxEntry::dot() && keyword[0] == ':')
)
// '!' indicates the top-level directory
if (keyword[0] == '!')
{
// Go up to top level
const dictionary* dictPtr = this;
@ -1811,10 +1659,7 @@ void Foam::dictArgList
Foam::Pair<Foam::word> Foam::dictAndKeyword(const word& scopedName)
{
string::size_type i = scopedName.find_last_of
(
functionEntries::inputSyntaxEntry::scopeChar()
);
string::size_type i = scopedName.find_last_of('/');
if (i != string::npos)
{

View File

@ -177,25 +177,8 @@ class dictionary
// Private Member Functions
//- Find and return an entry data stream pointer if present
// otherwise return nullptr. Supports scoping using '.'
const entry* lookupDotScopedSubEntryPtr
(
const word&,
bool recursive,
bool patternMatch
) const;
//- Find and return an entry data stream pointer if present
// otherwise return nullptr. Supports scoping using '/'
const entry* lookupSlashScopedSubEntryPtr
(
const word&,
bool recursive,
bool patternMatch
) const;
//- Find and return an entry data stream pointer if present
// otherwise return nullptr. Supports scoping using '/' or '.'
// otherwise return nullptr.
// Allows scoping using '/' with special handling for '!' and '..'.
const entry* lookupScopedSubEntryPtr
(
const word&,

View File

@ -25,7 +25,6 @@ License
#include "dictionary.H"
#include "IOobject.H"
#include "inputSyntaxEntry.H"
#include "inputModeEntry.H"
#include "calcIncludeEntry.H"
#include "stringOps.H"
@ -59,9 +58,6 @@ Foam::dictionary::dictionary(Istream& is, const bool keepHeader)
dictionaryName(is.name()),
parent_(dictionary::null)
{
// Reset input syntax as this is a "top-level" dictionary
functionEntries::inputSyntaxEntry::clear();
// Reset input mode as this is a "top-level" dictionary
functionEntries::inputModeEntry::clear();
@ -189,9 +185,6 @@ bool Foam::dictionary::substituteKeyword(const word& keyword)
Foam::Istream& Foam::operator>>(Istream& is, dictionary& dict)
{
// Reset input syntax as this is a "top-level" dictionary
functionEntries::inputSyntaxEntry::clear();
// Reset input mode assuming this is a "top-level" dictionary
functionEntries::inputModeEntry::clear();

View File

@ -25,7 +25,6 @@ License
#include "entry.H"
#include "dictionaryListEntry.H"
#include "inputSyntaxEntry.H"
#include "includeEntry.H"
#include "inputModeEntry.H"
#include "stringOps.H"
@ -153,20 +152,6 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
false
);
if
(
success
&& functionName == functionEntries::inputSyntaxEntry::typeName
)
{
return functionEntry::execute
(
functionName,
parentDict,
parentDict.lookup(keyword)
);
}
return success;
}
else

View File

@ -1,144 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 ? '/' : '.';
}
// ************************************************************************* //

View File

@ -1,148 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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/>.
Class
Foam::functionEntries::inputSyntaxEntry
Description
Specify the dictionary scoping syntax, expects a single word to follow.
An example of \c \#inputSyntax directive:
\verbatim
#inputSyntax dot
\endverbatim
The possible input syntax:
- \par slash use '/' as the scope operator
'../' to go to the parent dictionary
'!' to go to the top-level dictionary
- \par dot use '.' as the scope operator
'..' to go to the parent dictionary
':' to go to the top-level dictionary
The default dictionary syntax is \c slash but can be changed to \c dot in
etc/controlDict
\verbatim
OptimisationSwitches
{
.
.
.
inputSyntax dot;
}
\endverbatim
SourceFiles
inputSyntaxEntry.C
\*---------------------------------------------------------------------------*/
#ifndef inputSyntaxEntry_H
#define inputSyntaxEntry_H
#include "functionEntry.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionEntries
{
/*---------------------------------------------------------------------------*\
Class inputSyntaxEntry Declaration
\*---------------------------------------------------------------------------*/
class inputSyntaxEntry
:
public functionEntry
{
//- The input syntax options
enum inputSyntax
{
SLASH,
DOT
};
//- The default input syntax
static inputSyntax defaultSyntax_;
//- The current input syntax
static inputSyntax syntax_;
// Private Member Functions
//- Read the syntax as a word and return the corresponding enum
static inputSyntax syntax(Istream&);
public:
//- Runtime type information
ClassName("inputSyntax");
// Constructors
//- Disallow default bitwise copy construction
inputSyntaxEntry(const inputSyntaxEntry&) = delete;
// Member Functions
//- Execute the functionEntry in a sub-dict context
static bool execute(dictionary& parentDict, Istream&);
//- Reset the inputSyntax to the default specified in etc/controlDict
// if not specified to %dot
static void clear();
//- Return true if the inputSyntax is %slash
static bool slash();
//- Return true if the inputSyntax is %dot
static bool dot();
//- Return true if the inputSyntax is %slash
static char scopeChar();
// Member Operators
//- Disallow default bitwise assignment
void operator=(const inputSyntaxEntry&) = delete;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionEntries
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -459,10 +459,10 @@ Foam::string& Foam::stringOps::inplaceExpandCodeString
&&
(
isalnum(*iter)
|| *iter == '/' // For dictionary slash syntax
|| *iter == '!' // For dictionary slash syntax
|| *iter == '.' // For dictionary dot syntax
|| *iter == ':' // For dictionary dot syntax
|| *iter == '/'
|| *iter == '!'
|| *iter == '.'
|| *iter == ':'
|| *iter == '_'
)
)
@ -682,10 +682,10 @@ Foam::string& Foam::stringOps::inplaceExpandCodeTemplate
&&
(
isalnum(*iter)
|| *iter == '/' // For dictionary slash syntax
|| *iter == '!' // For dictionary slash syntax
|| *iter == '.' // For dictionary dot syntax
|| *iter == ':' // For dictionary dot syntax
|| *iter == '/'
|| *iter == '!'
|| *iter == '.'
|| *iter == ':'
|| *iter == '_'
)
)
@ -808,10 +808,10 @@ Foam::string& Foam::stringOps::inplaceExpandEntry
&&
(
isalnum(*iter)
|| *iter == '/' // For dictionary slash syntax
|| *iter == '!' // For dictionary slash syntax
|| *iter == '.' // For dictionary dot syntax
|| *iter == ':' // For dictionary dot syntax
|| *iter == '/'
|| *iter == '!'
|| *iter == '.'
|| *iter == ':'
|| *iter == '_'
)
)