initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / dictionary / primitiveEntry / primitiveEntry.H
blobafc391248380ea12f90f3fd14cf9fa5b5db8bd5c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::primitiveEntry
28 Description
29     A keyword and a list of tokens is a 'primitiveEntry'.
30     An primitiveEntry can be read, written and printed, and the types and
31     values of its tokens analysed.
33     A primitiveEntry is a high-level building block for data description. It
34     is a front-end for the token parser. A list of entries can be used as a
35     set of keyword syntax elements, for example.
37 SourceFiles
38     primitiveEntry.C
39     primitiveEntryIO.C
41 \*---------------------------------------------------------------------------*/
43 #ifndef primitiveEntry_H
44 #define primitiveEntry_H
46 #include "IStringStream.H"
47 #include "OStringStream.H"
49 #include "entry.H"
50 #include "ITstream.H"
51 #include "InfoProxy.H"
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 namespace Foam
58 class dictionary;
60 /*---------------------------------------------------------------------------*\
61                        Class primitiveEntry Declaration
62 \*---------------------------------------------------------------------------*/
64 class primitiveEntry
66     public entry,
67     public ITstream
69     // Private member functions
71         //- Append the given token to this entry
72         void append
73         (
74             const token& currToken,
75             const dictionary&,
76             Istream&
77         );
79         //- Append the given tokens starting at the current tokenIndex
80         void append(const tokenList&);
82         //- Expand the given variable (keyword starts with $)
83         bool expandVariable(const word&, const dictionary&);
85         //- Expand the given function (keyword starts with #)
86         bool expandFunction
87         (
88             const word&,
89             const dictionary&,
90             Istream&
91         );
93         //- Read the complete entry from the given stream
94         void readEntry(const dictionary&, Istream&);
96         //- Insert the given tokens at token posI
97         void insert(const tokenList&, const label posI);
100 public:
102     // Constructors
104         //- Construct from keyword and a Istream
105         primitiveEntry(const keyType&, Istream&);
107         //- Construct from keyword, parent dictionary and Istream
108         primitiveEntry(const keyType&, const dictionary& parentDict, Istream&);
110         //- Construct from keyword and a ITstream
111         primitiveEntry(const keyType&, const ITstream&);
113         //- Construct from keyword and a token
114         primitiveEntry(const keyType&, const token&);
116         //- Construct from keyword and a tokenList
117         primitiveEntry(const keyType&, const tokenList&);
119         //- Construct from keyword and a T
120         template<class T>
121         primitiveEntry(const keyType&, const T&);
123         autoPtr<entry> clone(const dictionary&) const
124         {
125             return autoPtr<entry>(new primitiveEntry(*this));
126         }
129     // Member functions
131         //- Return the dictionary name
132         const fileName& name() const
133         {
134             return ITstream::name();
135         }
137         //- Return the dictionary name
138         fileName& name()
139         {
140             return ITstream::name();
141         }
143         //- Return line number of first token in dictionary
144         label startLineNumber() const;
146         //- Return line number of last token in dictionary
147         label endLineNumber() const;
149         //- Return true because this entry is a stream
150         bool isStream() const
151         {
152             return true;
153         }
155         //- Return token stream if this entry is a primitive entry
156         ITstream& stream() const;
158         //- This entry is not a dictionary,
159         //  calling this function generates a FatalError
160         const dictionary& dict() const;
162         //- This entry is not a dictionary,
163         //  calling this function generates a FatalError
164         dictionary& dict();
166         //- Read tokens from the given stream
167         bool read(const dictionary&, Istream&);
169         // Write
170         void write(Ostream&) const;
172         //- Return info proxy.
173         //  Used to print token information to a stream
174         InfoProxy<primitiveEntry> info() const
175         {
176             return *this;
177         }
181 template<>
182 Ostream& operator<<(Ostream&, const InfoProxy<primitiveEntry>&);
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 } // End namespace Foam
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 #ifdef NoRepository
192 #   include "primitiveEntryTemplates.C"
193 #endif
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 #endif
199 // ************************************************************************* //