From a67f6bf7ae87a5a10114c369f47e7b2d6165068d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 17 Feb 2022 17:31:47 +0100 Subject: [PATCH] ENH: direct support of wordRes::filter in stringListOps --- .../primitives/strings/lists/stringListOps.H | 16 ++++++++-- .../strings/lists/stringListOpsTemplates.C | 31 +++++++++++++++---- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/OpenFOAM/primitives/strings/lists/stringListOps.H b/src/OpenFOAM/primitives/strings/lists/stringListOps.H index 8f52bf6f9c..64c8864edc 100644 --- a/src/OpenFOAM/primitives/strings/lists/stringListOps.H +++ b/src/OpenFOAM/primitives/strings/lists/stringListOps.H @@ -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 +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 // diff --git a/src/OpenFOAM/primitives/strings/lists/stringListOpsTemplates.C b/src/OpenFOAM/primitives/strings/lists/stringListOpsTemplates.C index 4478075d6c..1e986e7ef9 100644 --- a/src/OpenFOAM/primitives/strings/lists/stringListOpsTemplates.C +++ b/src/OpenFOAM/primitives/strings/lists/stringListOpsTemplates.C @@ -135,21 +135,18 @@ template 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 +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); +} + + // ************************************************************************* //