scalarRanges.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-2023 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 Class
27  Foam::scalarRanges
28 
29 Description
30  A collection of scalar bounds to be used as a unary predicate.
31 
32 SeeAlso
33  Foam::predicates::scalars
34 
35 SourceFiles
36  scalarRanges.C
37  scalarRangesI.H
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_scalarRanges_H
42 #define Foam_scalarRanges_H
43 
44 #include "scalarRange.H"
45 #include "List.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class scalarRanges Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class scalarRanges
57 :
58  public List<scalarRange>
59 {
60 public:
61 
62  // Constructors
63 
64  //- Inherit constructors from List of scalarRange
66 
67  //- Default construct
68  constexpr scalarRanges() noexcept = default;
69 
70  //- Construct by parsing string using the parse() static method
71  //- with optional reporting if any range fails to parse
72  explicit scalarRanges(const std::string& str, bool report = true)
73  :
74  List<scalarRange>(scalarRanges::parse(str, report))
75  {}
76 
77 
78  // Static Constructors
79 
80  //- Construct by parsing string for scalar ranges
81  //- with optional reporting if any range fails to parse.
82  // The individual items are space, comma or semicolon delimited.
83  static scalarRanges parse(const std::string& str, bool report = true);
84 
85 
86  // Member Functions
87 
88  //- True if the value is contained by any of the sub-ranges
89  bool contains(const scalar value) const
90  {
91  for (const scalarRange& range : *this)
92  {
93  if (range.contains(value))
94  {
95  return true;
96  }
97  }
98  return false;
99  }
100 
101  //- True if the value is matched by any of the sub-ranges
102  bool match(const scalar value) const { return contains(value); }
103 
104 
105  // Member Operators
106 
107  //- For use as a predicate, same as contains()
108  bool operator()(const scalar value) const { return contains(value); }
109 };
111 
112 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
113 
114 } // End namespace Foam
115 
116 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
117 
118 #endif
119 
120 // ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
constexpr scalarRanges() noexcept=default
Default construct.
scalar range
bool match(const scalar value) const
True if the value is matched by any of the sub-ranges.
Definition: scalarRanges.H:110
const direction noexcept
Definition: Scalar.H:258
static scalarRanges parse(const std::string &str, bool report=true)
Construct by parsing string for scalar ranges with optional reporting if any range fails to parse...
Definition: scalarRanges.C:27
A collection of scalar bounds to be used as a unary predicate.
Definition: scalarRanges.H:51
bool contains(const scalar value) const
True if the value is contained by any of the sub-ranges.
Definition: scalarRanges.H:95
bool operator()(const scalar value) const
For use as a predicate, same as contains()
Definition: scalarRanges.H:118
Namespace for OpenFOAM.
Scalar bounds to be used as a unary predicate.
Definition: scalarRange.H:63