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 | Copyright (C) 2011 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 "word.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward declaration of classes
49 class Istream;
50 class Ostream;
51 
52 
53 /*---------------------------------------------------------------------------*\
54  Class keyType Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 class keyType
58 :
59  public word
60 {
61  // Private data
62 
63  //- Is the keyType a pattern (regular expression)
64  bool isPattern_;
65 
66  // Private Member Functions
67 
68  //- Disallow assignments where we cannot determine string/word type
69  void operator=(const std::string&);
70 
71 public:
72 
73  // Static data members
74 
75  //- An empty keyType
76  static const keyType null;
77 
78 
79  // Constructors
80 
81  //- Construct null
82  inline keyType();
83 
84  //- Construct as copy
85  inline keyType(const keyType&);
86 
87  //- Construct as copy of word. Not treated as a regular expression
88  inline keyType(const word&);
89 
90  //- Construct as copy of string. Treat as regular expression.
91  inline keyType(const string&);
92 
93  //- Construct as copy of character array.
94  // Not treated as a regular expression
95  inline keyType(const char*);
96 
97  //- Construct as copy of std::string with specified treatment
98  inline keyType(const std::string&, const bool isPattern);
99 
100  //- Construct from Istream
101  // Treat as regular expression if surrounded by quotation marks.
102  keyType(Istream&);
103 
104 
105  // Member functions
106 
107  //- Should be treated as a match rather than a literal string
108  inline bool isPattern() const;
109 
110  //- Smart match as regular expression or as a string
111  // Optionally force a literal match only
112  bool match(const std::string&, bool literalMatch=false) const;
113 
114  // Member operators
115 
116  // Assignment
117 
118  //- Assignment operator
119  inline const keyType& operator=(const keyType&);
120 
121  //- Assign as word, not as non regular expression
122  inline const keyType& operator=(const word&);
123 
124  //- Assign as regular expression
125  inline const keyType& operator=(const string&);
126 
127  //- Assign as word, not as non regular expression
128  inline const keyType& operator=(const char*);
129 
130 
131  // IOstream operators
132 
133  friend Istream& operator>>(Istream&, keyType&);
134  friend Ostream& operator<<(Ostream&, const keyType&);
135 };
136 
137 
138 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 
140 } // End namespace Foam
141 
142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 
144 #include "keyTypeI.H"
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 #endif
149 
150 // ************************************************************************* //
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::keyType::keyType
keyType()
Construct null.
Definition: keyTypeI.H:28
Foam::keyType::isPattern
bool isPattern() const
Should be treated as a match rather than a literal string.
Definition: keyTypeI.H:76
Foam::keyType::isPattern_
bool isPattern_
Is the keyType a pattern (regular expression)
Definition: keyType.H:63
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:56
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::keyType::operator=
void operator=(const std::string &)
Disallow assignments where we cannot determine string/word type.
Foam::keyType::operator<<
friend Ostream & operator<<(Ostream &, const keyType &)
keyTypeI.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::keyType::operator>>
friend Istream & operator>>(Istream &, keyType &)
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
word.H
Foam::keyType::match
bool match(const std::string &, bool literalMatch=false) const
Smart match as regular expression or as a string.
Definition: keyType.C:52