primitiveEntry.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-2020 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
27Class
28 Foam::primitiveEntry
29
30Description
31 A keyword and a list of tokens comprise a primitiveEntry.
32 A primitiveEntry can be read, written and printed, and the types and
33 values of its tokens analysed.
34
35 A primitiveEntry is a high-level building block for data description.
36 It is a front-end for the token parser. A list of entries can be used
37 as a set of keyword syntax elements, for example.
38
39SourceFiles
40 primitiveEntry.C
41 primitiveEntryIO.C
42
43\*---------------------------------------------------------------------------*/
44
45#ifndef primitiveEntry_H
46#define primitiveEntry_H
47
48#include "entry.H"
49#include "ITstream.H"
50#include "InfoProxy.H"
51
52// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53
54namespace Foam
55{
56
57// Forward Declarations
58class dictionary;
59
60/*---------------------------------------------------------------------------*\
61 Class primitiveEntry Declaration
62\*---------------------------------------------------------------------------*/
65:
66 public entry,
67 public ITstream
68{
69 // Private Member Functions
70
71 //- Test if token is acceptable after filtering for function entries
72 //- and variable expansions.
73 bool acceptToken
74 (
75 const token& tok,
76 const dictionary& dict,
77 Istream& is
78 );
79
80 //- Expand the given variable.
81 // The keyword starts with '$', but has been removed by the caller
82 // and thus passed as a varName.
83 // Keywords with '${}' are expanded recursively.
84 bool expandVariable
85 (
86 const string& varName,
87 const dictionary& dict
88 );
89
90 //- Expand the given function.
91 // The keyword starts with '#', but has been removed by the caller.
92 // and thus passed as a functionName.
93 bool expandFunction
94 (
95 const word& functionName,
96 const dictionary& dict,
97 Istream& is
98 );
99
100 //- Read the complete entry from the given stream
101 void readEntry(const dictionary& dict, Istream& is);
102
103
104public:
105
106 // Constructors
107
108 //- Construct from keyword and no tokens.
109 // Contents to be filled with a later assignment
110 explicit primitiveEntry(const keyType& key);
111
112 //- Construct from keyword and a single token
113 primitiveEntry(const keyType& key, const token& tok);
114
115 //- Construct from keyword and a list of tokens
116 primitiveEntry(const keyType& key, const UList<token>& tokens);
117
118 //- Construct from keyword and by transferring a list of tokens
119 primitiveEntry(const keyType& key, List<token>&& tokens);
120
121 //- Construct from keyword and ITstream tokens
122 primitiveEntry(const keyType& key, const ITstream& is);
123
124 //- Construct from keyword and Istream
125 primitiveEntry(const keyType& key, Istream& is);
126
127 //- Construct from keyword, parent dictionary and Istream
128 primitiveEntry(const keyType& key, const dictionary& dict, Istream& is);
129
130 //- Construct from keyword and a value. Uses string stream serialization
131 template<class T>
132 primitiveEntry(const keyType& key, const T& val);
133
134 //- Clone the entry
135 autoPtr<entry> clone(const dictionary&) const
136 {
137 return autoPtr<entry>(new primitiveEntry(*this));
138 }
139
140
141 // Member Functions
142
143 //- Inherit read from ITstream
144 using ITstream::read;
145
146 //- Return the token stream name
147 virtual const fileName& name() const
148 {
149 return ITstream::name();
150 }
151
152 //- Return token stream name for modification
153 virtual fileName& name()
154 {
155 return ITstream::name();
156 }
157
158 //- Return token stream name relative to the current case
159 virtual fileName relativeName() const
160 {
161 return ITstream::relativeName();
162 }
163
164 //- Return line number of first token in dictionary
165 virtual label startLineNumber() const;
166
167 //- Return line number of last token in dictionary
168 virtual label endLineNumber() const;
169
170 //- Return true - this entry is a stream
171 virtual bool isStream() const noexcept
172 {
173 return true;
174 }
175
176 //- Return token stream for this primitive entry
177 virtual ITstream& stream() const;
178
179 //- This entry is not a dictionary,
180 // calling this function generates a FatalError
181 virtual const dictionary& dict() const;
182
183 //- This entry is not a dictionary,
184 // calling this function generates a FatalError
185 virtual dictionary& dict();
186
187 //- Read tokens from the given stream
188 virtual bool read(const dictionary& dict, Istream& is);
189
190 //- Write
191 virtual void write(Ostream& os) const;
192
193 //- Write, optionally with contents only (no keyword, etc)
194 void write(Ostream& os, const bool contentsOnly) const;
195
196 //- Return info proxy.
197 // Used to print token information to a stream
199 {
200 return *this;
201 }
202};
203
204
205template<>
206Ostream& operator<<(Ostream& os, const InfoProxy<primitiveEntry>& ip);
207
208
209// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210
211} // End namespace Foam
212
213// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214
215#ifdef NoRepository
217#endif
218
219// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220
221#endif
222
223// ************************************************************************* //
An input stream of tokens.
Definition: ITstream.H:56
virtual const fileName & name() const
Get the name of the stream.
Definition: ITstream.H:235
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual bool read()
Re-read model coefficients if they have changed.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
virtual fileName relativeName() const
Return scoped dictionary name relative to the current case.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
virtual autoPtr< entry > clone() const
Construct on freestore as copy.
Definition: entry.C:83
A class for handling file names.
Definition: fileName.H:76
A class for handling keywords in dictionaries.
Definition: keyType.H:71
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read,...
virtual fileName & name()
Return token stream name for modification.
InfoProxy< primitiveEntry > info() const
Return info proxy.
virtual fileName relativeName() const
Return token stream name relative to the current case.
virtual const fileName & name() const
Return the token stream name.
virtual bool isStream() const noexcept
Return true - this entry is a stream.
virtual bool read(const dictionary &dict, Istream &is)
Read tokens from the given stream.
autoPtr< entry > clone(const dictionary &) const
Clone the entry.
virtual label endLineNumber() const
Return line number of last token in dictionary.
virtual ITstream & stream() const
Return token stream for this primitive entry.
virtual const dictionary & dict() const
This entry is not a dictionary,.
virtual label startLineNumber() const
Return line number of first token in dictionary.
A token holds an item read from Istream.
Definition: token.H:69
A class for handling words, derived from Foam::string.
Definition: word.H:68
const volScalarField & T
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
const direction noexcept
Definition: Scalar.H:223
runTime write()