1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
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.
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.
40 \*---------------------------------------------------------------------------*/
42 #ifndef primitiveEntry_H
43 #define primitiveEntry_H
45 #include "IStringStream.H"
46 #include "OStringStream.H"
50 #include "InfoProxy.H"
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 /*---------------------------------------------------------------------------*\
60 Class primitiveEntry Declaration
61 \*---------------------------------------------------------------------------*/
68 // Private Member Functions
70 //- Append the given tokens starting at the current tokenIndex
71 void append(const UList<token>&);
73 //- Append the given token to this entry
76 const token& currToken,
81 //- Expand the given variable (keyword starts with $)
82 bool expandVariable(const word&, const dictionary&);
84 //- Expand the given function (keyword starts with #)
92 //- Read the complete entry from the given stream
93 void readEntry(const dictionary&, Istream&);
100 //- Construct from keyword and a Istream
101 primitiveEntry(const keyType&, Istream&);
103 //- Construct from keyword, parent dictionary and Istream
104 primitiveEntry(const keyType&, const dictionary& parentDict, Istream&);
106 //- Construct from keyword and a ITstream
107 primitiveEntry(const keyType&, const ITstream&);
109 //- Construct from keyword and a single token
110 primitiveEntry(const keyType&, const token&);
112 //- Construct from keyword and a list of tokens
113 primitiveEntry(const keyType&, const UList<token>&);
115 //- Construct from keyword and by transferring a list of tokens
116 primitiveEntry(const keyType&, const Xfer<List<token> >&);
118 //- Construct from keyword and a T
120 primitiveEntry(const keyType&, const T&);
122 autoPtr<entry> clone(const dictionary&) const
124 return autoPtr<entry>(new primitiveEntry(*this));
130 //- Return the dictionary name
131 const fileName& name() const
133 return ITstream::name();
136 //- Return the dictionary name
139 return ITstream::name();
142 //- Return line number of first token in dictionary
143 label startLineNumber() const;
145 //- Return line number of last token in dictionary
146 label endLineNumber() const;
148 //- Return true because this entry is a stream
149 bool isStream() const
154 //- Return token stream if this entry is a primitive entry
155 ITstream& stream() const;
157 //- This entry is not a dictionary,
158 // calling this function generates a FatalError
159 const dictionary& dict() const;
161 //- This entry is not a dictionary,
162 // calling this function generates a FatalError
165 //- Read tokens from the given stream
166 bool read(const dictionary&, Istream&);
169 void write(Ostream&) const;
171 //- Write, optionally with contents only (no keyword, etc)
172 void write(Ostream&, const bool contentsOnly) const;
174 //- Return info proxy.
175 // Used to print token information to a stream
176 InfoProxy<primitiveEntry> info() const
184 Ostream& operator<<(Ostream&, const InfoProxy<primitiveEntry>&);
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 } // End namespace Foam
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 # include "primitiveEntryTemplates.C"
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 // ************************************************************************* //