keyTypeI.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 \*---------------------------------------------------------------------------*/
28 
29 #include <algorithm>
30 
31 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
32 
33 inline bool Foam::keyType::valid(char c)
34 {
35  return
36  (
37  !isspace(c)
38  && c != '"' // string quote
39  && c != '\'' // string quote
40  && c != '/' // path separator
41  && c != ';' // end statement
42  );
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
49 :
50  word(),
51  type_(option::LITERAL)
52 {}
53 
54 
56 :
57  word(s, false),
58  type_(s.type_)
59 {}
60 
61 
63 :
64  word(s, false),
65  type_(option::LITERAL)
66 {}
67 
68 
69 inline Foam::keyType::keyType(const string& s)
70 :
71  word(s, false),
72  type_(option::REGEX)
73 {}
74 
75 
76 inline Foam::keyType::keyType(const char* s)
77 :
78  word(s, false),
79  type_(option::LITERAL)
80 {}
81 
82 
83 inline Foam::keyType::keyType(const std::string& s, option opt)
84 :
85  word(s, false),
86  type_(option(opt & 0x0F))
87 {}
88 
89 
91 :
92  word(std::move(static_cast<word&>(s)), false),
93  type_(s.type_)
94 {
95  s.type_ = option::LITERAL;
96 }
97 
98 
100 :
101  word(std::move(s), false),
102  type_(option::LITERAL)
103 {}
104 
105 
106 inline Foam::keyType::keyType(string&& s)
107 :
108  word(std::move(s), false),
109  type_(option::REGEX)
110 {}
111 
112 
113 inline Foam::keyType::keyType(std::string&& s, option opt)
114 :
115  word(std::move(s), false),
116  type_(option(opt & 0x0F))
117 {}
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
122 inline bool Foam::keyType::isLiteral() const
123 {
124  return (type_ != option::REGEX);
125 }
126 
127 
128 inline bool Foam::keyType::isPattern() const
129 {
130  return (type_ & option::REGEX);
131 }
132 
133 
134 inline void Foam::keyType::setType(option opt, bool adjust)
135 {
136  opt = option(opt & 0x0F);
137 
138  if (type_ != opt)
139  {
140  // Only strip when debug is active (potentially costly operation)
141  if (isPattern() && adjust && word::debug)
142  {
143  string::stripInvalid<word>(*this);
144  }
145 
146  type_ = opt;
147  }
148 }
149 
150 
152 {
153  type_ = option::REGEX;
154  return true;
155 }
156 
157 
158 inline void Foam::keyType::uncompile(bool adjust)
159 {
160  setType(option::LITERAL, adjust);
161 }
162 
163 
164 inline void Foam::keyType::clear()
165 {
166  word::clear();
167  type_ = option::LITERAL;
168 }
169 
170 
172 {
173  if (this == &s)
174  {
175  return; // Self-swap is a no-op
176  }
177 
178  word::swap(static_cast<word&>(s));
179  std::swap(type_, s.type_);
180 }
181 
182 
183 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
184 
185 inline bool Foam::keyType::operator()(const std::string& text) const
186 {
187  return match(text); // Use smart match
188 }
189 
190 
191 inline void Foam::keyType::operator=(const keyType& s)
192 {
193  if (this == &s)
194  {
195  return; // Self-assignment is a no-op
196  }
197 
198  assign(s); // Bypasses char checking
199  type_ = s.type_;
200 }
201 
202 
203 inline void Foam::keyType::operator=(keyType&& s)
204 {
205  if (this == &s)
206  {
207  return; // Self-assignment is a no-op
208  }
209 
210  clear();
211  swap(s);
212 }
213 
214 
215 inline void Foam::keyType::operator=(const word& s)
216 {
217  assign(s); // Bypasses char checking
218  type_ = option::LITERAL;
219 }
220 
221 
222 inline void Foam::keyType::operator=(const string& s)
223 {
224  assign(s); // Bypasses char checking
225  type_ = option::REGEX;
226 }
227 
228 
229 inline void Foam::keyType::operator=(const char* s)
230 {
231  assign(s); // Bypasses char checking
232  type_ = option::LITERAL;
233 }
234 
235 
236 // ************************************************************************* //
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::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:60
Foam::word::debug
static int debug
Debugging.
Definition: word.H:74
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::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:75
clear
patchWriters clear()
Foam::keyType::uncompile
void uncompile(bool adjust=false)
Mark as literal, instead of a regular expression.
Definition: keyTypeI.H:158
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::string::swap
void swap(std::string &str)
Swap contents. Self-swapping is a no-op.
Definition: stringI.H:266
Foam::FieldOps::assign
void assign(Field< Tout > &result, const Field< T1 > &a, const UnaryOp &op)
Populate a field as the result of a unary operation on an input.
Definition: FieldOps.C:35
Foam::isspace
bool isspace(char c)
Test for horizontal whitespace.
Definition: char.H:63
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