primitiveEntry.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-2025 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::primitiveEntry
26 
27 Description
28  A keyword and a list of tokens is a 'primitiveEntry'.
29  An primitiveEntry can be read, written and printed, and the types and
30  values of its tokens analysed.
31 
32  A primitiveEntry is a high-level building block for data description. It
33  is a front-end for the token parser. A list of entries can be used as a
34  set of keyword syntax elements, for example.
35 
36 SourceFiles
37  primitiveEntry.C
38  primitiveEntryIO.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef primitiveEntry_H
43 #define primitiveEntry_H
44 
45 #include "entry.H"
46 #include "ITstream.H"
47 #include "InfoProxy.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 class dictionary;
55 
56 /*---------------------------------------------------------------------------*\
57  Class primitiveEntry Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 class primitiveEntry
61 :
62  public entry,
63  public ITstream
64 {
65  // Private Member Functions
66 
67  //- Append the given tokens starting at the current tokenIndex
68  void append(const UList<token>&);
69 
70  //- Append the given token to this entry
71  void append(const token& currToken, const dictionary&, Istream&);
72 
73  //- Expand the given variable
74  bool expandVariable(const variable&, const dictionary&);
75 
76  //- Expand the given function (keyword starts with #)
77  bool expandFunction(const functionName&, const dictionary&, Istream&);
78 
79  //- Read the complete entry from the given stream
80  void readEntry(const dictionary&, Istream&);
81 
82  friend class functionEntry;
83 
84 
85 public:
86 
87  // Constructors
88 
89  //- Construct from line number and keyword
90  primitiveEntry(const label keyLineNumber, const keyType& key);
91 
92  //- Construct from keyword and a Istream
93  primitiveEntry(const keyType&, Istream&);
94 
95  //- Construct from keyword, parent dictionary and Istream
96  primitiveEntry(const keyType&, const dictionary& parentDict, Istream&);
97 
98  //- Construct from keyword and a ITstream
99  primitiveEntry(const keyType& key, const ITstream&);
100 
101  //- Construct from keyword, line number and ITstream
103  (
104  const label keyLineNumber,
105  const keyType& key,
106  const ITstream&
107  );
108 
109  //- Construct from keyword and a single token
110  primitiveEntry(const keyType&, const token&);
111 
112  //- Construct from keyword and a list of tokens
113  primitiveEntry(const keyType&, const UList<token>&);
114 
115  //- Construct from keyword and a list of tokens
116  primitiveEntry(const keyType&, const List<token>&);
117 
118  //- Move construct from keyword and by transferring a list of tokens
120 
121  //- Construct from keyword and a T
122  template<class T>
123  primitiveEntry(const keyType&, const T&);
124 
125  //- Construct from keyword and a T and start and end line numbers
126  template<class T>
128  (
129  const keyType&,
130  const T&,
131  const label startLineNumber,
132  const label endLineNumber = -1
133  );
134 
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 dictionary name
147  const fileName& name() const
148  {
149  return ITstream::name();
150  }
151 
152  //- Return the dictionary name
153  fileName& name()
154  {
155  return ITstream::name();
156  }
157 
158  //- Return line number of last token in dictionary
159  virtual label endLineNumber() const;
160 
161  //- Return true because this entry is a stream
162  bool isStream() const
163  {
164  return true;
165  }
166 
167  //- Return token stream if this entry is a primitive entry
168  ITstream& stream() const;
169 
170  //- This entry is not a dictionary,
171  // calling this function generates a FatalError
172  const dictionary& dict() const;
173 
174  //- This entry is not a dictionary,
175  // calling this function generates a FatalError
176  dictionary& dict();
177 
178  //- Read tokens from the given stream
179  virtual bool read(const dictionary&, Istream&);
180 
181  //- Write
182  void write(Ostream&) const;
183 
184  //- Write, optionally with contents only (no keyword, etc)
185  void write(Ostream&, const bool contentsOnly) const;
186 
187  //- Return info proxy.
188  // Used to print token information to a stream
190  {
191  return *this;
192  }
193 };
194 
195 
196 template<>
197 Ostream& operator<<(Ostream&, const InfoProxy<primitiveEntry>&);
198 
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 } // End namespace Foam
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 #ifdef NoRepository
207  #include "primitiveEntryTemplates.C"
208 #endif
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 #endif
213 
214 // ************************************************************************* //
Input token stream.
Definition: ITstream.H:56
virtual Istream & read(token &)
Return next token from stream.
Definition: ITstream.C:56
const fileName & name() const
Return the name of the stream.
Definition: ITstream.H:169
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:50
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
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:74
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:68
virtual autoPtr< entry > clone() const
Construct on freestore as copy.
Definition: entry.C:56
virtual label startLineNumber() const
Return line number of keyword of the entry.
Definition: entry.H:154
A class for handling file names.
Definition: fileName.H:82
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:66
A functionName is a word starting with '#'.
Definition: functionName.H:60
A class for handling keywords in dictionaries.
Definition: keyType.H:69
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read,...
bool isStream() const
Return true because this entry is a stream.
void write(Ostream &) const
Write.
InfoProxy< primitiveEntry > info() const
Return info proxy.
virtual Istream & read(token &)
Inherit read from ITstream.
Definition: ITstream.C:56
virtual label endLineNumber() const
Return line number of last token in dictionary.
ITstream & stream() const
Return token stream if this entry is a primitive entry.
const dictionary & dict() const
This entry is not a dictionary,.
const fileName & name() const
Return the dictionary name.
primitiveEntry(const label keyLineNumber, const keyType &key)
Construct from line number and keyword.
A token holds items read from Istream.
Definition: token.H:74
A variable is a word with support for additional characters, in particular '$' and '/'.
Definition: variable.H:61
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
void T(GeometricField< Type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf1)