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