All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2019 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 "IStringStream.H"
46 #include "OStringStream.H"
47 
48 #include "entry.H"
49 #include "ITstream.H"
50 #include "InfoProxy.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 class dictionary;
58 
59 /*---------------------------------------------------------------------------*\
60  Class primitiveEntry Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class primitiveEntry
64 :
65  public entry,
66  public ITstream
67 {
68  // Private Member Functions
69 
70  //- Append the given tokens starting at the current tokenIndex
71  void append(const UList<token>&);
72 
73  //- Append the given token to this entry
74  void append(const token& currToken, const dictionary&, Istream&);
75 
76  //- Expand the given variable
77  bool expandVariable(const variable&, const dictionary&);
78 
79  //- Expand the given function (keyword starts with #)
80  bool expandFunction(const functionName&, const dictionary&, Istream&);
81 
82  //- Read the complete entry from the given stream
83  void readEntry(const dictionary&, Istream&);
84 
85 
86 public:
87 
88  // Constructors
89 
90  //- Construct from keyword and a Istream
91  primitiveEntry(const keyType&, Istream&);
92 
93  //- Construct from keyword, parent dictionary and Istream
94  primitiveEntry(const keyType&, const dictionary& parentDict, Istream&);
95 
96  //- Construct from keyword and a ITstream
97  primitiveEntry(const keyType&, const ITstream&);
98 
99  //- Construct from keyword and a single token
100  primitiveEntry(const keyType&, const token&);
101 
102  //- Construct from keyword and a list of tokens
103  primitiveEntry(const keyType&, const UList<token>&);
104 
105  //- Move construct from keyword and by transferring a list of tokens
107 
108  //- Construct from keyword and a T
109  template<class T>
110  primitiveEntry(const keyType&, const T&);
112  autoPtr<entry> clone(const dictionary&) const
113  {
114  return autoPtr<entry>(new primitiveEntry(*this));
115  }
116 
117 
118  // Member Functions
119 
120  //- Inherit read from ITstream
121  using ITstream::read;
122 
123  //- Return the dictionary name
124  const fileName& name() const
125  {
126  return ITstream::name();
127  }
128 
129  //- Return the dictionary name
130  fileName& name()
131  {
132  return ITstream::name();
133  }
134 
135  //- Return line number of first token in dictionary
136  label startLineNumber() const;
137 
138  //- Return line number of last token in dictionary
139  label endLineNumber() const;
140 
141  //- Return true because this entry is a stream
142  bool isStream() const
143  {
144  return true;
145  }
146 
147  //- Return token stream if this entry is a primitive entry
148  ITstream& stream() const;
149 
150  //- This entry is not a dictionary,
151  // calling this function generates a FatalError
152  const dictionary& dict() const;
153 
154  //- This entry is not a dictionary,
155  // calling this function generates a FatalError
156  dictionary& dict();
157 
158  //- Read tokens from the given stream
159  virtual bool read(const dictionary&, Istream&);
160 
161  //- Write
162  void write(Ostream&) const;
163 
164  //- Write, optionally with contents only (no keyword, etc)
165  void write(Ostream&, const bool contentsOnly) const;
166 
167  //- Return info proxy.
168  // Used to print token information to a stream
170  {
171  return *this;
172  }
173 };
174 
175 
176 template<>
177 Ostream& operator<<(Ostream&, const InfoProxy<primitiveEntry>&);
178 
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 } // End namespace Foam
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 #ifdef NoRepository
187  #include "primitiveEntryTemplates.C"
188 #endif
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 #endif
193 
194 // ************************************************************************* //
const fileName & name() const
Return the name of the stream.
Definition: ITstream.H:128
A class for handling keywords in dictionaries.
Definition: keyType.H:66
void write(Ostream &) const
Write.
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
A class for handling file names.
Definition: fileName.H:79
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
InfoProxy< primitiveEntry > info() const
Return info proxy.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
label endLineNumber() const
Return line number of last token in dictionary.
A token holds items read from Istream.
Definition: token.H:72
virtual Istream & read(token &)
Return next token from stream.
Definition: ITstream.C:56
A keyword and a list of tokens is a &#39;primitiveEntry&#39;. An primitiveEntry can be read, written and printed, and the types and values of its tokens analysed.
A functionName is a word starting with &#39;#&#39;.
Definition: functionName.H:57
ITstream & stream() const
Return token stream if this entry is a 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:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
const dictionary & dict() const
This entry is not a dictionary,.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
virtual autoPtr< entry > clone() const
Construct on freestore as copy.
Definition: entry.C:54
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:45
label startLineNumber() const
Return line number of first token in dictionary.
primitiveEntry(const keyType &, Istream &)
Construct from keyword and a Istream.
const fileName & name() const
Return the dictionary name.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
virtual bool read(const dictionary &, Istream &)
Read tokens from the given stream.
bool isStream() const
Return true because this entry is a stream.
A variable is a word with support for additional characters, in particular &#39;$&#39; and &#39;/&#39;...
Definition: variable.H:58
Input token stream.
Definition: ITstream.H:49
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:65