ENH: direct support of wordRes::filter in stringListOps
This commit is contained in:
@ -41,8 +41,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef stringListOps_H
|
||||
#define stringListOps_H
|
||||
#ifndef Foam_stringListOps_H
|
||||
#define Foam_stringListOps_H
|
||||
|
||||
#include "labelList.H"
|
||||
#include "stringList.H"
|
||||
@ -358,6 +358,18 @@ struct foundOp
|
||||
};
|
||||
|
||||
|
||||
//- Return ids for items with matching names.
|
||||
// The filter predicate is a combination of allow and deny lists
|
||||
//
|
||||
// \return List indices for matches
|
||||
template<class StringListType, class AccessOp = noOp>
|
||||
labelList findMatching
|
||||
(
|
||||
const StringListType& input,
|
||||
const wordRes::filter& pred,
|
||||
AccessOp aop = noOp()
|
||||
);
|
||||
|
||||
//- Return ids for items with matching names.
|
||||
// Uses a combination of allow and deny lists
|
||||
//
|
||||
|
||||
@ -135,21 +135,18 @@ template<class StringListType, class AccessOp>
|
||||
Foam::labelList Foam::stringListOps::findMatching
|
||||
(
|
||||
const StringListType& input,
|
||||
const wordRes& allow,
|
||||
const wordRes& deny,
|
||||
const wordRes::filter& pred,
|
||||
AccessOp aop
|
||||
)
|
||||
{
|
||||
const label len = input.size();
|
||||
|
||||
if (allow.empty() && deny.empty())
|
||||
if (pred.empty())
|
||||
{
|
||||
// Accept all
|
||||
return identity(len);
|
||||
}
|
||||
|
||||
// Use combined accept/reject filter
|
||||
const wordRes::filter pred(allow, deny);
|
||||
|
||||
labelList indices(len);
|
||||
|
||||
label count = 0;
|
||||
@ -169,4 +166,26 @@ Foam::labelList Foam::stringListOps::findMatching
|
||||
}
|
||||
|
||||
|
||||
template<class StringListType, class AccessOp>
|
||||
Foam::labelList Foam::stringListOps::findMatching
|
||||
(
|
||||
const StringListType& input,
|
||||
const wordRes& allow,
|
||||
const wordRes& deny,
|
||||
AccessOp aop
|
||||
)
|
||||
{
|
||||
if (allow.empty() && deny.empty())
|
||||
{
|
||||
// Accept all
|
||||
return identity(input.size());
|
||||
}
|
||||
|
||||
// Use combined accept/reject filter
|
||||
const wordRes::filter pred(allow, deny);
|
||||
|
||||
return stringListOps::findMatching(input, pred, aop);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
Reference in New Issue
Block a user