mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improve IOobjectList name filtering
- support name filtering by class based on <Type> or predicates.
Eg,
objects.sortedNames<volScalarField>(namePattern);
vs objects.sortedNames(volScalarField::typeName, namePattern);
These can also be used directly for untyped name matching.
Eg,
objects.sortedNames<void>(namePattern);
Can also use a predicate:
objects.sortedNames(wordRe("vol.*Field"), namePattern);
objects.sortedNames
(
[](const word& clsName){ return clsName.startsWith("vol"); },
namePattern
);
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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& matchName,
|
||||
const bool syncPar
|
||||
const MatchPredicate& matchClass
|
||||
) const
|
||||
{
|
||||
// sort: false
|
||||
return namesImpl(*this, clsName, matchName, false, syncPar);
|
||||
return namesImpl(*this, matchClass, predicates::always(), false);
|
||||
}
|
||||
|
||||
|
||||
template<class MatchPredicate>
|
||||
Foam::wordList Foam::IOobjectList::sortedNames
|
||||
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 word& clsName,
|
||||
const MatchPredicate& matchName
|
||||
) const
|
||||
{
|
||||
// sort/sync: true, false
|
||||
return namesImpl(*this, clsName, matchName, true, false);
|
||||
return namesTypeImpl<Type>(*this, matchName, false);
|
||||
}
|
||||
|
||||
|
||||
template<class Type, class MatchPredicate>
|
||||
Foam::wordList Foam::IOobjectList::names
|
||||
(
|
||||
const MatchPredicate& matchName,
|
||||
const bool syncPar
|
||||
) const
|
||||
{
|
||||
wordList objNames(namesTypeImpl<Type>(*this, matchName, false));
|
||||
|
||||
checkNames(objNames, syncPar);
|
||||
return objNames;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class MatchPredicate>
|
||||
Foam::wordList Foam::IOobjectList::sortedNames
|
||||
(
|
||||
const MatchPredicate& matchClass
|
||||
) const
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user