wordRes.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) 2016-2019 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::wordRes
28 
29 Description
30  A List of wordRe with additional matching capabilities.
31 
32 SourceFiles
33  wordResI.H
34  wordRes.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef wordRes_H
39 #define wordRes_H
40 
41 #include "wordReList.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class wordRes Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class wordRes
53 :
54  public List<wordRe>
55 {
56  // Private Methods
57 
58  //- Smart match as literal or regex, stopping on the first match.
59  // \return index of first match, -1 if not found
60  inline static label first_match
61  (
62  const UList<wordRe>& selectors,
63  const std::string& text,
64  const bool literal=false
65  );
66 
67  //- Smart match across entire list, returning the best match type.
68  // Stops on the first literal match, or continues to examine
69  // if a regex match occurs.
70  // \return wordRe::LITERAL, wordRe::REGEX on match and
71  // wordRe::UNKNOWN otherwise.
72  inline static wordRe::compOption found_matched
73  (
74  const UList<wordRe>& selectors,
75  const std::string& text
76  );
77 
78 
79 public:
80 
81  // Public Classes
82 
83  //- Functor wrapper for matching against a List of wordRe
84  struct matcher
85  {
86  const UList<wordRe>& values;
87 
88  matcher(const UList<wordRe>& selectors)
89  :
90  values(selectors)
91  {}
92 
93  //- True if text matches ANY of the entries.
94  // Allows use as a predicate.
95  inline bool operator()(const std::string& text) const;
96  };
97 
98 
99  // Factory Methods
100 
101  //- Return a null wordRes - a reference to the NullObject
102  inline static const wordRes& null();
103 
104  //- Return a wordRes with duplicate entries filtered out.
105  // No distinction made between literals and regular expressions.
106  static wordRes uniq(const UList<wordRe>& input);
107 
108 
109  // Constructors
110 
111  //- Inherit constructors from List of wordRe
112  using List<wordRe>::List;
113 
114 
115  //- Destructor
116  ~wordRes() = default;
117 
118 
119  // Member Functions
120 
121  //- Filter out duplicate entries (inplace).
122  // No distinction made between literals and regular expressions.
123  void uniq();
124 
125  //- Smart match as literal or regex, stopping on the first match.
126  //
127  // \param literal Force literal match only.
128  // \return True if text matches ANY of the entries.
129  inline bool match(const std::string& text, bool literal=false) const;
130 
131  //- Smart match in the list of matchers, returning the match type.
132  // It stops if there is a literal match, or continues to examine
133  // other regexs.
134  // \return LITERAL if a lteral match was found,
135  // REGEX if any regex match was found,
136  // UNKNOWN otherwise.
137  inline wordRe::compOption matched(const std::string& text) const;
138 
139  //- Return list indices for all matches.
140  //
141  // \param input A list of string inputs to match against
142  // \param invert invert the matching logic
143  // \return indices of the matches in the input list
144  template<class StringType>
145  inline labelList matching
146  (
147  const UList<StringType>& input,
148  const bool invert=false
149  ) const;
150 
151 
152  // Member Operators
153 
154  //- Identical to match(), for use as a predicate.
155  inline bool operator()(const std::string& text) const;
156 };
157 
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 } // End namespace Foam
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #include "wordResI.H"
166 
167 #endif
168 
169 // ************************************************************************* //
Foam::wordRes::matching
labelList matching(const UList< StringType > &input, const bool invert=false) const
Return list indices for all matches.
Foam::wordRes::matched
wordRe::compOption matched(const std::string &text) const
Smart match in the list of matchers, returning the match type.
Definition: wordResI.H:98
Foam::wordRes::matcher::matcher
matcher(const UList< wordRe > &selectors)
Definition: wordRes.H:87
Foam::invert
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
Definition: ListOps.C:36
Foam::wordRes::match
bool match(const std::string &text, bool literal=false) const
Smart match as literal or regex, stopping on the first match.
Definition: wordResI.H:91
Foam::wordRes::operator()
bool operator()(const std::string &text) const
Identical to match(), for use as a predicate.
Definition: wordResI.H:132
Foam::wordRes::~wordRes
~wordRes()=default
Destructor.
Foam::wordRes::uniq
void uniq()
Filter out duplicate entries (inplace).
Definition: wordRes.C:70
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::wordRes::matcher
Functor wrapper for matching against a List of wordRe.
Definition: wordRes.H:83
Foam::wordRes::matcher::values
const UList< wordRe > & values
Definition: wordRes.H:85
wordReList.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
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::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::wordRes::matcher::operator()
bool operator()(const std::string &text) const
True if text matches ANY of the entries.
Definition: wordResI.H:138
Foam::input
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
Foam::wordRe::compOption
compOption
Enumeration with compile options.
Definition: wordRe.H:102
wordResI.H