diff --git a/applications/test/IOobjectList/Test-IOobjectList.C b/applications/test/IOobjectList/Test-IOobjectList.C index ec7ce76299f17dfb26db64063d74926e625422d6..3e0850c0d7336bfcaf62dfe5a4f1c9b39cebaedf 100644 --- a/applications/test/IOobjectList/Test-IOobjectList.C +++ b/applications/test/IOobjectList/Test-IOobjectList.C @@ -32,6 +32,8 @@ Description #include "timeSelector.H" #include "IOobjectList.H" #include "hashedWordList.H" +#include "labelIOList.H" +#include "scalarIOList.H" using namespace Foam; @@ -80,6 +82,67 @@ void reportDetail(const IOobjectList& objects) } +template<class Type> +void filterTest(const IOobjectList& objs, const wordRe& re) +{ + Info<< "Filter = " << re << nl; + + const word& typeName = Type::typeName; + + Info<< " <" << typeName <<">(" << re << ") : " + << objs.count<Type>(re) << nl + << " (" << typeName << "::typeName, " << re << ") : " + << objs.count(typeName, re) << nl; + + Info<< " <" << typeName << ">(" << re << ") : " + << flatOutput(objs.sortedNames<Type>(re)) << nl + // << flatOutput(objs.names<Type>(re)) << nl + << " (" << typeName << "::typeName, " << re << ") : " + << flatOutput(objs.sortedNames(typeName, re)) << nl + //<< flatOutput(objs.names(typeName, re)) << nl + ; + + + wordRe reClass("vol.*Field", wordRe::REGEX); + wordRe re2(re, wordRe::REGEX_ICASE); + + Info<< "General" << nl + << " <void>(" << re << ") : " + << flatOutput(objs.sortedNames<void>(re)) << nl + << " (" << reClass << ", " << re2 <<" ignore-case) : " + << flatOutput(objs.sortedNames(reClass, re2)) << nl + ; + + Info<< nl; +} + + +void registryTests(const IOobjectList& objs) +{ + Info<< nl << "IOobjectList " << flatOutput(objs.sortedNames()) << nl; + + Info<< "count" << nl + << " <void>() : " << objs.count<void>() << nl + << " <labelList>() : " << objs.count<labelIOList>() << nl + << " <scalarList>() : " << objs.count<scalarIOList>() << nl + << nl; + Info<< " <volScalarField>() : " + << objs.count<volScalarField>() << nl + << " (volScalarField::typeName) : " + << objs.count(volScalarField::typeName) << nl; + Info<< " <volVectorField>() : " + << objs.count<volVectorField>() << nl + << " (volVectorField::typeName) : " + << objs.count(volVectorField::typeName) << nl; + + + Info<< nl << "Filter on names:" << nl; + filterTest<volScalarField>(objs, wordRe("[p-z].*", wordRe::DETECT)); + + Info<< nl; +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: @@ -165,6 +228,8 @@ int main(int argc, char *argv[]) Info<<"remove: " << flatOutput(subsetTypes) << nl; Info<<"Pruned: " << classes << nl; + registryTests(objects); + // On last time if (timeI == timeDirs.size()-1) { diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.C b/src/OpenFOAM/db/IOobjectList/IOobjectList.C index 9b6824f85698c2cd6b916a77283e84f4438775de..8d914a1b470f49c32fe6ae0a9a13214b2bb5805f 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.C +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.C @@ -296,37 +296,33 @@ Foam::wordList Foam::IOobjectList::names(const bool syncPar) const } -Foam::wordList Foam::IOobjectList::names -( - const word& clsName -) const +Foam::wordList Foam::IOobjectList::names(const char* clsName) const { - // sort/sync: false, false - return namesImpl(*this, clsName, predicates::always(), false, false); + // No nullptr check - only called with string literals + return names(static_cast<word>(clsName)); } Foam::wordList Foam::IOobjectList::names ( - const word& clsName, + const char* clsName, const bool syncPar ) const { - // sort: false - return namesImpl(*this, clsName, predicates::always(), false, syncPar); + // No nullptr check - only called with string literals + return names(static_cast<word>(clsName), syncPar); } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + Foam::wordList Foam::IOobjectList::sortedNames() const { return HashPtrTable<IOobject>::sortedToc(); } -Foam::wordList Foam::IOobjectList::sortedNames -( - const bool syncPar -) const +Foam::wordList Foam::IOobjectList::sortedNames(const bool syncPar) const { wordList objNames(HashPtrTable<IOobject>::sortedToc()); @@ -335,24 +331,21 @@ Foam::wordList Foam::IOobjectList::sortedNames } -Foam::wordList Foam::IOobjectList::sortedNames -( - const word& clsName -) const +Foam::wordList Foam::IOobjectList::sortedNames(const char* clsName) const { - // sort/sync: true, false - return namesImpl(*this, clsName, predicates::always(), true, false); + // No nullptr check - only called with string literals + return sortedNames(static_cast<word>(clsName)); } Foam::wordList Foam::IOobjectList::sortedNames ( - const word& clsName, + const char* clsName, const bool syncPar ) const { - // sort: true - return namesImpl(*this, clsName, predicates::always(), true, syncPar); + // No nullptr check - only called with string literals + return names(static_cast<word>(clsName), syncPar); } diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.H b/src/OpenFOAM/db/IOobjectList/IOobjectList.H index b4882c5d9175b4b8822b03399795669457d1db71..692e81c8905776b82a1961bd9efb7d6f0285a703 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.H +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.H @@ -101,8 +101,7 @@ class IOobjectList const IOobjectList& list, const MatchPredicate1& matchClass, const MatchPredicate2& matchName, - const bool doSort, - const bool syncPar + const bool doSort ); //- Templated implementation for names(), sortedNames() @@ -374,31 +373,74 @@ public: // if the names are not consistent on all processors. wordList names(const bool syncPar) const; - //- The names of IOobjects with the given class - wordList names(const word& clsName) const; + //- The names of IOobjects with the given headerClassName + wordList names(const char* clsName) const; //- The names of the IOobjects with the given headerClassName // With syncPar = true, sorts the names and triggers FatalError // if the names are not consistent on all processors. - wordList names(const word& clsName, const bool syncPar) const; + wordList names(const char* clsName, const bool syncPar) const; //- The names of IOobjects with the given headerClassName - //- that also have a matching object name. + template<class MatchPredicate> + wordList names(const MatchPredicate& matchClass) const; + + //- The names of the IOobjects with the given headerClassName + // With syncPar = true, sorts the names and triggers FatalError + // if the names are not consistent on all processors. template<class MatchPredicate> wordList names ( - const word& clsName, - const MatchPredicate& matchName + const MatchPredicate& matchClass, + const bool syncPar + ) const; + + //- The names of IOobjects with the given headerClassName + //- that also have a matching object name. + template<class MatchPredicate1, class MatchPredicate2> + wordList names + ( + const MatchPredicate1& matchClass, + const MatchPredicate2& matchName ) const; //- The names of the IOobjects with the given headerClassName //- that also have a matching object name. // With syncPar = true, sorts the names and triggers FatalError // if the names are not consistent on all processors. - template<class MatchPredicate> + template<class MatchPredicate1, class MatchPredicate2> + wordList names + ( + const MatchPredicate1& matchClass, + const MatchPredicate2& matchName, + const bool syncPar + ) const; + + + //- The names of objects with headerClassName == Type::typeName + template<class Type> + wordList names() const; + + //- The names of objects with headerClassName == Type::typeName + // With syncPar = true, sorts the names and triggers FatalError + // if the names are not consistent on all processors. + template<class Type> + wordList names(bool syncPar) const; + + //- The names of objects with headerClassName == Type::typeName + //- that also have a matching object name. + // With syncPar = true, sorts the names and triggers FatalError + // if the names are not consistent on all processors. + template<class Type, class MatchPredicate> + wordList names(const MatchPredicate& matchName) const; + + //- The names of objects with headerClassName == Type::typeName + //- that also have a matching object name. + // With syncPar = true, sorts the names and triggers FatalError + // if the names are not consistent on all processors. + template<class Type, class MatchPredicate> wordList names ( - const word& clsName, const MatchPredicate& matchName, const bool syncPar ) const; @@ -409,36 +451,79 @@ public: //- The sorted names of the IOobjects wordList sortedNames() const; - //- The sorted names of the IOobjects - // With syncPar = true, a FatalError is - // triggered if the names are not consistent on all processors. + //- The sorted names of the IOobjects. + // With syncPar = true, sorts the names and triggers FatalError + // if the names are not consistent on all processors. wordList sortedNames(const bool syncPar) const; //- The sorted names of IOobjects with the given headerClassName - wordList sortedNames(const word& clsName) const; + wordList sortedNames(const char* clsName) const; //- The sorted names of the IOobjects with the given headerClassName // With syncPar = true, sorts the names and triggers FatalError // if the names are not consistent on all processors. - wordList sortedNames(const word& clsName, const bool syncPar) const; + wordList sortedNames(const char* clsName, const bool syncPar) const; //- The sorted names of IOobjects with the given headerClassName - //- that also have a matching object name. + template<class MatchPredicate> + wordList sortedNames(const MatchPredicate& matchClass) const; + + //- The sorted names of the IOobjects with the given headerClassName + // With syncPar = true, sorts the names and triggers FatalError + // if the names are not consistent on all processors. template<class MatchPredicate> wordList sortedNames ( - const word& clsName, - const MatchPredicate& matchName + const MatchPredicate& matchClass, + const bool syncPar + ) const; + + //- The sorted names of IOobjects with the given headerClassName + //- that also have a matching object name. + template<class MatchPredicate1, class MatchPredicate2> + wordList sortedNames + ( + const MatchPredicate1& matchClass, + const MatchPredicate2& matchName ) const; //- The sorted names of the IOobjects with the given headerClassName //- that also have a matching object name. // With syncPar = true, sorts the names and triggers FatalError // if the names are not consistent on all processors. - template<class MatchPredicate> + template<class MatchPredicate1, class MatchPredicate2> + wordList sortedNames + ( + const MatchPredicate1& matchClass, + const MatchPredicate2& matchName, + const bool syncPar + ) const; + + + //- The sorted names of objects with headerClassName == Type::typeName + template<class Type> + wordList sortedNames() const; + + //- The sorted names of objects with headerClassName == Type::typeName + // With syncPar = true, sorts the names and triggers FatalError + // if the names are not consistent on all processors. + template<class Type> + wordList sortedNames(bool syncPar) const; + + //- The sorted names of objects with headerClassName == Type::typeName + //- that also have a matching object name. + // With syncPar = true, sorts the names and triggers FatalError + // if the names are not consistent on all processors. + template<class Type, class MatchPredicate> + wordList sortedNames(const MatchPredicate& matchName) const; + + //- The sorted names of objects with headerClassName == Type::typeName + //- that also have a matching object name. + // With syncPar = true, sorts the names and triggers FatalError + // if the names are not consistent on all processors. + template<class Type, class MatchPredicate> wordList sortedNames ( - const word& clsName, const MatchPredicate& matchName, const bool syncPar ) const; diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C b/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C index c08833c124a326d20d2939cd48dd5c16fcebd32c..b7dc5b9b37305d0be87692ad736dac1b23d02ba3 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C +++ b/src/OpenFOAM/db/IOobjectList/IOobjectListTemplates.C @@ -111,8 +111,7 @@ Foam::wordList Foam::IOobjectList::namesImpl const IOobjectList& list, const MatchPredicate1& matchClass, const MatchPredicate2& matchName, - const bool doSort, - const bool syncPar + const bool doSort ) { wordList objNames(list.size()); @@ -130,15 +129,13 @@ Foam::wordList Foam::IOobjectList::namesImpl } } - objNames.setSize(count); + objNames.resize(count); if (doSort) { Foam::sort(objNames); } - checkNames(objNames, syncPar); - return objNames; } @@ -330,18 +327,6 @@ Foam::IOobjectList::classes } -template<class MatchPredicate> -Foam::wordList Foam::IOobjectList::names -( - const word& clsName, - const MatchPredicate& matchName -) const -{ - // sort/sync: false, false - return namesImpl(*this, clsName, matchName, false, false); -} - - template<class MatchPredicate> Foam::label Foam::IOobjectList::count ( @@ -385,38 +370,186 @@ Foam::label Foam::IOobjectList::count template<class MatchPredicate> Foam::wordList Foam::IOobjectList::names ( - const word& clsName, + const MatchPredicate& matchClass +) const +{ + return namesImpl(*this, matchClass, predicates::always(), false); +} + + +template<class MatchPredicate> +Foam::wordList Foam::IOobjectList::names +( + const MatchPredicate& matchClass, + const bool syncPar +) const +{ + wordList objNames + ( + namesImpl(*this, matchClass, predicates::always(), false) + ); + + checkNames(objNames, syncPar); + return objNames; +} + + +template<class MatchPredicate1, class MatchPredicate2> +Foam::wordList Foam::IOobjectList::names +( + const MatchPredicate1& matchClass, + const MatchPredicate2& matchName +) const +{ + return namesImpl(*this, matchClass, matchName, false); +} + + +template<class MatchPredicate1, class MatchPredicate2> +Foam::wordList Foam::IOobjectList::names +( + const MatchPredicate1& matchClass, + const MatchPredicate2& matchName, + const bool syncPar +) const +{ + wordList objNames(namesImpl(*this, matchClass, matchName, false)); + + checkNames(objNames, syncPar); + return objNames; +} + + +template<class Type> +Foam::wordList Foam::IOobjectList::names() const +{ + return namesTypeImpl<Type>(*this, predicates::always(), false); +} + + +template<class Type> +Foam::wordList Foam::IOobjectList::names(const bool syncPar) const +{ + wordList objNames(namesTypeImpl<Type>(*this, predicates::always(), false)); + + checkNames(objNames, syncPar); + return objNames; +} + + +template<class Type, class MatchPredicate> +Foam::wordList Foam::IOobjectList::names +( + const MatchPredicate& matchName +) const +{ + return namesTypeImpl<Type>(*this, matchName, false); +} + + +template<class Type, class MatchPredicate> +Foam::wordList Foam::IOobjectList::names +( const MatchPredicate& matchName, const bool syncPar ) const { - // sort: false - return namesImpl(*this, clsName, matchName, false, syncPar); + wordList objNames(namesTypeImpl<Type>(*this, matchName, false)); + + checkNames(objNames, syncPar); + return objNames; } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + template<class MatchPredicate> Foam::wordList Foam::IOobjectList::sortedNames ( - const word& clsName, - const MatchPredicate& matchName + const MatchPredicate& matchClass ) const { - // sort/sync: true, false - return namesImpl(*this, clsName, matchName, true, false); + return namesImpl(*this, matchClass, predicates::always(), true); } template<class MatchPredicate> Foam::wordList Foam::IOobjectList::sortedNames ( - const word& clsName, + const MatchPredicate& matchClass, + const bool syncPar +) const +{ + wordList objNames + ( + namesImpl(*this, matchClass, predicates::always(), true) + ); + + checkNames(objNames, syncPar); + return objNames; +} + + +template<class MatchPredicate1, class MatchPredicate2> +Foam::wordList Foam::IOobjectList::sortedNames +( + const MatchPredicate1& matchClass, + const MatchPredicate2& matchName +) const +{ + return namesImpl(*this, matchClass, matchName, true); +} + +template<class MatchPredicate1, class MatchPredicate2> +Foam::wordList Foam::IOobjectList::sortedNames +( + const MatchPredicate1& matchClass, + const MatchPredicate2& matchName, + const bool syncPar +) const +{ + wordList objNames(namesImpl(*this, matchClass, matchName, true)); + + checkNames(objNames, syncPar); + return objNames; +} + + +template<class Type> +Foam::wordList Foam::IOobjectList::sortedNames() const +{ + return namesTypeImpl<Type>(*this, predicates::always(), true); +} + + +template<class Type> +Foam::wordList Foam::IOobjectList::sortedNames(const bool syncPar) const +{ + wordList objNames(namesTypeImpl<Type>(*this, predicates::always(), true)); + + checkNames(objNames, syncPar); + return objNames; +} + + +template<class Type, class MatchPredicate> +Foam::wordList Foam::IOobjectList::sortedNames +( + const MatchPredicate& matchName +) const +{ + return namesTypeImpl<Type>(*this, matchName, true); +} + + +template<class Type, class MatchPredicate> +Foam::wordList Foam::IOobjectList::sortedNames +( const MatchPredicate& matchName, const bool syncPar ) const { - // sort: true - return namesImpl(*this, clsName, matchName, true, syncPar); + return namesTypeImpl<Type>(*this, matchName, true, syncPar); }