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-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
30
31inline bool Foam::keyType::valid(const char c)
32{
33 // Also accept '{' and '}' (for regex grouping?)
34 return (word::valid(c) || c == '{' || c == '}');
35}
36
37
38// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39
41:
42 word(),
43 type_(option::LITERAL)
44{}
45
46
47inline Foam::keyType::keyType(const word& str)
48:
49 word(str),
50 type_(option::LITERAL)
51{}
52
53
55:
56 word(std::move(str)),
57 type_(option::LITERAL)
58{}
59
60
61inline Foam::keyType::keyType(const string& str)
62:
63 word(str, false), // No stripping
64 type_(option::REGEX)
65{}
66
67
68inline Foam::keyType::keyType(string&& str)
69:
70 word(std::move(str), false), // No stripping
71 type_(option::REGEX)
72{}
73
74
75inline Foam::keyType::keyType(const std::string& str, option opt)
76:
77 word(str, false), // No stripping
78 type_(option(opt & 0x0F))
79{}
80
81
82inline Foam::keyType::keyType(std::string&& str, option opt)
83:
84 word(std::move(str), false), // No stripping
85 type_(option(opt & 0x0F))
86{}
87
88
89inline Foam::keyType::keyType(const char* str, option opt)
90:
91 word(str, false), // No stripping
92 type_(option(opt & 0x0F))
93{}
94
95
96// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97
99{
100 return !(type_ & option::REGEX);
101}
102
103
105{
106 return (type_ & option::REGEX);
107}
108
109
110inline void Foam::keyType::setType(option opt, bool adjust)
111{
112 opt = option(opt & 0x0F);
113
114 if (type_ != opt)
115 {
116 // Only strip when debug is active (potentially costly operation)
117 if (adjust && isPattern() && word::debug)
118 {
119 string::stripInvalid<word>(*this);
120 }
121
122 type_ = opt;
123 }
124}
125
126
128{
129 type_ = option::REGEX;
130 return true;
131}
132
133
135{
136 type_ = option::LITERAL;
137}
138
139
140inline void Foam::keyType::uncompile(bool adjust)
141{
142 // Only strip when debug is active (potentially costly operation)
143 if (adjust && isPattern() && word::debug)
144 {
145 string::stripInvalid<word>(*this);
146 }
147
148 type_ = option::LITERAL;
149}
150
151
153{
154 word::clear();
155 type_ = option::LITERAL;
156}
157
158
159// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
160
161inline bool Foam::keyType::operator()(const std::string& text) const
162{
163 return match(text); // Use smart match
164}
165
166
167inline void Foam::keyType::operator=(const keyType& str)
168{
169 if (this == &str)
170 {
171 return; // Self-assignment is a no-op
172 }
173
174 assign(str); // Bypasses char checking
175 type_ = str.type_;
176}
177
178
180{
181 if (this == &str)
182 {
183 return; // Self-assignment is a no-op
184 }
185
186 clear();
187 swap(str);
188}
189
190
191inline void Foam::keyType::operator=(const char* str)
192{
193 assign(str); // Bypasses char checking
194 type_ = option::LITERAL;
195}
196
197
198inline void Foam::keyType::operator=(const word& str)
199{
200 assign(str); // Bypasses char checking
201 type_ = option::LITERAL;
202}
203
204
205inline void Foam::keyType::operator=(const string& str)
206{
207 assign(str); // Bypasses char checking
208 type_ = option::REGEX;
209}
210
211
212// ************************************************************************* //
bool valid() const
True if all internal ids are non-negative.
Ostream & operator()() const
Output stream (master only).
Definition: ensightCaseI.H:74
A class for handling keywords in dictionaries.
Definition: keyType.H:71
option
Enumeration for the data type and search/match modes (bitmask)
Definition: keyType.H:79
bool isLiteral() const noexcept
The keyType is treated as literal, not as pattern.
Definition: keyTypeI.H:98
bool compile() noexcept
Mark as regular expression.
Definition: keyTypeI.H:127
void uncompile() noexcept
Mark as literal string.
Definition: keyTypeI.H:134
keyType()
Default construct, empty literal.
Definition: keyTypeI.H:40
bool isPattern() const noexcept
The keyType is treated as a pattern, not as literal string.
Definition: keyTypeI.H:104
void clear()
Clear string and set as literal.
Definition: keyTypeI.H:152
void operator=(const std::string &)=delete
No assignment where type could be indeterminate.
virtual topoSetSource::sourceType setType() const
The source category is a cellSet.
A class for handling words, derived from Foam::string.
Definition: word.H:68
static int debug
Debugging.
Definition: word.H:77
patchWriters clear()
const direction noexcept
Definition: Scalar.H:223