keyType.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::keyType
29 
30 Description
31  A class for handling keywords in dictionaries.
32 
33  A keyType is the keyword of a dictionary.
34  It differs from word in that it also accepts patterns (regular expressions).
35  It is very similar to wordRe, but doesn't store a regular expression.
36 
37 SourceFiles
38  keyType.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef keyType_H
43 #define keyType_H
44 
45 #include "word.H"
46 #include "stdFoam.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward Declarations
54 class Istream;
55 class Ostream;
56 
57 /*---------------------------------------------------------------------------*\
58  Class keyType Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 class keyType
62 :
63  public word
64 {
65 public:
66 
67  // Public Data Types
68 
69  //- Enumeration for the data type and search/match modes (bitmask)
70  // eg, (keyType::REGEX | keyType::RECURSIVE)
71  enum option : unsigned char
72  {
73  // Base stored types
74  LITERAL = 0,
75  REGEX = 1,
76 
77  // Variants for search/match only
78  RECURSIVE = 0x80,
81  };
82 
83 
84 private:
85 
86  // Private Data
87 
88  //- Treat keyType as literal, regex etc.
89  // Never contains RECURSIVE values.
90  option type_;
91 
92 
93  // Private Member Functions
94 
95  //- No assignment where we cannot determine string/word type
96  void operator=(const std::string&) = delete;
97 
98 
99 public:
100 
101  // Static Data Members
102 
103  //- An empty keyType
104  static const keyType null;
105 
106 
107  // Constructors
108 
109  //- Construct null
110  inline keyType();
111 
112  //- Copy construct, retaining type (literal or regex)
113  inline keyType(const keyType& s);
114 
115  //- Copy construct from word, treat as literal.
116  inline keyType(const word& s);
117 
118  //- Copy construct from string, treat as regular expression.
119  inline keyType(const string& s);
120 
121  //- Construct as copy of character array, treat as literal.
122  inline keyType(const char* s);
123 
124  //- Copy construct from std::string with specified treatment
125  inline keyType(const std::string& s, option opt);
126 
127  //- Move construct, retaining type (literal or regex)
128  inline keyType(keyType&& s);
129 
130  //- Move construct from word, treat as literal.
131  inline keyType(word&& s);
132 
133  //- Move construct from string, treat as regular expression.
134  inline keyType(string&& s);
135 
136  //- Move construct from std::string with specified treatment
137  inline keyType(std::string&& s, option opt);
138 
139  //- Construct from Istream
140  // Treat as regular expression if surrounded by quotation marks.
141  explicit keyType(Istream& is);
142 
143 
144  // Member Functions
145 
146  //- Is this character valid for a keyType?
147  // This is largely identical with what word accepts, but also
148  // permit brace-brackets, which are valid for some regexs.
149  inline static bool valid(char c);
150 
151 
152  // Access
153 
154  //- The keyType is treated as literal, not as pattern.
155  inline bool isLiteral() const;
156 
157  //- The keyType is treated as a pattern, not as literal string.
158  inline bool isPattern() const;
159 
160 
161  // Infrastructure
162 
163  //- Change the representation
164  inline void setType(option opt, bool adjust = false);
165 
166  //- Mark as regular expression
167  inline bool compile();
168 
169  //- Mark as literal, instead of a regular expression.
170  // Optionally strip invalid word characters.
171  inline void uncompile(bool adjust = false);
172 
173 
174  // Editing
175 
176  //- Clear string and set as literal
177  inline void clear();
178 
179  //- Swap contents. Self-swapping is a no-op.
180  inline void swap(keyType& s);
181 
182 
183  // Matching/Searching
184 
185  //- Smart match as regular expression or as a string.
186  // Optionally force a literal match only
187  bool match(const std::string& text, bool literal=false) const;
188 
189 
190  // Member Operators
191 
192  //- Perform smart match on text, as per match()
193  // Allows use as a predicate.
194  inline bool operator()(const std::string& text) const;
195 
196 
197  //- Copy assignment, retaining type (literal or regex)
198  // Self-assignment is a no-op.
199  inline void operator=(const keyType& s);
200 
201  //- Move assignment, retaining type (literal or regex)
202  // Self-assignment is a no-op.
203  inline void operator=(keyType&& s);
204 
205  //- Assign as word, treat as literal
206  inline void operator=(const word& s);
207 
208  //- Assign from Foam::string, treat as regular expression
209  inline void operator=(const string& s);
210 
211  //- Assign as word, treat as literal
212  inline void operator=(const char* s);
213 
214 
215  // Housekeeping
216 
217  //- Deprecated(2019-08) construct as literal/regex
218  // \deprecated(2019-08) - use Construct with option
219  FOAM_DEPRECATED_FOR(2019-08, "Construct with option")
220  keyType(const std::string& s, bool isPattern)
221  :
223  {}
224 };
225 
226 
227 // IOstream Operators
228 
229 //- Read operator
230 Istream& operator>>(Istream& is, keyType& val);
231 
232 //- Write operator
233 Ostream& operator<<(Ostream& os, const keyType& val);
234 
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 } // End namespace Foam
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 #include "keyTypeI.H"
243 
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 
246 #endif
247 
248 // ************************************************************************* //
Foam::keyType::LITERAL_RECURSIVE
Definition: keyType.H:78
Foam::keyType::valid
static bool valid(char c)
Is this character valid for a keyType?
Definition: keyTypeI.H:33
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::keyType::keyType
keyType()
Construct null.
Definition: keyTypeI.H:48
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
Foam::keyType::swap
void swap(keyType &s)
Swap contents. Self-swapping is a no-op.
Definition: keyTypeI.H:171
Foam::keyType::clear
void clear()
Clear string and set as literal.
Definition: keyTypeI.H:164
Foam::keyType::isPattern
bool isPattern() const
The keyType is treated as a pattern, not as literal string.
Definition: keyTypeI.H:128
Foam::keyType::operator()
bool operator()(const std::string &text) const
Perform smart match on text, as per match()
Definition: keyTypeI.H:185
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:60
Foam::keyType::RECURSIVE
Recursive search (eg, in dictionary)
Definition: keyType.H:77
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
keyTypeI.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::keyType::setType
void setType(option opt, bool adjust=false)
Change the representation.
Definition: keyTypeI.H:134
Foam::keyType::compile
bool compile()
Mark as regular expression.
Definition: keyTypeI.H:151
Foam::keyType::uncompile
void uncompile(bool adjust=false)
Mark as literal, instead of a regular expression.
Definition: keyTypeI.H:158
stdFoam.H
Foam::keyType::REGEX
Regular expression.
Definition: keyType.H:74
Foam::FOAM_DEPRECATED_FOR
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:69
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::keyType::LITERAL
String literal.
Definition: keyType.H:73
word.H
Foam::keyType::isLiteral
bool isLiteral() const
The keyType is treated as literal, not as pattern.
Definition: keyTypeI.H:122
Foam::keyType::option
option
Enumeration for the data type and search/match modes (bitmask)
Definition: keyType.H:70
Foam::keyType::REGEX_RECURSIVE
Definition: keyType.H:79
Foam::keyType::match
bool match(const std::string &text, bool literal=false) const
Smart match as regular expression or as a string.
Definition: keyType.C:51