OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

primitiveEntry.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::primitiveEntry
00027 
00028 Description
00029     A keyword and a list of tokens is a 'primitiveEntry'.
00030     An primitiveEntry can be read, written and printed, and the types and
00031     values of its tokens analysed.
00032 
00033     A primitiveEntry is a high-level building block for data description. It
00034     is a front-end for the token parser. A list of entries can be used as a
00035     set of keyword syntax elements, for example.
00036 
00037 SourceFiles
00038     primitiveEntry.C
00039     primitiveEntryIO.C
00040 
00041 \*---------------------------------------------------------------------------*/
00042 
00043 #ifndef primitiveEntry_H
00044 #define primitiveEntry_H
00045 
00046 #include "IStringStream.H"
00047 #include "OStringStream.H"
00048 
00049 #include "entry.H"
00050 #include "ITstream.H"
00051 #include "InfoProxy.H"
00052 
00053 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00054 
00055 namespace Foam
00056 {
00057 
00058 class dictionary;
00059 
00060 /*---------------------------------------------------------------------------*\
00061                        Class primitiveEntry Declaration
00062 \*---------------------------------------------------------------------------*/
00063 
00064 class primitiveEntry
00065 :
00066     public entry,
00067     public ITstream
00068 {
00069     // Private member functions
00070 
00071         //- Append the given token to this entry
00072         void append
00073         (
00074             const token& currToken,
00075             const dictionary&,
00076             Istream&
00077         );
00078 
00079         //- Append the given tokens starting at the current tokenIndex
00080         void append(const tokenList&);
00081 
00082         //- Expand the given variable (keyword starts with $)
00083         bool expandVariable(const word&, const dictionary&);
00084 
00085         //- Expand the given function (keyword starts with #)
00086         bool expandFunction
00087         (
00088             const word&,
00089             const dictionary&,
00090             Istream&
00091         );
00092 
00093         //- Read the complete entry from the given stream
00094         void readEntry(const dictionary&, Istream&);
00095 
00096         //- Insert the given tokens at token posI
00097         void insert(const tokenList&, const label posI);
00098 
00099 
00100 public:
00101 
00102     // Constructors
00103 
00104         //- Construct from keyword and a Istream
00105         primitiveEntry(const keyType&, Istream&);
00106 
00107         //- Construct from keyword, parent dictionary and Istream
00108         primitiveEntry(const keyType&, const dictionary& parentDict, Istream&);
00109 
00110         //- Construct from keyword and a ITstream
00111         primitiveEntry(const keyType&, const ITstream&);
00112 
00113         //- Construct from keyword and a token
00114         primitiveEntry(const keyType&, const token&);
00115 
00116         //- Construct from keyword and a tokenList
00117         primitiveEntry(const keyType&, const tokenList&);
00118 
00119         //- Construct from keyword and a T
00120         template<class T>
00121         primitiveEntry(const keyType&, const T&);
00122 
00123         autoPtr<entry> clone(const dictionary&) const
00124         {
00125             return autoPtr<entry>(new primitiveEntry(*this));
00126         }
00127 
00128 
00129     // Member functions
00130 
00131         //- Return the dictionary name
00132         const fileName& name() const
00133         {
00134             return ITstream::name();
00135         }
00136 
00137         //- Return the dictionary name
00138         fileName& name()
00139         {
00140             return ITstream::name();
00141         }
00142 
00143         //- Return line number of first token in dictionary
00144         label startLineNumber() const;
00145 
00146         //- Return line number of last token in dictionary
00147         label endLineNumber() const;
00148 
00149         //- Return true because this entry is a stream
00150         bool isStream() const
00151         {
00152             return true;
00153         }
00154 
00155         //- Return token stream if this entry is a primitive entry
00156         ITstream& stream() const;
00157 
00158         //- This entry is not a dictionary,
00159         //  calling this function generates a FatalError
00160         const dictionary& dict() const;
00161 
00162         //- This entry is not a dictionary,
00163         //  calling this function generates a FatalError
00164         dictionary& dict();
00165 
00166         //- Read tokens from the given stream
00167         bool read(const dictionary&, Istream&);
00168 
00169         // Write
00170         void write(Ostream&) const;
00171 
00172         //- Return info proxy.
00173         //  Used to print token information to a stream
00174         InfoProxy<primitiveEntry> info() const
00175         {
00176             return *this;
00177         }
00178 };
00179 
00180 
00181 template<>
00182 Ostream& operator<<(Ostream&, const InfoProxy<primitiveEntry>&);
00183 
00184 
00185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00186 
00187 } // End namespace Foam
00188 
00189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00190 
00191 #ifdef NoRepository
00192 #   include "primitiveEntryTemplates.C"
00193 #endif
00194 
00195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00196 
00197 #endif
00198 
00199 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd