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