mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add dictionary method subDictOrAdd (related to #1442)
This commit is contained in:
committed by
Andrew Heather
parent
f1ed0a617b
commit
8a75bdb12f
@ -531,6 +531,46 @@ Foam::dictionary& Foam::dictionary::subDict
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::dictionary& Foam::dictionary::subDictOrAdd
|
||||||
|
(
|
||||||
|
const word& keyword,
|
||||||
|
enum keyType::option matchOpt
|
||||||
|
)
|
||||||
|
{
|
||||||
|
searcher finder(search(keyword, matchOpt));
|
||||||
|
|
||||||
|
dictionary* ptr = finder.dictPtr();
|
||||||
|
|
||||||
|
if (ptr)
|
||||||
|
{
|
||||||
|
// Found and a sub-dictionary
|
||||||
|
return *ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (finder.good())
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction(*this)
|
||||||
|
<< "Entry '" << keyword
|
||||||
|
<< "' is not a sub-dictionary in dictionary "
|
||||||
|
<< name() << nl
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr = this->set(keyword, dictionary())->dictPtr();
|
||||||
|
|
||||||
|
if (!ptr)
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction(*this)
|
||||||
|
<< "Failed to insert sub-dictionary '" << keyword
|
||||||
|
<< "' in dictionary "
|
||||||
|
<< name() << nl
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return *ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::dictionary Foam::dictionary::subOrEmptyDict
|
Foam::dictionary Foam::dictionary::subOrEmptyDict
|
||||||
(
|
(
|
||||||
const word& keyword,
|
const word& keyword,
|
||||||
@ -551,7 +591,7 @@ Foam::dictionary Foam::dictionary::subOrEmptyDict
|
|||||||
FatalIOErrorInFunction(*this)
|
FatalIOErrorInFunction(*this)
|
||||||
<< "Entry '" << keyword
|
<< "Entry '" << keyword
|
||||||
<< "' is not a sub-dictionary in dictionary "
|
<< "' is not a sub-dictionary in dictionary "
|
||||||
<< name()
|
<< name() << nl
|
||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -809,7 +849,7 @@ bool Foam::dictionary::merge(const dictionary& dict)
|
|||||||
{
|
{
|
||||||
FatalIOErrorInFunction(*this)
|
FatalIOErrorInFunction(*this)
|
||||||
<< "Attempted merge to self for dictionary "
|
<< "Attempted merge to self for dictionary "
|
||||||
<< name()
|
<< name() << nl
|
||||||
<< abort(FatalIOError);
|
<< abort(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -878,7 +918,7 @@ void Foam::dictionary::operator=(const dictionary& rhs)
|
|||||||
{
|
{
|
||||||
FatalIOErrorInFunction(*this)
|
FatalIOErrorInFunction(*this)
|
||||||
<< "Attempted assignment to self for dictionary "
|
<< "Attempted assignment to self for dictionary "
|
||||||
<< name()
|
<< name() << nl
|
||||||
<< abort(FatalIOError);
|
<< abort(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -900,8 +940,8 @@ void Foam::dictionary::operator+=(const dictionary& rhs)
|
|||||||
if (this == &rhs)
|
if (this == &rhs)
|
||||||
{
|
{
|
||||||
FatalIOErrorInFunction(*this)
|
FatalIOErrorInFunction(*this)
|
||||||
<< "attempted addition assignment to self for dictionary "
|
<< "Attempted addition assignment to self for dictionary "
|
||||||
<< name()
|
<< name() << nl
|
||||||
<< abort(FatalIOError);
|
<< abort(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -917,8 +957,8 @@ void Foam::dictionary::operator|=(const dictionary& rhs)
|
|||||||
if (this == &rhs)
|
if (this == &rhs)
|
||||||
{
|
{
|
||||||
FatalIOErrorInFunction(*this)
|
FatalIOErrorInFunction(*this)
|
||||||
<< "attempted assignment to self for dictionary "
|
<< "Attempted assignment to self for dictionary "
|
||||||
<< name()
|
<< name() << nl
|
||||||
<< abort(FatalIOError);
|
<< abort(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -937,8 +977,8 @@ void Foam::dictionary::operator<<=(const dictionary& rhs)
|
|||||||
if (this == &rhs)
|
if (this == &rhs)
|
||||||
{
|
{
|
||||||
FatalIOErrorInFunction(*this)
|
FatalIOErrorInFunction(*this)
|
||||||
<< "attempted assignment to self for dictionary "
|
<< "Attempted assignment to self for dictionary "
|
||||||
<< name()
|
<< name() << nl
|
||||||
<< abort(FatalIOError);
|
<< abort(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -749,6 +749,16 @@ public:
|
|||||||
enum keyType::option matchOpt = keyType::REGEX
|
enum keyType::option matchOpt = keyType::REGEX
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Find and return a sub-dictionary for manipulation.
|
||||||
|
// Fatal if the entry exist and is not a sub-dictionary.
|
||||||
|
//
|
||||||
|
// \param matchOpt the default search is non-recursive with patterns
|
||||||
|
dictionary& subDictOrAdd
|
||||||
|
(
|
||||||
|
const word& keyword,
|
||||||
|
enum keyType::option matchOpt = keyType::REGEX
|
||||||
|
);
|
||||||
|
|
||||||
//- Find and return a sub-dictionary as a copy, otherwise return
|
//- Find and return a sub-dictionary as a copy, otherwise return
|
||||||
//- an empty dictionary.
|
//- an empty dictionary.
|
||||||
// Warn if the entry exists but is not a sub-dictionary.
|
// Warn if the entry exists but is not a sub-dictionary.
|
||||||
|
|||||||
Reference in New Issue
Block a user