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 | Copyright (C) 2011-2015 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
75  (
76  const token& currToken,
77  const dictionary&,
78  Istream&
79  );
80 
81  //- Expand the given variable (keyword starts with $)
82  bool expandVariable(const string&, const dictionary&);
83 
84  //- Expand the given function (keyword starts with #)
85  bool expandFunction
86  (
87  const word&,
88  const dictionary&,
89  Istream&
90  );
91 
92  //- Read the complete entry from the given stream
93  void readEntry(const dictionary&, Istream&);
94 
95 
96 public:
97 
98  // Constructors
99 
100  //- Construct from keyword and a Istream
101  primitiveEntry(const keyType&, Istream&);
102 
103  //- Construct from keyword, parent dictionary and Istream
104  primitiveEntry(const keyType&, const dictionary& parentDict, Istream&);
105 
106  //- Construct from keyword and a ITstream
107  primitiveEntry(const keyType&, const ITstream&);
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 by transferring a list of tokens
116  primitiveEntry(const keyType&, const Xfer<List<token> >&);
117 
118  //- Construct from keyword and a T
119  template<class T>
120  primitiveEntry(const keyType&, const T&);
122  autoPtr<entry> clone(const dictionary&) const
123  {
124  return autoPtr<entry>(new primitiveEntry(*this));
125  }
126 
127 
128  // Member functions
129 
130  //- Inherit read from ITstream
131  using ITstream::read;
132 
133  //- Return the dictionary name
134  const fileName& name() const
135  {
136  return ITstream::name();
137  }
138 
139  //- Return the dictionary name
140  fileName& name()
141  {
142  return ITstream::name();
143  }
144 
145  //- Return line number of first token in dictionary
146  label startLineNumber() const;
147 
148  //- Return line number of last token in dictionary
149  label endLineNumber() const;
150 
151  //- Return true because this entry is a stream
152  bool isStream() const
153  {
154  return true;
155  }
156 
157  //- Return token stream if this entry is a primitive entry
158  ITstream& stream() const;
159 
160  //- This entry is not a dictionary,
161  // calling this function generates a FatalError
162  const dictionary& dict() const;
163 
164  //- This entry is not a dictionary,
165  // calling this function generates a FatalError
166  dictionary& dict();
167 
168  //- Read tokens from the given stream
169  virtual bool read(const dictionary&, Istream&);
170 
171  //- Write
172  void write(Ostream&) const;
173 
174  //- Write, optionally with contents only (no keyword, etc)
175  void write(Ostream&, const bool contentsOnly) const;
176 
177  //- Return info proxy.
178  // Used to print token information to a stream
180  {
181  return *this;
182  }
183 };
184 
185 
186 template<>
187 Ostream& operator<<(Ostream&, const InfoProxy<primitiveEntry>&);
188 
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 } // End namespace Foam
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #ifdef NoRepository
197 # include "primitiveEntryTemplates.C"
198 #endif
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 #endif
203 
204 // ************************************************************************* //
virtual autoPtr< entry > clone() const
Construct on freestore as copy.
Definition: entry.C:54
Input token stream.
Definition: ITstream.H:49
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
A class for handling words, derived from string.
Definition: word.H:59
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 list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const fileName & name() const
Return the dictionary name.
label endLineNumber() const
Return line number of last token in dictionary.
virtual Istream & read(token &)
Return next token from stream.
Definition: ITstream.C:56
Namespace for OpenFOAM.
A class for handling keywords in dictionaries.
Definition: keyType.H:56
const fileName & name() const
Return the name of the stream.
Definition: ITstream.H:128
void write(Ostream &) const
Write.
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
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:45
primitiveEntry(const keyType &, Istream &)
Construct from keyword and a Istream.
A token holds items read from Istream.
Definition: token.H:67
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:65
virtual bool read(const dictionary &, Istream &)
Read tokens from the given stream.
A class for handling file names.
Definition: fileName.H:69
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:53
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.
InfoProxy< primitiveEntry > info() const
Return info proxy.
const dictionary & dict() const
This entry is not a dictionary,.
bool isStream() const
Return true because this entry is a stream.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
ITstream & stream() const
Return token stream if this entry is a primitive entry.
label startLineNumber() const
Return line number of first token in dictionary.