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 
83 public:
84 
85  // Constructors
86 
87  //- Construct from keyword and a Istream
88  primitiveEntry(const keyType&, Istream&);
89 
90  //- Construct from keyword, parent dictionary and Istream
91  primitiveEntry(const keyType&, const dictionary& parentDict, Istream&);
92 
93  //- Construct from keyword and a ITstream
94  primitiveEntry(const keyType&, const ITstream&);
95 
96  //- Construct from keyword and a single token
97  primitiveEntry(const keyType&, const token&);
98 
99  //- Construct from keyword and a list of tokens
100  primitiveEntry(const keyType&, const UList<token>&);
101 
102  //- Move construct from keyword and by transferring a list of tokens
104 
105  //- Construct from keyword and a T
106  template<class T>
107  primitiveEntry(const keyType&, const T&);
108 
109  //- Construct from keyword and a T and start and end line numbers
110  template<class T>
112  (
113  const keyType&,
114  const T&,
115  const label startLineNumber,
116  const label endLineNumber = -1
117  );
118 
119  autoPtr<entry> clone(const dictionary&) const
120  {
121  return autoPtr<entry>(new primitiveEntry(*this));
122  }
123 
124 
125  // Member Functions
126 
127  //- Inherit read from ITstream
128  using ITstream::read;
129 
130  //- Return the dictionary name
131  const fileName& name() const
132  {
133  return ITstream::name();
134  }
135 
136  //- Return the dictionary name
137  fileName& name()
138  {
139  return ITstream::name();
140  }
141 
142  //- Return line number of last token in dictionary
143  virtual label endLineNumber() const;
144 
145  //- Return true because this entry is a stream
146  bool isStream() const
147  {
148  return true;
149  }
150 
151  //- Return token stream if this entry is a primitive entry
152  ITstream& stream() const;
153 
154  //- This entry is not a dictionary,
155  // calling this function generates a FatalError
156  const dictionary& dict() const;
157 
158  //- This entry is not a dictionary,
159  // calling this function generates a FatalError
160  dictionary& dict();
161 
162  //- Read tokens from the given stream
163  virtual bool read(const dictionary&, Istream&);
164 
165  //- Write
166  void write(Ostream&) const;
167 
168  //- Write, optionally with contents only (no keyword, etc)
169  void write(Ostream&, const bool contentsOnly) const;
170 
171  //- Return info proxy.
172  // Used to print token information to a stream
174  {
175  return *this;
176  }
177 };
178 
179 
180 template<>
181 Ostream& operator<<(Ostream&, const InfoProxy<primitiveEntry>&);
182 
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 } // End namespace Foam
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 #ifdef NoRepository
191  #include "primitiveEntryTemplates.C"
192 #endif
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #endif
197 
198 // ************************************************************************* //
Input token stream.
Definition: ITstream.H:53
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:130
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 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
primitiveEntry(const keyType &, Istream &)
Construct from keyword and a Istream.
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.
A token holds items read from Istream.
Definition: token.H:73
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
void T(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)