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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::primitiveEntry
29 
30 Description
31  A keyword and a list of tokens comprise a primitiveEntry.
32  A primitiveEntry can be read, written and printed, and the types and
33  values of its tokens analysed.
34 
35  A primitiveEntry is a high-level building block for data description.
36  It is a front-end for the token parser. A list of entries can be used
37  as a set of keyword syntax elements, for example.
38 
39 SourceFiles
40  primitiveEntry.C
41  primitiveEntryIO.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef primitiveEntry_H
46 #define primitiveEntry_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  //- Test if token is acceptable after filtering for function entries
71  //- and variable expansions.
72  bool acceptToken
73  (
74  const token& tok,
75  const dictionary& dict,
76  Istream& is
77  );
78 
79  //- Expand the given variable.
80  // The keyword starts with '$', but has been removed by the caller
81  // and thus passed as a varName.
82  // Keywords with '${}' are expanded recursively.
83  bool expandVariable
84  (
85  const string& varName,
86  const dictionary& dict
87  );
88 
89  //- Expand the given function.
90  // The keyword starts with '#', but has been removed by the caller.
91  // and thus passed as a functionName.
92  bool expandFunction
93  (
94  const word& functionName,
95  const dictionary& dict,
96  Istream& is
97  );
98 
99  //- Read the complete entry from the given stream
100  void readEntry(const dictionary& dict, Istream& is);
101 
102 
103 public:
104 
105  // Constructors
106 
107  //- Construct from keyword and a Istream
108  primitiveEntry(const keyType& key, Istream& is);
109 
110  //- Construct from keyword, parent dictionary and Istream
111  primitiveEntry(const keyType& key, const dictionary& dict, Istream& is);
112 
113  //- Construct from keyword and a ITstream
114  primitiveEntry(const keyType& key, const ITstream& is);
115 
116  //- Construct from keyword and a single token
117  primitiveEntry(const keyType& key, const token& tok);
118 
119  //- Construct from keyword and a list of tokens
120  primitiveEntry(const keyType& key, const UList<token>& tokens);
121 
122  //- Construct from keyword and by transferring a list of tokens
123  primitiveEntry(const keyType& key, List<token>&& tokens);
124 
125  //- Construct from keyword and a T
126  template<class T>
127  primitiveEntry(const keyType& key, const T& val);
128 
129  autoPtr<entry> clone(const dictionary&) const
130  {
131  return autoPtr<entry>(new primitiveEntry(*this));
132  }
133 
134 
135  // Member Functions
136 
137  //- Inherit read from ITstream
138  using ITstream::read;
139 
140  //- Return the dictionary name
141  virtual const fileName& name() const
142  {
143  return ITstream::name();
144  }
145 
146  //- Return the dictionary name
147  virtual fileName& name()
148  {
149  return ITstream::name();
150  }
151 
152  //- Return line number of first token in dictionary
153  virtual label startLineNumber() const;
154 
155  //- Return line number of last token in dictionary
156  virtual label endLineNumber() const;
157 
158  //- Return true - this entry is a stream
159  virtual bool isStream() const
160  {
161  return true;
162  }
163 
164  //- Return token stream for this primitive entry
165  virtual ITstream& stream() const;
166 
167  //- This entry is not a dictionary,
168  // calling this function generates a FatalError
169  virtual const dictionary& dict() const;
170 
171  //- This entry is not a dictionary,
172  // calling this function generates a FatalError
173  virtual dictionary& dict();
174 
175  //- Read tokens from the given stream
176  virtual bool read(const dictionary& dict, Istream& is);
177 
178  //- Write
179  virtual void write(Ostream& os) const;
180 
181  //- Write, optionally with contents only (no keyword, etc)
182  void write(Ostream& os, const bool contentsOnly) const;
183 
184  //- Return info proxy.
185  // Used to print token information to a stream
187  {
188  return *this;
189  }
190 };
191 
192 
193 template<>
194 Ostream& operator<<(Ostream& os, const InfoProxy<primitiveEntry>& ip);
195 
196 
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 
199 } // End namespace Foam
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 #ifdef NoRepository
204  #include "primitiveEntryTemplates.C"
205 #endif
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 #endif
210 
211 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::primitiveEntry
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read,...
Definition: primitiveEntry.H:62
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::InfoProxy
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:47
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
ITstream.H
InfoProxy.H
Foam::primitiveEntry::primitiveEntry
primitiveEntry(const keyType &key, Istream &is)
Construct from keyword and a Istream.
Definition: primitiveEntryIO.C:263
Foam::primitiveEntry::stream
virtual ITstream & stream() const
Return token stream for this primitive entry.
Definition: primitiveEntry.C:282
Foam::primitiveEntry::read
virtual bool read(const dictionary &dict, Istream &is)
Read tokens from the given stream.
Definition: primitiveEntryIO.C:104
Foam::token
A token holds an item read from Istream.
Definition: token.H:69
Foam::primitiveEntry::write
virtual void write(Ostream &os) const
Write.
Definition: primitiveEntryIO.C:300
Foam::primitiveEntry::clone
autoPtr< entry > clone(const dictionary &) const
Construct on freestore as copy with reference to the.
Definition: primitiveEntry.H:128
Foam::primitiveEntry::dict
virtual const dictionary & dict() const
This entry is not a dictionary,.
Definition: primitiveEntry.C:290
Foam::ITstream::read
virtual Istream & read(token &tok)
Return next token from stream.
Definition: ITstream.C:251
entry.H
Foam::ITstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: ITstream.H:204
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:60
Foam::ITstream
An input stream of tokens.
Definition: ITstream.H:55
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::primitiveEntry::endLineNumber
virtual label endLineNumber() const
Return line number of last token in dictionary.
Definition: primitiveEntry.C:269
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::primitiveEntry::startLineNumber
virtual label startLineNumber() const
Return line number of first token in dictionary.
Definition: primitiveEntry.C:256
Foam::primitiveEntry::info
InfoProxy< primitiveEntry > info() const
Return info proxy.
Definition: primitiveEntry.H:185
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
primitiveEntryTemplates.C
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::entry::clone
virtual autoPtr< entry > clone() const
Construct on freestore as copy.
Definition: entry.C:69
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::UList
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:103
Foam::primitiveEntry::isStream
virtual bool isStream() const
Return true - this entry is a stream.
Definition: primitiveEntry.H:158
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::primitiveEntry::name
virtual const fileName & name() const
Return the dictionary name.
Definition: primitiveEntry.H:140
Foam::primitiveEntry::name
virtual fileName & name()
Return the dictionary name.
Definition: primitiveEntry.H:146