00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 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 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your 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, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::primitiveEntry 00026 00027 Description 00028 A keyword and a list of tokens is a 'primitiveEntry'. 00029 An primitiveEntry can be read, written and printed, and the types and 00030 values of its tokens analysed. 00031 00032 A primitiveEntry is a high-level building block for data description. It 00033 is a front-end for the token parser. A list of entries can be used as a 00034 set of keyword syntax elements, for example. 00035 00036 SourceFiles 00037 primitiveEntry.C 00038 primitiveEntryIO.C 00039 00040 \*---------------------------------------------------------------------------*/ 00041 00042 #ifndef primitiveEntry_H 00043 #define primitiveEntry_H 00044 00045 #include <OpenFOAM/IStringStream.H> 00046 #include <OpenFOAM/OStringStream.H> 00047 00048 #include <OpenFOAM/entry.H> 00049 #include <OpenFOAM/ITstream.H> 00050 #include <OpenFOAM/InfoProxy.H> 00051 00052 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00053 00054 namespace Foam 00055 { 00056 00057 class dictionary; 00058 00059 /*---------------------------------------------------------------------------*\ 00060 Class primitiveEntry Declaration 00061 \*---------------------------------------------------------------------------*/ 00062 00063 class primitiveEntry 00064 : 00065 public entry, 00066 public ITstream 00067 { 00068 // Private member functions 00069 00070 //- Append the given token to this entry 00071 void append 00072 ( 00073 const token& currToken, 00074 const dictionary&, 00075 Istream& 00076 ); 00077 00078 //- Append the given tokens starting at the current tokenIndex 00079 void append(const tokenList&); 00080 00081 //- Expand the given variable (keyword starts with $) 00082 bool expandVariable(const word&, const dictionary&); 00083 00084 //- Expand the given function (keyword starts with #) 00085 bool expandFunction 00086 ( 00087 const word&, 00088 const dictionary&, 00089 Istream& 00090 ); 00091 00092 //- Read the complete entry from the given stream 00093 void readEntry(const dictionary&, Istream&); 00094 00095 //- Insert the given tokens at token posI 00096 void insert(const tokenList&, const label posI); 00097 00098 00099 public: 00100 00101 // Constructors 00102 00103 //- Construct from keyword and a Istream 00104 primitiveEntry(const keyType&, Istream&); 00105 00106 //- Construct from keyword, parent dictionary and Istream 00107 primitiveEntry(const keyType&, const dictionary& parentDict, Istream&); 00108 00109 //- Construct from keyword and a ITstream 00110 primitiveEntry(const keyType&, const ITstream&); 00111 00112 //- Construct from keyword and a token 00113 primitiveEntry(const keyType&, const token&); 00114 00115 //- Construct from keyword and a tokenList 00116 primitiveEntry(const keyType&, const tokenList&); 00117 00118 //- Construct from keyword and a T 00119 template<class T> 00120 primitiveEntry(const keyType&, const T&); 00121 00122 autoPtr<entry> clone(const dictionary&) const 00123 { 00124 return autoPtr<entry>(new primitiveEntry(*this)); 00125 } 00126 00127 00128 // Member functions 00129 00130 //- Return the dictionary name 00131 const fileName& name() const 00132 { 00133 return ITstream::name(); 00134 } 00135 00136 //- Return the dictionary name 00137 fileName& name() 00138 { 00139 return ITstream::name(); 00140 } 00141 00142 //- Return line number of first token in dictionary 00143 label startLineNumber() const; 00144 00145 //- Return line number of last token in dictionary 00146 label endLineNumber() const; 00147 00148 //- Return true because this entry is a stream 00149 bool isStream() const 00150 { 00151 return true; 00152 } 00153 00154 //- Return token stream if this entry is a primitive entry 00155 ITstream& stream() const; 00156 00157 //- This entry is not a dictionary, 00158 // calling this function generates a FatalError 00159 const dictionary& dict() const; 00160 00161 //- This entry is not a dictionary, 00162 // calling this function generates a FatalError 00163 dictionary& dict(); 00164 00165 //- Read tokens from the given stream 00166 bool read(const dictionary&, Istream&); 00167 00168 // Write 00169 void write(Ostream&) const; 00170 00171 //- Return info proxy. 00172 // Used to print token information to a stream 00173 InfoProxy<primitiveEntry> info() const 00174 { 00175 return *this; 00176 } 00177 }; 00178 00179 00180 template<> 00181 Ostream& operator<<(Ostream&, const InfoProxy<primitiveEntry>&); 00182 00183 00184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00185 00186 } // End namespace Foam 00187 00188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00189 00190 #ifdef NoRepository 00191 # include <OpenFOAM/primitiveEntryTemplates.C> 00192 #endif 00193 00194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00195 00196 #endif 00197 00198 // ************************ vim: set sw=4 sts=4 et: ************************ //