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-2019 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  //- Enumeration of the keyword types
72  enum type
73  {
74  UNDEFINED,
75  WORD,
76  FUNCTIONNAME,
77  VARIABLE,
78  PATTERN
79  };
80 
81 
82  // Private Data
83 
84  //- The type of this keyword
85  type type_;
86 
87 
88 public:
89 
90  // Static Data Members
91 
92  //- An empty keyType
93  static const keyType null;
94 
95 
96  // Constructors
97 
98  //- Construct null
99  inline keyType();
100 
101  //- Copy constructor
102  inline keyType(const keyType&);
103 
104  //- Construct as word
105  inline keyType(const word&);
106 
107  //- Construct as functionName
108  inline explicit keyType(const functionName&);
109 
110  //- Construct as variable
111  inline explicit keyType(const variable&);
112 
113  //- Construct as pattern
114  inline explicit keyType(const string&);
115 
116  //- Construct as word from character array.
117  inline keyType(const char*);
118 
119  //- Construct from token
120  explicit keyType(const token&);
121 
122  //- Construct from Istream
123  explicit keyType(Istream&);
124 
125 
126  // Member Functions
127 
128  //- Return true if the type has not been defined
129  inline bool isUndefined() const;
130 
131  //- Return true if the keyword is a functionName
132  inline bool isFunctionName() const;
133 
134  //- Return true if the keyword is a variable
135  inline bool isVariable() const;
136 
137  //- Should be treated as a match rather than a literal string
138  inline bool isPattern() const;
139 
140  //- Smart match as regular expression or as a string
141  // Optionally force a literal match only
142  bool match(const std::string&, bool literalMatch=false) const;
143 
144 
145  // Member Operators
146 
147  // Assignment
148 
149  //- Assignment operator
150  inline void operator=(const keyType&);
151 
152  //- Assign as functionName
153  inline void operator=(const functionName&);
154 
155  //- Assign as variable
156  inline void operator=(const variable&);
157 
158  //- Assign as word
159  inline void operator=(const word&);
160 
161  //- Assign as pattern
162  inline void operator=(const string&);
163 
164  //- Assign as word
165  inline void operator=(const char*);
166 
167  //- Disallow assignments where we cannot determine string/word type
168  void operator=(const std::string&) = delete;
169 
170  //- Assign from token setting the appropriate type
171  void operator=(const token&);
172 
173 
174  // IOstream Operators
175 
177  friend Ostream& operator<<(Ostream&, const keyType&);
178 };
179 
180 
181 //- Write the keyword to the Ostream with the current level of indentation
182 Ostream& writeKeyword(Foam::Ostream& os, const keyType& kw);
183 
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 } // End namespace Foam
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 #include "keyTypeI.H"
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
196 
197 // ************************************************************************* //
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
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
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:73
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:62
Namespace for OpenFOAM.
Istream & operator>>(Istream &, pistonPointEdgeData &)
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