Commit 0bada1e3 authored by Mark Olesen's avatar Mark Olesen
Browse files

dictionary cosmetics

- partial revert for commit d21869b5
  * only add extra newlines for a top-level dictionary that is output as such

- make "#inputMode merge" the default instead of "#inputMode error"
  * this corresponds to a very common usage case
parent 36613fa5
......@@ -117,12 +117,7 @@ Foam::dictionary::dictionary
name_(dict.name()),
parent_(parentDict)
{
for
(
IDLList<entry>::iterator iter = begin();
iter != end();
++iter
)
forAllIter(IDLList<entry>, *this, iter)
{
hashedEntries_.insert(iter().keyword(), &iter());
......@@ -147,12 +142,7 @@ Foam::dictionary::dictionary
name_(dict.name()),
parent_(dictionary::null)
{
for
(
IDLList<entry>::iterator iter = begin();
iter != end();
++iter
)
forAllIter(IDLList<entry>, *this, iter)
{
hashedEntries_.insert(iter().keyword(), &iter());
......@@ -238,12 +228,7 @@ Foam::SHA1Digest Foam::dictionary::digest() const
OSHA1stream os;
// process entries
for
(
IDLList<entry>::const_iterator iter = begin();
iter != end();
++iter
)
forAllConstIter(IDLList<entry>, *this, iter)
{
os << *iter;
}
......@@ -262,7 +247,8 @@ bool Foam::dictionary::found(const word& keyword, bool recursive) const
{
if (patternEntries_.size())
{
DLList<entry*>::const_iterator wcLink = patternEntries_.begin();
DLList<entry*>::const_iterator wcLink =
patternEntries_.begin();
DLList<autoPtr<regExp> >::const_iterator reLink =
patternRegexps_.begin();
......@@ -475,12 +461,7 @@ Foam::wordList Foam::dictionary::toc() const
wordList keys(size());
label nKeys = 0;
for
(
IDLList<entry>::const_iterator iter = begin();
iter != end();
++iter
)
forAllConstIter(IDLList<entry>::const_iterator, *this, iter)
{
keys[nKeys++] = iter().keyword();
}
......@@ -494,12 +475,7 @@ Foam::List<Foam::keyType> Foam::dictionary::keys(bool patterns) const
List<keyType> keys(size());
label nKeys = 0;
for
(
IDLList<entry>::const_iterator iter = begin();
iter != end();
++iter
)
forAllConstIter(IDLList<entry>, *this, iter)
{
if (iter().keyword().isPattern() ? patterns : !patterns)
{
......@@ -665,8 +641,10 @@ bool Foam::dictionary::remove(const word& Keyword)
if (iter != hashedEntries_.end())
{
// Delete from patterns first
DLList<entry*>::iterator wcLink = patternEntries_.begin();
DLList<autoPtr<regExp> >::iterator reLink = patternRegexps_.begin();
DLList<entry*>::iterator wcLink =
patternEntries_.begin();
DLList<autoPtr<regExp> >::iterator reLink =
patternRegexps_.begin();
// Find in pattern using exact match only
if (findInPatterns(false, Keyword, wcLink, reLink))
......@@ -792,12 +770,7 @@ bool Foam::dictionary::merge(const dictionary& dict)
bool changed = false;
for
(
IDLList<entry>::const_iterator iter = dict.begin();
iter != dict.end();
++iter
)
forAllConstIter(IDLList<entry>, *this, iter)
{
HashTable<entry*>::iterator fnd = hashedEntries_.find(iter().keyword());
......@@ -882,12 +855,7 @@ void Foam::dictionary::operator=(const dictionary& rhs)
// Create clones of the entries in the given dictionary
// resetting the parentDict to this dictionary
for
(
IDLList<entry>::const_iterator iter = rhs.begin();
iter != rhs.end();
++iter
)
forAllConstIter(IDLList<entry>, rhs, iter)
{
add(iter().clone(*this).ptr());
}
......@@ -904,12 +872,7 @@ void Foam::dictionary::operator+=(const dictionary& rhs)
<< abort(FatalError);
}
for
(
IDLList<entry>::const_iterator iter = rhs.begin();
iter != rhs.end();
++iter
)
forAllConstIter(IDLList<entry>, rhs, iter)
{
add(iter().clone(*this).ptr());
}
......@@ -926,12 +889,7 @@ void Foam::dictionary::operator|=(const dictionary& rhs)
<< abort(FatalError);
}
for
(
IDLList<entry>::const_iterator iter = rhs.begin();
iter != rhs.end();
++iter
)
forAllConstIter(IDLList<entry>, rhs, iter)
{
if (!found(iter().keyword()))
{
......@@ -951,12 +909,7 @@ void Foam::dictionary::operator<<=(const dictionary& rhs)
<< abort(FatalError);
}
for
(
IDLList<entry>::const_iterator iter = rhs.begin();
iter != rhs.end();
++iter
)
forAllConstIter(IDLList<entry>, rhs, iter)
{
set(iter().clone(*this).ptr());
}
......
......@@ -154,12 +154,8 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const
// Write entry
os << e;
// Add new line if applicable
if
(
(e.isDict() || (!e.isDict() && parent()==dictionary::null))
&& e != *last()
)
// Add extra new line between entries for "top-level" dictionaries
if (!subDict && parent() == dictionary::null && e != *last())
{
os << nl;
}
......@@ -167,7 +163,7 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const
// Check stream before going to next entry.
if (!os.good())
{
WarningIn("dictionary::write(Ostream& os, bool subDict)")
WarningIn("dictionary::write(Ostream&, bool subDict)")
<< "Can't write entry " << iter().keyword()
<< " for dictionary " << name()
<< endl;
......
......@@ -103,14 +103,13 @@ bool Foam::functionEntry::execute
is.fatalCheck
(
"functionEntry::execute"
"(const word& functionName, const dictionary& parentDict, "
"primitiveEntry&, Istream&)"
"(const word&, const dictionary&, primitiveEntry&, Istream&)"
);
if (!executeprimitiveEntryIstreamMemberFunctionTablePtr_)
{
cerr<<"functionEntry::execute"
<< "(const word&, dictionary&, primitiveEntry&, Istream&)"
<< "(const word&, const dictionary&, primitiveEntry&, Istream&)"
<< " not yet initialized, function = "
<< functionName.c_str() << std::endl;
......@@ -126,8 +125,7 @@ bool Foam::functionEntry::execute
FatalErrorIn
(
"functionEntry::execute"
"(const word& functionName, const dictionary& parentDict, "
"primitiveEntry&, Istream&)"
"(const word&, const dictionary&, primitiveEntry&, Istream&)"
) << "Unknown functionEntry " << functionName
<< endl << endl
<< "Valid functionEntries are :" << endl
......
......@@ -95,7 +95,7 @@ public:
(
const word& functionName,
dictionary& parentDict,
Istream& is
Istream&
);
declareMemberFunctionSelectionTable
......@@ -117,8 +117,8 @@ public:
(
const word& functionName,
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
primitiveEntry&,
Istream&
);
......
......@@ -62,8 +62,7 @@ namespace functionEntries
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::fileName Foam::functionEntries::includeEntry::includeFileName
(
......@@ -73,6 +72,7 @@ Foam::fileName Foam::functionEntries::includeEntry::includeFileName
fileName fName(is);
fName.expand();
// relative name
if (fName.size() && fName[0] != '/')
{
fName = fileName(is.name()).path()/fName;
......@@ -82,17 +82,19 @@ Foam::fileName Foam::functionEntries::includeEntry::includeFileName
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionEntries::includeEntry::execute
(
dictionary& parentDict,
Istream& is
)
{
IFstream fileStream(includeFileName(is));
IFstream ifs(includeFileName(is));
if (fileStream)
if (ifs)
{
parentDict.read(fileStream);
parentDict.read(ifs);
return true;
}
else
......@@ -100,9 +102,9 @@ bool Foam::functionEntries::includeEntry::execute
FatalIOErrorIn
(
"functionEntries::includeEntry::includeEntry"
"(dictionary& parentDict,Istream& is)",
"(dictionary& parentDict, Istream&)",
is
) << "Cannot open include file " << fileStream.name()
) << "Cannot open include file " << ifs.name()
<< " while reading dictionary " << parentDict.name()
<< exit(FatalIOError);
......@@ -117,11 +119,11 @@ bool Foam::functionEntries::includeEntry::execute
Istream& is
)
{
IFstream fileStream(includeFileName(is));
IFstream ifs(includeFileName(is));
if (fileStream)
if (ifs)
{
entry.read(parentDict, fileStream);
entry.read(parentDict, ifs);
return true;
}
else
......@@ -129,9 +131,9 @@ bool Foam::functionEntries::includeEntry::execute
FatalIOErrorIn
(
"functionEntries::includeEntry::includeEntry"
"(dictionary& parentDict, primitiveEntry& entry, Istream& is)",
"(dictionary& parentDict, primitiveEntry& entry, Istream&)",
is
) << "Cannot open include file " << fileStream.name()
) << "Cannot open include file " << ifs.name()
<< " while reading dictionary " << parentDict.name()
<< exit(FatalIOError);
......
......@@ -58,7 +58,7 @@ namespace functionEntries
{
/*---------------------------------------------------------------------------*\
Class includeEntry Declaration
Class includeEntry Declaration
\*---------------------------------------------------------------------------*/
class includeEntry
......@@ -68,7 +68,7 @@ class includeEntry
// Private Member Functions
//- Read the include fileName from Istream, expand and return
static fileName includeFileName(Istream& is);
static fileName includeFileName(Istream&);
//- Disallow default bitwise copy construct
includeEntry(const includeEntry&);
......@@ -86,18 +86,14 @@ public:
// Member Functions
//- Execute the functionEntry in a sub-dict context
static bool execute
(
dictionary& parentDict,
Istream& is
);
static bool execute(dictionary& parentDict, Istream&);
//- Execute the functionEntry in a primitiveEntry context
static bool execute
(
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
primitiveEntry&,
Istream&
);
};
......
......@@ -39,6 +39,9 @@ const Foam::word Foam::functionEntries::inputModeEntry::typeName
// might include inputModeEntries
int Foam::functionEntries::inputModeEntry::debug(0);
Foam::functionEntries::inputModeEntry::inputMode
Foam::functionEntries::inputModeEntry::mode_(MERGE);
namespace Foam
{
namespace functionEntries
......@@ -53,10 +56,6 @@ namespace functionEntries
}
}
// * * * * * * * * * * * * * * * * Private Data * * * * * * * * * * * * * * //
Foam::label Foam::functionEntries::inputModeEntry::mode_ = imError;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// we could combine this into execute() directly, but leave it here for now
......@@ -65,17 +64,17 @@ void Foam::functionEntries::inputModeEntry::setMode(Istream& is)
clear();
word mode(is);
if (mode == "merge")
if (mode == "merge" || mode == "default")
{
mode_ = imMerge;
mode_ = MERGE;
}
else if (mode == "overwrite")
{
mode_ = imOverwrite;
mode_ = OVERWRITE;
}
else if (mode == "error" || mode == "default")
else if (mode == "error")
{
mode_ = imError;
mode_ = ERROR;
}
else
{
......@@ -101,33 +100,19 @@ bool Foam::functionEntries::inputModeEntry::execute
void Foam::functionEntries::inputModeEntry::clear()
{
mode_ = imError;
mode_ = MERGE;
}
bool Foam::functionEntries::inputModeEntry::merge()
{
if (mode_ & imMerge)
{
return true;
}
else
{
return false;
}
return mode_ == MERGE;
}
bool Foam::functionEntries::inputModeEntry::overwrite()
{
if (mode_ & imOverwrite)
{
return true;
}
else
{
return false;
}
return mode_ == OVERWRITE;
}
......
......@@ -38,7 +38,7 @@ Description
@param merge merge sub-dictionaries when possible
@param overwrite keep last entry and silently remove previous ones
@param error flag duplicate entry as an error
@param default currently the same as error
@param default currently the same as merge
SourceFiles
inputModeEntry.C
......@@ -68,13 +68,13 @@ class inputModeEntry
//- input mode options
enum inputMode
{
imError = 0,
imMerge = 0x1,
imOverwrite = 0x2
ERROR,
MERGE,
OVERWRITE
};
//- current input mode
static label mode_;
static inputMode mode_;
// Private Member Functions
......@@ -98,19 +98,15 @@ public:
// Member Functions
//- Execute the functionEntry in a sub-dict context
static bool execute
(
dictionary& parentDict,
Istream&
);
static bool execute(dictionary& parentDict, Istream&);
//- Reset the inputMode to 'default'
//- Reset the inputMode to %default
static void clear();
//- Return true if the inputMode is 'merge'
//- Return true if the inputMode is %merge
static bool merge();
//- Return true if the inputMode is 'overwrite'
//- Return true if the inputMode is %overwrite
static bool overwrite();
};
......
......@@ -80,11 +80,7 @@ public:
// Member Functions
//- Execute the functionEntry in a sub-dict context
static bool execute
(
dictionary& parentDict,
Istream& is
);
static bool execute(dictionary& parentDict, Istream&);
};
......
......@@ -162,10 +162,7 @@ bool Foam::solution::read()
relaxationFactors_ = dict.subDict("relaxationFactors");
}
if (relaxationFactors_.found("default"))
{
relaxationFactors_.lookup("default") >> defaultRelaxationFactor_;
}
relaxationFactors_.readIfPresent("default", defaultRelaxationFactor_);
if (dict.found("solvers"))
{
......@@ -227,7 +224,7 @@ Foam::scalar Foam::solution::relaxationFactor(const word& name) const
{
FatalIOErrorIn
(
"Foam::solution::relaxationFactor(const word& name)",
"Foam::solution::relaxationFactor(const word&)",
relaxationFactors_
) << "Cannot find relaxationFactor for '" << name
<< "' or a suitable default value."
......@@ -242,7 +239,7 @@ const Foam::dictionary& Foam::solution::solverDict(const word& name) const
{
if (debug)
{
InfoIn("solution::solverDict(const word& name)")
InfoIn("solution::solverDict(const word&)")
<< "Lookup solver for " << name << endl;
}
......@@ -254,7 +251,7 @@ const Foam::dictionary& Foam::solution::solver(const word& name) const
{
if (debug)
{
InfoIn("solution::solver(const word& name)")
InfoIn("solution::solver(const word&)")
<< "Lookup solver for " << name << endl;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment