mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'feature-objectRegistry' into 'develop'
ENH: improve objectRegistry functionality (issue #322) - Recursive searching for objects within a registry is now optional (previous it was always done). A recursive search effectively blocks the construction of sub-sub-registries if their names are 'masked' by some parent level sub-registry with the same name! (BUG) - Recursive search is now turned OFF by default, which makes it consistent with dictionary and probably causes the least number of surprises. ---- Various new convenience methods added: lookupObjectRef() - returns a non-const reference. For example, volScalarField& U = mesh().lookupObjectRef<volScalarField>("U"); Instead of volScalarField& U = const_cast<volScalarField&> ( mesh().lookupObject<volScalarField>("U") ); -- lookupObjectPtr() - returns a const pointer, and nullptr on failure. For example, const volScalarField* Uptr = mesh().lookupObjectPtr<volScalarField>("U"); if (Uptr) { const volScalarField& U = *Uptr; ... } Instead of if (mesh().foundObject<volScalarField>("U")) { const volScalarField& U = mesh().lookupObject<volScalarField>("U"); ... } -- lookupObjectRefPtr() - returns a non-const pointer, and nullptr on failure. For example, volScalarField* Uptr = mesh().lookupObjectRefPtr<volScalarField>("U"); if (Uptr) { volScalarField& U = *Uptr; // use as reference (*Uptr) = ...; // or use directly } Instead of if (mesh().foundObject<volScalarField>("U")) { volScalarField& U = const_cast<volScalarField&> ( mesh().lookupObject<volScalarField>("U") ); } -- sortedNames() - now works with template parameters and with regular expression matching as well. For example, wordList names = mesh().sortedNames(); wordList fields = mesh().sortedName<volScalarField>(); Instead of wordList names = mesh().sortedNames(); wordList fields = mesh().names<volScalarField>(); Foam::sort(fields); -- See merge request !83
This commit is contained in:
@ -76,9 +76,8 @@ void printRegistry
|
||||
Foam::label indent
|
||||
)
|
||||
{
|
||||
hashedWordList regs = obr.names<objectRegistry>();
|
||||
regs.sort();
|
||||
wordList names = obr.sortedNames();
|
||||
hashedWordList regs = obr.sortedNames<objectRegistry>();
|
||||
|
||||
std::string prefix;
|
||||
for (label i=indent; i; --i)
|
||||
@ -121,7 +120,8 @@ void printRegistry
|
||||
const word& name = regs[i];
|
||||
const objectRegistry& next = obr.lookupObject<objectRegistry>
|
||||
(
|
||||
name
|
||||
name,
|
||||
recursive
|
||||
);
|
||||
|
||||
os << prefix.c_str()
|
||||
@ -158,13 +158,13 @@ int main(int argc, char *argv[])
|
||||
"skip",
|
||||
"skip some parts"
|
||||
);
|
||||
// argList::validArgs.append("recursive (true|false)");
|
||||
argList::validArgs.append("recursive (true|false)");
|
||||
|
||||
#include "setRootCase.H"
|
||||
#include "createTime.H"
|
||||
#include "createPolyMesh.H"
|
||||
|
||||
// recursive = Switch(args[1]);
|
||||
recursive = Switch(args[1]);
|
||||
|
||||
const bool optMesh = args.optionFound("mesh");
|
||||
const bool optSkip = args.optionFound("skip");
|
||||
@ -183,7 +183,8 @@ int main(int argc, char *argv[])
|
||||
db.subRegistry
|
||||
(
|
||||
entryName,
|
||||
true
|
||||
true,
|
||||
recursive
|
||||
);
|
||||
}
|
||||
|
||||
@ -200,7 +201,8 @@ int main(int argc, char *argv[])
|
||||
const objectRegistry& subreg = db.subRegistry
|
||||
(
|
||||
regName,
|
||||
true
|
||||
true,
|
||||
recursive
|
||||
);
|
||||
|
||||
for (label j = 0; j < 3; ++j)
|
||||
@ -210,12 +212,14 @@ int main(int argc, char *argv[])
|
||||
subreg.subRegistry
|
||||
(
|
||||
entryName,
|
||||
true
|
||||
true,
|
||||
recursive
|
||||
);
|
||||
subreg.subRegistry
|
||||
(
|
||||
"$" + entryName, // qualified to avoid collisions
|
||||
true
|
||||
true,
|
||||
recursive
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -231,7 +235,8 @@ int main(int argc, char *argv[])
|
||||
db.subRegistry
|
||||
(
|
||||
entryName,
|
||||
true
|
||||
true,
|
||||
recursive
|
||||
);
|
||||
}
|
||||
|
||||
@ -249,7 +254,8 @@ int main(int argc, char *argv[])
|
||||
const objectRegistry& subreg = db.subRegistry
|
||||
(
|
||||
regName,
|
||||
false
|
||||
false,
|
||||
recursive
|
||||
);
|
||||
|
||||
if (!optSkip)
|
||||
@ -261,7 +267,8 @@ int main(int argc, char *argv[])
|
||||
subreg.subRegistry
|
||||
(
|
||||
entryName,
|
||||
true
|
||||
true,
|
||||
recursive
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user