keyType.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::keyType
26 
27 Description
28  A class for handling keywords in dictionaries.
29 
30  A keyType is the keyword of a dictionary.
31  It differs from word in that it accepts patterns (regular expressions).
32 
33 SourceFiles
34  keyType.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef keyType_H
39 #define keyType_H
40 
41 #include "functionName.H"
42 #include "variable.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward declaration of classes
50 class Istream;
51 class Ostream;
52 class token;
53 
54 
55 // Forward declaration of friend functions and operators
56 
57 class keyType;
58 
59 Istream& operator>>(Istream&, keyType&);
60 Ostream& operator<<(Ostream&, const keyType&);
61 
62 
63 /*---------------------------------------------------------------------------*\
64  Class keyType Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 class keyType
68 :
69  public variable
70 {
71 public:
72 
73  //- Enumeration of the keyword types
74  enum type
75  {
79  VARIABLE,
81  };
82 
83 
84 private:
85 
86  // Private Data
87 
88  //- The type of this keyword
89  type type_;
90 
91 
92 public:
93 
94  // Static Data Members
95 
96  //- An empty keyType
97  static const keyType null;
98 
99 
100  // Constructors
101 
102  //- Construct null
103  inline keyType();
104 
105  //- Copy constructor
106  inline keyType(const keyType&);
107 
108  //- Construct as word
109  inline keyType(const word&);
110 
111  //- Construct as functionName
112  inline keyType(const functionName&);
113 
114  //- Construct as variable
115  inline keyType(const variable&);
116 
117  //- Construct as pattern
118  inline keyType(const string&);
119 
120  //- Construct as word from character array.
121  inline keyType(const char*);
122 
123  //- Construct from token
124  explicit keyType(const token&);
125 
126  //- Construct from Istream
127  explicit keyType(Istream&);
128 
129 
130  // Member Functions
131 
132  inline type Type() const
133  {
134  return type_;
135  }
136 
137  //- Return true if the type has not been defined
138  inline bool isUndefined() const;
139 
140  //- Return true if the keyword is a functionName
141  inline bool isFunctionName() const;
142 
143  //- Return true if the keyword is a variable
144  inline bool isVariable() const;
145 
146  //- Should be treated as a match rather than a literal string
147  inline bool isPattern() const;
148 
149  //- Smart match as regular expression or as a string
150  // Optionally force a literal match only
151  bool match(const std::string&, bool literalMatch=false) const;
152 
153 
154  // Member Operators
155 
156  // Assignment
157 
158  //- Assignment operator
159  inline void operator=(const keyType&);
160 
161  //- Assign as functionName
162  inline void operator=(const functionName&);
163 
164  //- Assign as variable
165  inline void operator=(const variable&);
166 
167  //- Assign as word
168  inline void operator=(const word&);
169 
170  //- Assign as pattern
171  inline void operator=(const string&);
172 
173  //- Assign as word
174  inline void operator=(const char*);
175 
176  //- Disallow assignments where we cannot determine string/word type
177  void operator=(const std::string&) = delete;
178 
179  //- Assign from token setting the appropriate type
180  void operator=(const token&);
181 
182 
183  // IOstream Operators
184 
186  friend Ostream& operator<<(Ostream&, const keyType&);
187 };
188 
189 
190 //- Write the keyword to the Ostream with the current level of indentation
191 Ostream& writeKeyword(Foam::Ostream& os, const keyType& kw);
192 
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 } // End namespace Foam
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 #include "keyTypeI.H"
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 #endif
205 
206 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A functionName is a word starting with '#'.
Definition: functionName.H:60
A class for handling keywords in dictionaries.
Definition: keyType.H:69
bool isPattern() const
Should be treated as a match rather than a literal string.
Definition: keyTypeI.H:97
type Type() const
Definition: keyType.H:131
friend Ostream & operator<<(Ostream &, const keyType &)
friend Istream & operator>>(Istream &, keyType &)
bool isVariable() const
Return true if the keyword is a variable.
Definition: keyTypeI.H:91
void operator=(const keyType &)
Assignment operator.
Definition: keyTypeI.H:105
type
Enumeration of the keyword types.
Definition: keyType.H:74
@ FUNCTIONNAME
Definition: keyType.H:77
bool isFunctionName() const
Return true if the keyword is a functionName.
Definition: keyTypeI.H:85
keyType()
Construct null.
Definition: keyTypeI.H:28
bool isUndefined() const
Return true if the type has not been defined.
Definition: keyTypeI.H:79
bool match(const std::string &, bool literalMatch=false) const
Smart match as regular expression or as a string.
Definition: keyType.C:58
A token holds items read from Istream.
Definition: token.H:74
A variable is a word with support for additional characters, in particular '$' and '/'.
Definition: variable.H:61
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.
Istream & operator>>(Istream &, pointEdgeDist &)
Definition: pointEdgeDist.C:41
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
Ostream & writeKeyword(Foam::Ostream &os, const keyType &kw)
Write the keyword to the Ostream with the current level of indentation.
Definition: keyType.C:155