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-2020 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  autoPtr<entry> clone(const dictionary&) const
110  {
111  return autoPtr<entry>(new primitiveEntry(*this));
112  }
113 
114 
115  // Member Functions
116 
117  //- Inherit read from ITstream
118  using ITstream::read;
119 
120  //- Return the dictionary name
121  const fileName& name() const
122  {
123  return ITstream::name();
124  }
125 
126  //- Return the dictionary name
127  fileName& name()
128  {
129  return ITstream::name();
130  }
131 
132  //- Return line number of first token in dictionary
133  label startLineNumber() const;
134 
135  //- Return line number of last token in dictionary
136  label endLineNumber() const;
137 
138  //- Return true because this entry is a stream
139  bool isStream() const
140  {
141  return true;
142  }
143 
144  //- Return token stream if this entry is a primitive entry
145  ITstream& stream() const;
146 
147  //- This entry is not a dictionary,
148  // calling this function generates a FatalError
149  const dictionary& dict() const;
150 
151  //- This entry is not a dictionary,
152  // calling this function generates a FatalError
153  dictionary& dict();
154 
155  //- Read tokens from the given stream
156  virtual bool read(const dictionary&, Istream&);
157 
158  //- Write
159  void write(Ostream&) const;
160 
161  //- Write, optionally with contents only (no keyword, etc)
162  void write(Ostream&, const bool contentsOnly) const;
163 
164  //- Return info proxy.
165  // Used to print token information to a stream
167  {
168  return *this;
169  }
170 };
171 
172 
173 template<>
174 Ostream& operator<<(Ostream&, const InfoProxy<primitiveEntry>&);
175 
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 } // End namespace Foam
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #ifdef NoRepository
184  #include "primitiveEntryTemplates.C"
185 #endif
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #endif
190 
191 // ************************************************************************* //
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:128
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 keyword definitions, which are a keyword followed by any number of values (e....
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:54
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.
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.
label startLineNumber() const
Return line number of first token in dictionary.
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
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)