diff --git a/applications/test/DirLister/DirLister.H b/applications/test/DirLister/DirLister.H index 77db93ad3b..9e76206b51 100644 --- a/applications/test/DirLister/DirLister.H +++ b/applications/test/DirLister/DirLister.H @@ -85,7 +85,7 @@ Description fileNameList procDirs ( - DirLister::dirs(".").sorted(matchProcs) + DirLister::dirs(".").csorted(matchProcs) ); } \endcode @@ -206,11 +206,11 @@ public: //- Return a complete list of names, sorted in natural order template - List sorted() const; + List csorted() const; //- Return complete list of names, sorted in natural order template - List sorted + List csorted ( const UnaryPredicate& pred, const bool prune = false diff --git a/applications/test/DirLister/DirListerTemplates.C b/applications/test/DirLister/DirListerTemplates.C index 5fb079ca6e..7de1216c63 100644 --- a/applications/test/DirLister/DirListerTemplates.C +++ b/applications/test/DirLister/DirListerTemplates.C @@ -70,23 +70,23 @@ Foam::List Foam::DirLister::list() const template -Foam::List Foam::DirLister::sorted +Foam::List Foam::DirLister::csorted ( const UnaryPredicate& pred, const bool prune ) const { - List lst(list(pred, prune)); - sort(lst, stringOps::natural_sort()); + List list(list(pred, prune)); + Foam::sort(list, stringOps::natural_sort()); - return lst; + return list; } template -Foam::List Foam::DirLister::sorted() const +Foam::List Foam::DirLister::csorted() const { - return sorted(predicates::always()); + return csorted(predicates::always()); } diff --git a/applications/test/DirLister/Test-DirLister.C b/applications/test/DirLister/Test-DirLister.C index af0e76bc9d..49a14336a2 100644 --- a/applications/test/DirLister/Test-DirLister.C +++ b/applications/test/DirLister/Test-DirLister.C @@ -162,7 +162,7 @@ int main(int argc, char *argv[]) Info<< "dirList: " << flatOutput ( - DirLister::dirs(".").sorted(relist) + DirLister::dirs(".").csorted(relist) ) << nl; } diff --git a/applications/test/HashTable1/Test-HashTable1.C b/applications/test/HashTable1/Test-HashTable1.C index 75e4eeda2d..1f116d0986 100644 --- a/applications/test/HashTable1/Test-HashTable1.C +++ b/applications/test/HashTable1/Test-HashTable1.C @@ -75,8 +75,8 @@ int main() } - Info<< "\ntable1 sorted() :" << endl; - for (const auto& iter : table1.sorted()) + Info<< "\ntable1 csorted() :" << endl; + for (const auto& iter : table1.csorted()) { Info<< " " << iter.key() << " => " << iter.val() << nl; } @@ -100,7 +100,7 @@ int main() } Info<< "\nInplace modified - via sorted() access :" << endl; - for (const auto& iter : table1.sorted()) + for (const auto& iter : table1.csorted()) { Info<< " " << iter.key() << " => " << iter.val() << nl; } diff --git a/applications/test/IOobjectList/Test-IOobjectList.C b/applications/test/IOobjectList/Test-IOobjectList.C index 5a74e1adfd..c5546650a0 100644 --- a/applications/test/IOobjectList/Test-IOobjectList.C +++ b/applications/test/IOobjectList/Test-IOobjectList.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -290,14 +290,14 @@ int main(int argc, char *argv[]) Info<< "Time: " << runTime.timeName() << nl; report(objects); - report(objects.sorted()); + report(objects.csorted()); - report(objects.sorted()); - report(objects.sorted()); + report(objects.csorted()); + report(objects.csorted()); // Extra checks - report(objects.sorted()); - report(objects.sorted()); + report(objects.csorted()); + report(objects.csorted()); findObjectTest(objects); diff --git a/applications/test/foamToEnsight-check/foamToEnsight-check.C b/applications/test/foamToEnsight-check/foamToEnsight-check.C index 18b0dbb131..4885972a81 100644 --- a/applications/test/foamToEnsight-check/foamToEnsight-check.C +++ b/applications/test/foamToEnsight-check/foamToEnsight-check.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022 OpenCFD Ltd. + Copyright (C) 2022-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -139,7 +139,7 @@ void printInfo(const ensightMesh& mesh, int verbose = 0) FixedList cellStats(Zero); FixedList faceStats(Zero); - for (const auto& iter : mesh.cellZoneParts().sorted()) + for (const auto& iter : mesh.cellZoneParts().csorted()) { FixedList stats = printPartInfo(iter.val(), verbose); @@ -149,7 +149,7 @@ void printInfo(const ensightMesh& mesh, int verbose = 0) } } - for (const auto& iter : mesh.faceZoneParts().sorted()) + for (const auto& iter : mesh.faceZoneParts().csorted()) { FixedList stats = printPartInfo(iter.val(), verbose); @@ -159,7 +159,7 @@ void printInfo(const ensightMesh& mesh, int verbose = 0) } } - for (const auto& iter : mesh.boundaryParts().sorted()) + for (const auto& iter : mesh.boundaryParts().csorted()) { FixedList stats = printPartInfo(iter.val(), verbose); diff --git a/applications/test/gravityMeshObject/Test-gravityMeshObject.C b/applications/test/gravityMeshObject/Test-gravityMeshObject.C index bee9e70120..f95a39fe49 100644 --- a/applications/test/gravityMeshObject/Test-gravityMeshObject.C +++ b/applications/test/gravityMeshObject/Test-gravityMeshObject.C @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) Info<< "Found: " << objects << nl << endl; - for (const IOobject& io : objects.sorted()) + for (const IOobject& io : objects.csorted()) { if (io.name() == meshObjects::gravity::typeName) { diff --git a/applications/test/objectRegistry/Test-objectRegistry.C b/applications/test/objectRegistry/Test-objectRegistry.C index 76c3f4a1c5..2b2c6c1ff8 100644 --- a/applications/test/objectRegistry/Test-objectRegistry.C +++ b/applications/test/objectRegistry/Test-objectRegistry.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -78,8 +78,8 @@ void printRegistry Foam::label indent ) { - UPtrList objects(obr.sorted()); - wordList regNames(obr.sortedNames()); + const UPtrList objects(obr.csorted()); + const wordList regNames(obr.sortedNames()); std::string prefix; for (label i=indent; i; --i) diff --git a/applications/test/objectRegistry2/Test-objectRegistry2.C b/applications/test/objectRegistry2/Test-objectRegistry2.C index 80780f6b99..66f7da171e 100644 --- a/applications/test/objectRegistry2/Test-objectRegistry2.C +++ b/applications/test/objectRegistry2/Test-objectRegistry2.C @@ -145,8 +145,8 @@ void printRegistry Foam::label indent ) { - UPtrList objects(obr.sorted()); - wordList regNames(obr.sortedNames()); + const UPtrList objects(obr.csorted()); + const wordList regNames(obr.sortedNames()); std::string prefix; for (label i=indent; i; --i) @@ -315,7 +315,7 @@ int main(int argc, char *argv[]) registryTests(mesh); - report(mesh.sorted()); + report(mesh.csorted()); report(mesh.csorted()); Info<< nl; diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C index 01dd0bcfd2..59e247b3a4 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C @@ -192,14 +192,6 @@ Foam::HashTable::csorted() const } -template -Foam::UPtrList::node_type> -Foam::HashTable::sorted() const -{ - return csorted(); -} - - template Foam::UPtrList::node_type> Foam::HashTable::sorted() diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index 6879d890e1..3884212de8 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -34,7 +34,7 @@ Description depends on the method used to generate the hash key index, the table capacity, insertion order etc. When the key order is important, use the sortedToc() method to obtain a list of sorted - keys and use that for further access, or the sorted() method + keys and use that for further access, or the csorted()/sorted() methods to obtain a UPtrList of entries to traverse in sorted order. Internally the table uses closed addressing into a flat storage space @@ -351,11 +351,6 @@ public: // The lifetime of the returned content cannot exceed the parent! UPtrList csorted() const; - //- Const access to the hash-table contents in sorted order - //- (sorted by keys). - // The lifetime of the returned content cannot exceed the parent! - UPtrList sorted() const; - //- Non-const access to the hash-table contents in sorted order //- (sorted by keys). // The lifetime of the returned content cannot exceed the parent! @@ -1006,6 +1001,11 @@ public: //- Same as contains() bool found(const Key& key) const { return this->contains(key); } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted() const { return this->csorted(); } }; diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.C b/src/OpenFOAM/db/IOobjectList/IOobjectList.C index 4439109d00..c06d0f7503 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.C +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.C @@ -220,22 +220,6 @@ Foam::label Foam::IOobjectList::count(const char* clsName) const } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -Foam::UPtrList -Foam::IOobjectList::sorted() const -{ - return sorted(); -} - - -Foam::UPtrList -Foam::IOobjectList::sorted(const bool syncPar) const -{ - return sorted(syncPar); -} - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Foam::wordList Foam::IOobjectList::names() const diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.H b/src/OpenFOAM/db/IOobjectList/IOobjectList.H index 5c951c4ec5..427f8513fd 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.H +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -129,12 +129,13 @@ class IOobjectList const bool doSort ); - //- Templated implementation for sorted() + //- Templated implementation for csorted()/sorted() template static UPtrList objectsTypeImpl ( const IOobjectList& list, - const MatchPredicate& matchName + const MatchPredicate& matchName, + const bool doSort ); //- Templated implementation for lookup() @@ -421,26 +422,37 @@ public: HashTable classes(const MatchPredicate& matchName) const; - // Sorted access + // List-wise access (unsorted) - //- The sorted list of IOobjects - // The lifetime of the returned content cannot exceed the parent! - UPtrList sorted() const; - - //- The sorted list of IOobjects with optional check for - //- parallel consistency. - // FatalError if syncPar = true and names are not consistent on all - // processors. - // The lifetime of the returned content cannot exceed the parent! - UPtrList sorted(const bool syncPar) const; - - //- The sorted list of IOobjects with headerClassName == Type::typeName + //- The unsorted list of IOobjects with + //- headerClassName == Type::typeName // // \note If \a Type is \c void, no headerClassName check is used // (always true). // The lifetime of the returned content cannot exceed the parent! template - UPtrList sorted() const; + UPtrList cobjects() const; + + //- The unsorted list of IOobjects with + //- headerClassName == Type::typeName + //- that also have a matching object name. + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList cobjects + ( + const MatchPredicate& matchName + ) const; + + // List-wise access (sorted) + + //- The sorted list of IOobjects with + //- headerClassName == Type::typeName + // + // \note If \a Type is \c void, no headerClassName check is used + // (always true). + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList csorted() const; //- The sorted names of the IOobjects with optional check for //- parallel consistency. @@ -448,13 +460,30 @@ public: // processors. // The lifetime of the returned content cannot exceed the parent! template - UPtrList sorted(const bool syncPar) const; + UPtrList csorted(const bool syncPar) const; + + //- The sorted list of IOobjects + // The lifetime of the returned content cannot exceed the parent! + UPtrList csorted() const + { + return csorted(); + } + + //- The sorted list of IOobjects with optional check for + //- parallel consistency. + // FatalError if syncPar = true and names are not consistent on all + // processors. + // The lifetime of the returned content cannot exceed the parent! + UPtrList csorted(const bool syncPar) const + { + return csorted(syncPar); + } //- The sorted list of IOobjects with headerClassName == Type::typeName //- that also have a matching object name. // The lifetime of the returned content cannot exceed the parent! template - UPtrList sorted(const MatchPredicate& matchName) const; + UPtrList csorted(const MatchPredicate& matchName) const; //- The sorted list of IOobjects with headerClassName == Type::typeName //- that also have a matching object name. @@ -462,7 +491,7 @@ public: // processors. // The lifetime of the returned content cannot exceed the parent! template - UPtrList sorted + UPtrList csorted ( const MatchPredicate& matchName, const bool syncPar @@ -769,10 +798,67 @@ public: { return getObject(objName); } + + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + template + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted() const + { + return csorted(); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + template + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted(const bool syncPar) const + { + return csorted(syncPar); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted() const + { + return csorted(); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted(const bool syncPar) const + { + return csorted(syncPar); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + template + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted(const MatchPredicate& matchName) const + { + return csorted(matchName); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + template + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted + ( + const MatchPredicate& matchName, + const bool syncPar + ) const + { + return csorted(matchName, syncPar); + } }; -// Ostream operator +// Ostream Operator Ostream& operator<<(Ostream& os, const IOobjectList& list); diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C b/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C index 515e964715..475c3586b6 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C +++ b/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -177,13 +177,14 @@ Foam::wordList Foam::IOobjectList::namesTypeImpl } -// Templated implementation for sorted() +// Templated implementation for csorted(), csorted() template Foam::UPtrList Foam::IOobjectList::objectsTypeImpl ( const IOobjectList& list, - const MatchPredicate& matchName + const MatchPredicate& matchName, + const bool doSort ) { UPtrList result(list.size()); @@ -203,7 +204,10 @@ Foam::IOobjectList::objectsTypeImpl result.resize(count); - Foam::sort(result, nameOp()); // Sort by object name() + if (doSort) + { + Foam::sort(result, nameOp()); // Sort by object name() + } return result; } @@ -472,19 +476,30 @@ Foam::label Foam::IOobjectList::count template Foam::UPtrList -Foam::IOobjectList::sorted() const +Foam::IOobjectList::cobjects() const { - return objectsTypeImpl(*this, predicates::always()); + // doSort = false + return objectsTypeImpl(*this, predicates::always(), false); } template Foam::UPtrList -Foam::IOobjectList::sorted(const bool syncPar) const +Foam::IOobjectList::csorted() const +{ + // doSort = true + return objectsTypeImpl(*this, predicates::always(), true); +} + + +template +Foam::UPtrList +Foam::IOobjectList::csorted(const bool syncPar) const { UPtrList list ( - objectsTypeImpl(*this, predicates::always()) + // doSort = true + objectsTypeImpl(*this, predicates::always(), true) ); checkObjectOrder(list, syncPar); @@ -495,18 +510,31 @@ Foam::IOobjectList::sorted(const bool syncPar) const template Foam::UPtrList -Foam::IOobjectList::sorted +Foam::IOobjectList::cobjects ( const MatchPredicate& matchName ) const { - return objectsTypeImpl(*this, matchName); + // doSort = false + return objectsTypeImpl(*this, matchName, false); } template Foam::UPtrList -Foam::IOobjectList::sorted +Foam::IOobjectList::csorted +( + const MatchPredicate& matchName +) const +{ + // doSort = true + return objectsTypeImpl(*this, matchName, true); +} + + +template +Foam::UPtrList +Foam::IOobjectList::csorted ( const MatchPredicate& matchName, const bool syncPar @@ -514,7 +542,8 @@ Foam::IOobjectList::sorted { UPtrList list ( - objectsTypeImpl(*this, matchName) + // doSort = true + objectsTypeImpl(*this, matchName, true) ); checkObjectOrder(list, syncPar); @@ -531,6 +560,7 @@ Foam::wordList Foam::IOobjectList::names const MatchPredicate& matchClass ) const { + // doSort = false return namesImpl(*this, matchClass, predicates::always(), false); } @@ -553,6 +583,7 @@ Foam::wordList Foam::IOobjectList::names const MatchPredicate2& matchName ) const { + // doSort = false return namesImpl(*this, matchClass, matchName, false); } @@ -572,6 +603,7 @@ Foam::wordList Foam::IOobjectList::names template Foam::wordList Foam::IOobjectList::names() const { + // doSort = false return namesTypeImpl(*this, predicates::always(), false); } @@ -589,6 +621,7 @@ Foam::wordList Foam::IOobjectList::names const MatchPredicate& matchName ) const { + // doSort = false return namesTypeImpl(*this, matchName, false); } diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index df993fd902..76b7bad5cb 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -158,27 +158,6 @@ Foam::label Foam::objectRegistry::count(const char* clsName) const } -Foam::UPtrList -Foam::objectRegistry::csorted() const -{ - return objectsTypeImpl(*this, predicates::always()); -} - - -Foam::UPtrList -Foam::objectRegistry::sorted() const -{ - return objectsTypeImpl(*this, predicates::always()); -} - - -Foam::UPtrList -Foam::objectRegistry::sorted() -{ - return objectsTypeImpl(*this, predicates::always()); -} - - Foam::wordList Foam::objectRegistry::names() const { return HashTable::toc(); diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index 9ae0c9e868..226ef9f043 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -150,13 +150,24 @@ class objectRegistry const bool doSort ); - //- Templated implementation for sorted() + //- Templated implementation for csorted()/sorted() // Called with 'Type' or 'const Type' template static UPtrList objectsTypeImpl ( + const bool strict, // Check with isType const objectRegistry& list, - const MatchPredicate& matchName + const MatchPredicate& matchName, + const bool doSort // Sort the list by name + ); + + //- Templated implementation for lookupClass() + // Called with 'Type' or 'const Type' + template + static HashTable lookupClassTypeImpl + ( + const bool strict, // Check with isType + const objectRegistry& list ); @@ -240,49 +251,69 @@ public: HashTable classes(const MatchPredicate& matchName) const; - // Sorted access + // List-wise access (unsorted) - //- Return sorted list of objects + //- Return unsorted list of objects with a class satisfying + //- \c isA\ or \c isType\ (with Strict) // The lifetime of the returned content cannot exceed the parent! - UPtrList csorted() const; + template + UPtrList cobjects() const; - //- Return sorted list of objects + //- Return unsorted list of objects with a class satisfying + //- \c isA\ or \c isType\ (with Strict) // The lifetime of the returned content cannot exceed the parent! - UPtrList sorted() const; + template + UPtrList objects(); - //- Return sorted list of objects + //- Return unsorted list of objects with a class satisfying + //- \c isA\ that also have a matching object name. // The lifetime of the returned content cannot exceed the parent! - UPtrList sorted(); - - //- Return sorted list of objects with a class satisfying \c isA\ - // The lifetime of the returned content cannot exceed the parent! - template - UPtrList csorted() const; - - //- Return sorted list of objects with a class satisfying \c isA\ - // The lifetime of the returned content cannot exceed the parent! - template - UPtrList sorted() const; - - //- Return sorted list of objects with a class satisfying \c isA\ - // The lifetime of the returned content cannot exceed the parent! - template - UPtrList sorted(); + template + UPtrList cobjects(const MatchPredicate& matchName) const; //- Return sorted list of objects with a class satisfying \c isA\ //- that also have a matching object name. // The lifetime of the returned content cannot exceed the parent! template + UPtrList objects(const MatchPredicate& matchName); + + + // List-wise access (sorted) + + //- Return sorted list of objects with a class satisfying + //- \c isA\ or \c isType\ (with Strict) + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList csorted() const; + + //- Return sorted list of objects with a class satisfying + //- \c isA\ or \c isType\ (with Strict) + // The lifetime of the returned content cannot exceed the parent! + template + UPtrList sorted(); + + //- Return sorted list of objects + // The lifetime of the returned content cannot exceed the parent! + UPtrList csorted() const + { + return csorted(); + } + + //- Return sorted list of objects + // The lifetime of the returned content cannot exceed the parent! + UPtrList sorted() + { + return sorted(); + } + + //- Return sorted list of objects with a class satisfying + //- \c isA\ that also have a matching object name. + // The lifetime of the returned content cannot exceed the parent! + template UPtrList csorted(const MatchPredicate& matchName) const; - //- Return sorted list of objects with a class satisfying \c isA\ - //- that also have a matching object name. - // The lifetime of the returned content cannot exceed the parent! - template - UPtrList sorted(const MatchPredicate& matchName) const; - - //- Return sorted list of objects with a class satisfying \c isA\ - //- that also have a matching object name. + //- Return sorted list of objects with a class satisfying + //- \c isA\ that also have a matching object name. // The lifetime of the returned content cannot exceed the parent! template UPtrList sorted(const MatchPredicate& matchName); @@ -351,7 +382,7 @@ public: const MatchPredicate2& matchName ) const; - //- The unsorted names of objects with a class satisfying \c isA\. + //- The unsorted names of objects with a class satisfying \c isA\ // // \note If \a Type is \c void, no isA check is used (always true). template @@ -417,17 +448,27 @@ public: ) const; - //- Return all objects with a class satisfying \c isA\ - // - // \param strict use \c isType\ instead of \c isA\ - template - HashTable lookupClass(const bool strict = false) const; + //- Return all objects with a class satisfying + //- \c isA\ or \c isType\ (with Strict) + template + HashTable lookupClass() const; + + //- Return all objects with a class satisfying + //- \c isA\ or \c isType\ (with Strict) + template + HashTable lookupClass(); //- Return all objects with a class satisfying \c isA\ // // \param strict use \c isType\ instead of \c isA\ template - HashTable lookupClass(const bool strict = false); + HashTable lookupClass(const bool strict) const; + + //- Return all objects with a class satisfying \c isA\ + // + // \param strict use \c isType\ instead of \c isA\ + template + HashTable lookupClass(const bool strict); //- Return const pointer to the regIOobject. // @@ -673,6 +714,32 @@ public: { return this->getObjectPtr(name, recursive); } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + template + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted() const + { + return csorted(); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted() const + { + return csorted(); + } + + //- Deprecated(2023-07) use csorted() method + // \deprecated(2023-07) - use csorted() method + template + FOAM_DEPRECATED_FOR(2023-07, "csorted() method") + UPtrList sorted(const MatchPredicate& matchName) const + { + return csorted(matchName); + } }; diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C index 9204516b5d..a03ebcd00c 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C @@ -184,13 +184,15 @@ Foam::wordList Foam::objectRegistry::namesTypeImpl } -// Templated implementation for sorted() +// Templated implementation for cobjects()/objects(), csorted()/sorted() template Foam::UPtrList Foam::objectRegistry::objectsTypeImpl ( + const bool strict, const objectRegistry& list, - const MatchPredicate& matchName + const MatchPredicate& matchName, + const bool doSort ) { typedef typename std::remove_cv::type BaseType; @@ -200,9 +202,15 @@ Foam::objectRegistry::objectsTypeImpl label count = 0; forAllConstIters(list, iter) { - const BaseType* ptr = Foam::isA(*iter.val()); + const regIOobject* obj = iter.val(); + const BaseType* ptr = dynamic_cast(obj); - if (ptr && matchName(ptr->name())) + if + ( + ptr + && (!strict || Foam::isType(*obj)) + && matchName(ptr->name()) + ) { result.set(count, const_cast(ptr)); ++count; @@ -211,7 +219,42 @@ Foam::objectRegistry::objectsTypeImpl result.resize(count); - Foam::sort(result, nameOp()); // Sort by object name() + if (doSort) + { + Foam::sort(result, nameOp()); // Sort by object name() + } + + return result; +} + + +// Templated implementation for lookupClass() +template +Foam::HashTable +Foam::objectRegistry::lookupClassTypeImpl +( + const bool strict, + const objectRegistry& list +) +{ + typedef typename std::remove_cv::type BaseType; + + HashTable result(list.capacity()); + + forAllConstIters(list, iter) + { + const regIOobject* obj = iter.val(); + const BaseType* ptr = dynamic_cast(obj); + + if + ( + ptr + && (!strict || Foam::isType(*obj)) + ) + { + result.insert(obj->name(), const_cast(ptr)); + } + } return result; } @@ -294,27 +337,71 @@ Foam::label Foam::objectRegistry::count // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -template +template +Foam::UPtrList +Foam::objectRegistry::cobjects() const +{ + return objectsTypeImpl + ( + Strict, *this, predicates::always(), false // doSort = false + ); +} + + +template +Foam::UPtrList +Foam::objectRegistry::objects() +{ + return objectsTypeImpl + ( + Strict, *this, predicates::always(), false // doSort = false + ); +} + + +template Foam::UPtrList Foam::objectRegistry::csorted() const { - return objectsTypeImpl(*this, predicates::always()); + return objectsTypeImpl + ( + Strict, *this, predicates::always(), true // doSort = true + ); } -template -Foam::UPtrList -Foam::objectRegistry::sorted() const -{ - return objectsTypeImpl(*this, predicates::always()); -} - - -template +template Foam::UPtrList Foam::objectRegistry::sorted() { - return objectsTypeImpl(*this, predicates::always()); + return objectsTypeImpl + ( + Strict, *this, predicates::always(), true // doSort = false + ); +} + + +template +Foam::UPtrList +Foam::objectRegistry::cobjects +( + const MatchPredicate& matchName +) const +{ + // doSort = false + return objectsTypeImpl(false, *this, matchName, false); +} + + +template +Foam::UPtrList +Foam::objectRegistry::objects +( + const MatchPredicate& matchName +) +{ + // doSort = false + return objectsTypeImpl(false, *this, matchName, false); } @@ -325,20 +412,10 @@ Foam::objectRegistry::csorted const MatchPredicate& matchName ) const { - return objectsTypeImpl(*this, matchName); + return objectsTypeImpl(false, *this, matchName, true); } -template -Foam::UPtrList -Foam::objectRegistry::sorted -( - const MatchPredicate& matchName -) const -{ - return objectsTypeImpl(*this, matchName); -} - template Foam::UPtrList Foam::objectRegistry::sorted @@ -346,7 +423,7 @@ Foam::objectRegistry::sorted const MatchPredicate& matchName ) { - return objectsTypeImpl(*this, matchName); + return objectsTypeImpl(false, *this, matchName, true); } @@ -428,30 +505,27 @@ Foam::wordList Foam::objectRegistry::sortedNames } +template +Foam::HashTable Foam::objectRegistry::lookupClass() const +{ + return lookupClassTypeImpl(Strict, *this); +} + + +template +Foam::HashTable Foam::objectRegistry::lookupClass() +{ + return lookupClassTypeImpl(Strict, *this); +} + + template Foam::HashTable Foam::objectRegistry::lookupClass ( const bool strict ) const { - HashTable objectsOfClass(size()); - - forAllConstIters(*this, iter) - { - const regIOobject* obj = iter.val(); - - if - ( - strict - ? bool(Foam::isType(*obj)) - : bool(Foam::isA(*obj)) - ) - { - objectsOfClass.insert(obj->name(), dynamic_cast(obj)); - } - } - - return objectsOfClass; + return lookupClassTypeImpl(strict, *this); } @@ -461,24 +535,7 @@ Foam::HashTable Foam::objectRegistry::lookupClass const bool strict ) { - HashTable objectsOfClass(size()); - - forAllIters(*this, iter) - { - regIOobject* obj = iter.val(); - - if - ( - strict - ? bool(Foam::isType(*obj)) - : bool(Foam::isA(*obj)) - ) - { - objectsOfClass.insert(obj->name(), dynamic_cast(obj)); - } - } - - return objectsOfClass; + return lookupClassTypeImpl(strict, *this); } diff --git a/src/OpenFOAM/meshes/MeshObject/MeshObject.C b/src/OpenFOAM/meshes/MeshObject/MeshObject.C index 6423b898c2..26bbf42e81 100644 --- a/src/OpenFOAM/meshes/MeshObject/MeshObject.C +++ b/src/OpenFOAM/meshes/MeshObject/MeshObject.C @@ -206,7 +206,7 @@ void Foam::meshObject::updateMesh(objectRegistry& obr, const mapPolyMesh& mpm) forAllIters(meshObjects, iter) { - // isA> + // isA> auto* objectPtr = dynamic_cast*>(*iter); if (objectPtr) @@ -277,7 +277,7 @@ void Foam::meshObject::clearUpto(objectRegistry& obr) forAllIters(meshObjects, iter) { - // isA + // isA> auto* objectPtr = dynamic_cast*>(*iter); if (!objectPtr)