dictionary cosmetics

- partial revert for commit d21869b580
  * 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
This commit is contained in:
Mark Olesen
2009-03-18 13:15:17 +01:00
parent 36613fa5af
commit 0bada1e31b
10 changed files with 69 additions and 150 deletions

View File

@ -117,12 +117,7 @@ Foam::dictionary::dictionary
name_(dict.name()), name_(dict.name()),
parent_(parentDict) parent_(parentDict)
{ {
for forAllIter(IDLList<entry>, *this, iter)
(
IDLList<entry>::iterator iter = begin();
iter != end();
++iter
)
{ {
hashedEntries_.insert(iter().keyword(), &iter()); hashedEntries_.insert(iter().keyword(), &iter());
@ -147,12 +142,7 @@ Foam::dictionary::dictionary
name_(dict.name()), name_(dict.name()),
parent_(dictionary::null) parent_(dictionary::null)
{ {
for forAllIter(IDLList<entry>, *this, iter)
(
IDLList<entry>::iterator iter = begin();
iter != end();
++iter
)
{ {
hashedEntries_.insert(iter().keyword(), &iter()); hashedEntries_.insert(iter().keyword(), &iter());
@ -238,12 +228,7 @@ Foam::SHA1Digest Foam::dictionary::digest() const
OSHA1stream os; OSHA1stream os;
// process entries // process entries
for forAllConstIter(IDLList<entry>, *this, iter)
(
IDLList<entry>::const_iterator iter = begin();
iter != end();
++iter
)
{ {
os << *iter; os << *iter;
} }
@ -262,7 +247,8 @@ bool Foam::dictionary::found(const word& keyword, bool recursive) const
{ {
if (patternEntries_.size()) if (patternEntries_.size())
{ {
DLList<entry*>::const_iterator wcLink = patternEntries_.begin(); DLList<entry*>::const_iterator wcLink =
patternEntries_.begin();
DLList<autoPtr<regExp> >::const_iterator reLink = DLList<autoPtr<regExp> >::const_iterator reLink =
patternRegexps_.begin(); patternRegexps_.begin();
@ -475,12 +461,7 @@ Foam::wordList Foam::dictionary::toc() const
wordList keys(size()); wordList keys(size());
label nKeys = 0; label nKeys = 0;
for forAllConstIter(IDLList<entry>::const_iterator, *this, iter)
(
IDLList<entry>::const_iterator iter = begin();
iter != end();
++iter
)
{ {
keys[nKeys++] = iter().keyword(); keys[nKeys++] = iter().keyword();
} }
@ -494,12 +475,7 @@ Foam::List<Foam::keyType> Foam::dictionary::keys(bool patterns) const
List<keyType> keys(size()); List<keyType> keys(size());
label nKeys = 0; label nKeys = 0;
for forAllConstIter(IDLList<entry>, *this, iter)
(
IDLList<entry>::const_iterator iter = begin();
iter != end();
++iter
)
{ {
if (iter().keyword().isPattern() ? patterns : !patterns) if (iter().keyword().isPattern() ? patterns : !patterns)
{ {
@ -665,8 +641,10 @@ bool Foam::dictionary::remove(const word& Keyword)
if (iter != hashedEntries_.end()) if (iter != hashedEntries_.end())
{ {
// Delete from patterns first // Delete from patterns first
DLList<entry*>::iterator wcLink = patternEntries_.begin(); DLList<entry*>::iterator wcLink =
DLList<autoPtr<regExp> >::iterator reLink = patternRegexps_.begin(); patternEntries_.begin();
DLList<autoPtr<regExp> >::iterator reLink =
patternRegexps_.begin();
// Find in pattern using exact match only // Find in pattern using exact match only
if (findInPatterns(false, Keyword, wcLink, reLink)) if (findInPatterns(false, Keyword, wcLink, reLink))
@ -792,12 +770,7 @@ bool Foam::dictionary::merge(const dictionary& dict)
bool changed = false; bool changed = false;
for forAllConstIter(IDLList<entry>, *this, iter)
(
IDLList<entry>::const_iterator iter = dict.begin();
iter != dict.end();
++iter
)
{ {
HashTable<entry*>::iterator fnd = hashedEntries_.find(iter().keyword()); 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 // Create clones of the entries in the given dictionary
// resetting the parentDict to this dictionary // resetting the parentDict to this dictionary
for forAllConstIter(IDLList<entry>, rhs, iter)
(
IDLList<entry>::const_iterator iter = rhs.begin();
iter != rhs.end();
++iter
)
{ {
add(iter().clone(*this).ptr()); add(iter().clone(*this).ptr());
} }
@ -904,12 +872,7 @@ void Foam::dictionary::operator+=(const dictionary& rhs)
<< abort(FatalError); << abort(FatalError);
} }
for forAllConstIter(IDLList<entry>, rhs, iter)
(
IDLList<entry>::const_iterator iter = rhs.begin();
iter != rhs.end();
++iter
)
{ {
add(iter().clone(*this).ptr()); add(iter().clone(*this).ptr());
} }
@ -926,12 +889,7 @@ void Foam::dictionary::operator|=(const dictionary& rhs)
<< abort(FatalError); << abort(FatalError);
} }
for forAllConstIter(IDLList<entry>, rhs, iter)
(
IDLList<entry>::const_iterator iter = rhs.begin();
iter != rhs.end();
++iter
)
{ {
if (!found(iter().keyword())) if (!found(iter().keyword()))
{ {
@ -951,12 +909,7 @@ void Foam::dictionary::operator<<=(const dictionary& rhs)
<< abort(FatalError); << abort(FatalError);
} }
for forAllConstIter(IDLList<entry>, rhs, iter)
(
IDLList<entry>::const_iterator iter = rhs.begin();
iter != rhs.end();
++iter
)
{ {
set(iter().clone(*this).ptr()); set(iter().clone(*this).ptr());
} }

View File

@ -154,12 +154,8 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const
// Write entry // Write entry
os << e; os << e;
// Add new line if applicable // Add extra new line between entries for "top-level" dictionaries
if if (!subDict && parent() == dictionary::null && e != *last())
(
(e.isDict() || (!e.isDict() && parent()==dictionary::null))
&& e != *last()
)
{ {
os << nl; os << nl;
} }
@ -167,7 +163,7 @@ void Foam::dictionary::write(Ostream& os, bool subDict) const
// Check stream before going to next entry. // Check stream before going to next entry.
if (!os.good()) if (!os.good())
{ {
WarningIn("dictionary::write(Ostream& os, bool subDict)") WarningIn("dictionary::write(Ostream&, bool subDict)")
<< "Can't write entry " << iter().keyword() << "Can't write entry " << iter().keyword()
<< " for dictionary " << name() << " for dictionary " << name()
<< endl; << endl;

View File

@ -103,14 +103,13 @@ bool Foam::functionEntry::execute
is.fatalCheck is.fatalCheck
( (
"functionEntry::execute" "functionEntry::execute"
"(const word& functionName, const dictionary& parentDict, " "(const word&, const dictionary&, primitiveEntry&, Istream&)"
"primitiveEntry&, Istream&)"
); );
if (!executeprimitiveEntryIstreamMemberFunctionTablePtr_) if (!executeprimitiveEntryIstreamMemberFunctionTablePtr_)
{ {
cerr<<"functionEntry::execute" cerr<<"functionEntry::execute"
<< "(const word&, dictionary&, primitiveEntry&, Istream&)" << "(const word&, const dictionary&, primitiveEntry&, Istream&)"
<< " not yet initialized, function = " << " not yet initialized, function = "
<< functionName.c_str() << std::endl; << functionName.c_str() << std::endl;
@ -126,8 +125,7 @@ bool Foam::functionEntry::execute
FatalErrorIn FatalErrorIn
( (
"functionEntry::execute" "functionEntry::execute"
"(const word& functionName, const dictionary& parentDict, " "(const word&, const dictionary&, primitiveEntry&, Istream&)"
"primitiveEntry&, Istream&)"
) << "Unknown functionEntry " << functionName ) << "Unknown functionEntry " << functionName
<< endl << endl << endl << endl
<< "Valid functionEntries are :" << endl << "Valid functionEntries are :" << endl

View File

@ -95,7 +95,7 @@ public:
( (
const word& functionName, const word& functionName,
dictionary& parentDict, dictionary& parentDict,
Istream& is Istream&
); );
declareMemberFunctionSelectionTable declareMemberFunctionSelectionTable
@ -117,8 +117,8 @@ public:
( (
const word& functionName, const word& functionName,
const dictionary& parentDict, const dictionary& parentDict,
primitiveEntry& entry, primitiveEntry&,
Istream& is Istream&
); );

View File

@ -62,8 +62,7 @@ namespace functionEntries
} }
} }
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::fileName Foam::functionEntries::includeEntry::includeFileName Foam::fileName Foam::functionEntries::includeEntry::includeFileName
( (
@ -73,6 +72,7 @@ Foam::fileName Foam::functionEntries::includeEntry::includeFileName
fileName fName(is); fileName fName(is);
fName.expand(); fName.expand();
// relative name
if (fName.size() && fName[0] != '/') if (fName.size() && fName[0] != '/')
{ {
fName = fileName(is.name()).path()/fName; fName = fileName(is.name()).path()/fName;
@ -82,17 +82,19 @@ Foam::fileName Foam::functionEntries::includeEntry::includeFileName
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionEntries::includeEntry::execute bool Foam::functionEntries::includeEntry::execute
( (
dictionary& parentDict, dictionary& parentDict,
Istream& is Istream& is
) )
{ {
IFstream fileStream(includeFileName(is)); IFstream ifs(includeFileName(is));
if (fileStream) if (ifs)
{ {
parentDict.read(fileStream); parentDict.read(ifs);
return true; return true;
} }
else else
@ -100,9 +102,9 @@ bool Foam::functionEntries::includeEntry::execute
FatalIOErrorIn FatalIOErrorIn
( (
"functionEntries::includeEntry::includeEntry" "functionEntries::includeEntry::includeEntry"
"(dictionary& parentDict,Istream& is)", "(dictionary& parentDict, Istream&)",
is is
) << "Cannot open include file " << fileStream.name() ) << "Cannot open include file " << ifs.name()
<< " while reading dictionary " << parentDict.name() << " while reading dictionary " << parentDict.name()
<< exit(FatalIOError); << exit(FatalIOError);
@ -117,11 +119,11 @@ bool Foam::functionEntries::includeEntry::execute
Istream& is Istream& is
) )
{ {
IFstream fileStream(includeFileName(is)); IFstream ifs(includeFileName(is));
if (fileStream) if (ifs)
{ {
entry.read(parentDict, fileStream); entry.read(parentDict, ifs);
return true; return true;
} }
else else
@ -129,9 +131,9 @@ bool Foam::functionEntries::includeEntry::execute
FatalIOErrorIn FatalIOErrorIn
( (
"functionEntries::includeEntry::includeEntry" "functionEntries::includeEntry::includeEntry"
"(dictionary& parentDict, primitiveEntry& entry, Istream& is)", "(dictionary& parentDict, primitiveEntry& entry, Istream&)",
is is
) << "Cannot open include file " << fileStream.name() ) << "Cannot open include file " << ifs.name()
<< " while reading dictionary " << parentDict.name() << " while reading dictionary " << parentDict.name()
<< exit(FatalIOError); << exit(FatalIOError);

View File

@ -58,7 +58,7 @@ namespace functionEntries
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class includeEntry Declaration Class includeEntry Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class includeEntry class includeEntry
@ -68,7 +68,7 @@ class includeEntry
// Private Member Functions // Private Member Functions
//- Read the include fileName from Istream, expand and return //- Read the include fileName from Istream, expand and return
static fileName includeFileName(Istream& is); static fileName includeFileName(Istream&);
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
includeEntry(const includeEntry&); includeEntry(const includeEntry&);
@ -86,18 +86,14 @@ public:
// Member Functions // Member Functions
//- Execute the functionEntry in a sub-dict context //- Execute the functionEntry in a sub-dict context
static bool execute static bool execute(dictionary& parentDict, Istream&);
(
dictionary& parentDict,
Istream& is
);
//- Execute the functionEntry in a primitiveEntry context //- Execute the functionEntry in a primitiveEntry context
static bool execute static bool execute
( (
const dictionary& parentDict, const dictionary& parentDict,
primitiveEntry& entry, primitiveEntry&,
Istream& is Istream&
); );
}; };

View File

@ -39,6 +39,9 @@ const Foam::word Foam::functionEntries::inputModeEntry::typeName
// might include inputModeEntries // might include inputModeEntries
int Foam::functionEntries::inputModeEntry::debug(0); int Foam::functionEntries::inputModeEntry::debug(0);
Foam::functionEntries::inputModeEntry::inputMode
Foam::functionEntries::inputModeEntry::mode_(MERGE);
namespace Foam namespace Foam
{ {
namespace functionEntries namespace functionEntries
@ -53,10 +56,6 @@ namespace functionEntries
} }
} }
// * * * * * * * * * * * * * * * * Private Data * * * * * * * * * * * * * * //
Foam::label Foam::functionEntries::inputModeEntry::mode_ = imError;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// we could combine this into execute() directly, but leave it here for now // 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(); clear();
word mode(is); word mode(is);
if (mode == "merge") if (mode == "merge" || mode == "default")
{ {
mode_ = imMerge; mode_ = MERGE;
} }
else if (mode == "overwrite") else if (mode == "overwrite")
{ {
mode_ = imOverwrite; mode_ = OVERWRITE;
} }
else if (mode == "error" || mode == "default") else if (mode == "error")
{ {
mode_ = imError; mode_ = ERROR;
} }
else else
{ {
@ -101,33 +100,19 @@ bool Foam::functionEntries::inputModeEntry::execute
void Foam::functionEntries::inputModeEntry::clear() void Foam::functionEntries::inputModeEntry::clear()
{ {
mode_ = imError; mode_ = MERGE;
} }
bool Foam::functionEntries::inputModeEntry::merge() bool Foam::functionEntries::inputModeEntry::merge()
{ {
if (mode_ & imMerge) return mode_ == MERGE;
{
return true;
}
else
{
return false;
}
} }
bool Foam::functionEntries::inputModeEntry::overwrite() bool Foam::functionEntries::inputModeEntry::overwrite()
{ {
if (mode_ & imOverwrite) return mode_ == OVERWRITE;
{
return true;
}
else
{
return false;
}
} }

View File

@ -38,7 +38,7 @@ Description
@param merge merge sub-dictionaries when possible @param merge merge sub-dictionaries when possible
@param overwrite keep last entry and silently remove previous ones @param overwrite keep last entry and silently remove previous ones
@param error flag duplicate entry as an error @param error flag duplicate entry as an error
@param default currently the same as error @param default currently the same as merge
SourceFiles SourceFiles
inputModeEntry.C inputModeEntry.C
@ -68,13 +68,13 @@ class inputModeEntry
//- input mode options //- input mode options
enum inputMode enum inputMode
{ {
imError = 0, ERROR,
imMerge = 0x1, MERGE,
imOverwrite = 0x2 OVERWRITE
}; };
//- current input mode //- current input mode
static label mode_; static inputMode mode_;
// Private Member Functions // Private Member Functions
@ -98,19 +98,15 @@ public:
// Member Functions // Member Functions
//- Execute the functionEntry in a sub-dict context //- Execute the functionEntry in a sub-dict context
static bool execute static bool execute(dictionary& parentDict, Istream&);
(
dictionary& parentDict,
Istream&
);
//- Reset the inputMode to 'default' //- Reset the inputMode to %default
static void clear(); static void clear();
//- Return true if the inputMode is 'merge' //- Return true if the inputMode is %merge
static bool merge(); static bool merge();
//- Return true if the inputMode is 'overwrite' //- Return true if the inputMode is %overwrite
static bool overwrite(); static bool overwrite();
}; };

View File

@ -80,11 +80,7 @@ public:
// Member Functions // Member Functions
//- Execute the functionEntry in a sub-dict context //- Execute the functionEntry in a sub-dict context
static bool execute static bool execute(dictionary& parentDict, Istream&);
(
dictionary& parentDict,
Istream& is
);
}; };

View File

@ -162,10 +162,7 @@ bool Foam::solution::read()
relaxationFactors_ = dict.subDict("relaxationFactors"); relaxationFactors_ = dict.subDict("relaxationFactors");
} }
if (relaxationFactors_.found("default")) relaxationFactors_.readIfPresent("default", defaultRelaxationFactor_);
{
relaxationFactors_.lookup("default") >> defaultRelaxationFactor_;
}
if (dict.found("solvers")) if (dict.found("solvers"))
{ {
@ -227,7 +224,7 @@ Foam::scalar Foam::solution::relaxationFactor(const word& name) const
{ {
FatalIOErrorIn FatalIOErrorIn
( (
"Foam::solution::relaxationFactor(const word& name)", "Foam::solution::relaxationFactor(const word&)",
relaxationFactors_ relaxationFactors_
) << "Cannot find relaxationFactor for '" << name ) << "Cannot find relaxationFactor for '" << name
<< "' or a suitable default value." << "' or a suitable default value."
@ -242,7 +239,7 @@ const Foam::dictionary& Foam::solution::solverDict(const word& name) const
{ {
if (debug) if (debug)
{ {
InfoIn("solution::solverDict(const word& name)") InfoIn("solution::solverDict(const word&)")
<< "Lookup solver for " << name << endl; << "Lookup solver for " << name << endl;
} }
@ -254,7 +251,7 @@ const Foam::dictionary& Foam::solution::solver(const word& name) const
{ {
if (debug) if (debug)
{ {
InfoIn("solution::solver(const word& name)") InfoIn("solution::solver(const word&)")
<< "Lookup solver for " << name << endl; << "Lookup solver for " << name << endl;
} }