ENH: direct support of wordRes::filter in stringListOps

This commit is contained in:
Mark Olesen
2022-02-17 17:31:47 +01:00
parent 42f426f6c4
commit a67f6bf7ae
2 changed files with 39 additions and 8 deletions

View File

@ -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
//

View File

@ -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);
}
// ************************************************************************* //