scalarPredicatesI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2018-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
29 
31 (
32  const word& opName,
33  const scalar opVal,
34  const scalar tol
35 )
36 {
37  return operation(opNames[opName], opVal, tol);
38 }
39 
40 
42 (
43  const Tuple2<word, scalar>& op,
44  const scalar tol
45 )
46 {
47  return operation(opNames[op.first()], op.second(), tol);
48 }
49 
50 
52 (
53  const std::pair<word, scalar>& op,
54  const scalar tol
55 )
56 {
57  return operation(opNames[op.first], op.second, tol);
58 }
59 
60 
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62 
64 (
65  const scalar value,
66  label pos
67 ) const
68 {
69  return (this->find(value, pos) >= 0);
70 }
71 
72 
73 inline bool Foam::predicates::scalars::match(const scalar& value) const
74 {
75  return this->matchAny(value);
76 }
77 
78 
79 inline bool Foam::predicates::scalars::matchAny(const scalar& value) const
80 {
81  for (const unary& test : *this)
82  {
83  if (test(value))
84  {
85  return true;
86  }
87  }
88 
89  return false;
90 }
91 
92 
93 inline bool Foam::predicates::scalars::matchAll(const scalar& value) const
94 {
95  for (const unary& test : *this)
96  {
97  if (!test(value))
98  {
99  return false;
100  }
101  }
102 
103  return (!this->empty());
104 }
105 
106 
108 (
109  const scalar& value
110 ) const
111 {
112  labelList indices(this->size());
113 
114  label i = 0, count = 0;
115  for (const unary& test : *this)
116  {
117  if (test(value))
118  {
119  indices[count] = i;
120  ++count;
121  }
122  ++i;
123  }
124  indices.resize(count);
125 
126  return indices;
127 }
128 
129 
131 (
132  const UList<scalar>& input,
133  const bool invert
134 ) const
135 {
136  const label len = input.size();
137 
138  labelList indices(len);
139 
140  label count = 0;
141  for (label i=0; i < len; ++i)
142  {
143  if (match(input[i]) ? !invert : invert)
144  {
145  indices[count] = i;
146  ++count;
147  }
148  }
149  indices.resize(count);
150 
151  return indices;
152 }
153 
154 
155 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
156 
157 inline bool Foam::predicates::scalars::operator()(const scalar& value) const
158 {
159  return this->found(value);
160 }
161 
162 
163 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::predicates::scalars::match
bool match(const scalar &value) const
Match any condition in the list.
Definition: scalarPredicatesI.H:73
Foam::invert
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
Definition: ListOps.C:36
Foam::ListOps::find
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Find index of the first occurrence that satisfies the predicate.
Foam::predicates::scalars::operator()
bool operator()(const scalar &value) const
Identical to found(), match(), for use as a predicate.
Definition: scalarPredicatesI.H:157
Foam::predicates::scalars::matchAll
bool matchAll(const scalar &value) const
Match all conditions in the list.
Definition: scalarPredicatesI.H:93
Foam::predicates::scalars::found
bool found(const scalar value, label pos=0) const
True if the value matches any in the list.
Definition: scalarPredicatesI.H:64
Foam::predicates::scalars::operation
static unary operation(const opType op, const scalar opVal, const scalar tol=VSMALL)
Standard comparison method by type.
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::stringOps::match
bool match(const UList< wordRe > &patterns, const std::string &text)
Return true if text matches one of the regular expressions.
Definition: stringOps.H:76
Foam::predicates::scalars::matchAny
bool matchAny(const scalar &value) const
Match any condition in the list.
Definition: scalarPredicatesI.H:79
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::List< label >
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::input
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
Foam::Tuple2::second
const T2 & second() const noexcept
Return second.
Definition: Tuple2.H:130
Foam::Tuple2
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:60
Foam::predicates::scalars::matching
labelList matching(const scalar &value) const
Extract list indices for all matches.
Definition: scalarPredicatesI.H:108
Foam::Tuple2::first
const T1 & first() const noexcept
Return first.
Definition: Tuple2.H:118
Foam::predicates::scalars::unary
std::function< bool(Foam::scalar)> unary
The unary function type for testing a scalar.
Definition: scalarPredicates.H:75
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177