|
|
|
dictionary.HGo 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-2007 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 dictionary 00027 00028 Description 00029 A dictionary is a list of keyword definitions. A keyword definition 00030 consists of a keyword followed by any number of values 00031 (e.g. words and numbers). Dictionary is the base class for IOdictionary 00032 It serves the purpose of a bootstrap dictionary for the objectRegistry data 00033 dictionaries, since unlike the IOdictionary class, it does not use a 00034 objectRegistry itself to work. 00035 00036 SourceFiles 00037 dictionary.C 00038 dictionaryIO.C 00039 00040 \*---------------------------------------------------------------------------*/ 00041 00042 #ifndef dictionary_H 00043 #define dictionary_H 00044 00045 #include "entry.H" 00046 #include "IDLList.H" 00047 #include "fileName.H" 00048 #include "ITstream.H" 00049 #include "HashTable.H" 00050 #include "className.H" 00051 00052 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00053 00054 namespace Foam 00055 { 00056 00057 /*---------------------------------------------------------------------------*\ 00058 Class dictionary Declaration 00059 \*---------------------------------------------------------------------------*/ 00060 00061 class dictionary 00062 : 00063 public IDLList<entry> 00064 { 00065 // Private data 00066 00067 //- Dictionary name 00068 fileName name_; 00069 00070 //- HashTable of the enries held on the DL-list for quick lookup 00071 HashTable<entry*> hashedEntries_; 00072 00073 //- Add a new entry 00074 void add(entry*); 00075 00076 //- Read dictionary from Istream 00077 bool read(Istream&, const word& = word::null); 00078 00079 00080 public: 00081 00082 // Declare name of the class and it's debug switch 00083 ClassName("dictionary"); 00084 00085 00086 //- Null dictionary 00087 static const dictionary null; 00088 00089 00090 // Constructors 00091 00092 //- Construct null 00093 dictionary(); 00094 00095 //- Construct from Istream, reading entries until lastEntry or EOF 00096 dictionary(Istream&, const word& lastEntry = word::null); 00097 00098 //- Construct as copy 00099 dictionary(const dictionary&); 00100 00101 //- Construct and return clone 00102 autoPtr<dictionary> clone() const; 00103 00104 //- Construct on freestore from Istream 00105 static autoPtr<dictionary> New(Istream& is); 00106 00107 00108 // Desstructor 00109 00110 ~dictionary(); 00111 00112 00113 // Member functions 00114 00115 //- Return the dictionary name 00116 const fileName& name() const 00117 { 00118 return name_; 00119 } 00120 00121 //- Return the dictionary name 00122 fileName& name() 00123 { 00124 return name_; 00125 } 00126 00127 //- Return line number of first token in dictionary 00128 label startLineNumber() const; 00129 00130 //- Return line number of last token in dictionary 00131 label endLineNumber() const; 00132 00133 00134 // Search and lookup 00135 00136 //- Search dictionary for given keyword 00137 bool found(const word& keyword) const; 00138 00139 //- Find and return an entry data stream 00140 const entry& lookupEntry(const word&) const; 00141 00142 //- Find and return an entry data stream 00143 ITstream& lookup(const word&) const; 00144 00145 //- Check if entry is a sub-dictionary 00146 bool isDict(const word&) const; 00147 00148 //- Find and return a sub-dictionary 00149 const dictionary& subDict(const word&) const; 00150 00151 //- Return the table of contents 00152 wordList toc() const; 00153 00154 00155 // Editing 00156 00157 //- Add an entry 00158 void add(const entry&); 00159 00160 //- Add a token entry 00161 void add(const word& keyword, const token&); 00162 00163 //- Add a word entry 00164 void add(const word& keyword, const word&); 00165 00166 //- Add a string entry 00167 void add(const word& keyword, const Foam::string&); 00168 00169 //- Add a label entry 00170 void add(const word& keyword, const label); 00171 00172 //- Add a scalar entry 00173 void add(const word& keyword, const scalar); 00174 00175 //- Add an entry constructed from a ITstream 00176 void add(const word& keyword, const ITstream&); 00177 00178 //- Add an entry constructed from a tokenList 00179 void add(const word& keyword, const tokenList& tokens); 00180 00181 //- Add a T entry 00182 template<class T> 00183 void add(const word& keyword, const T&); 00184 00185 //- Add a dictionary entry 00186 void add(const word& keyword, const dictionary&); 00187 00188 //- Remove an entry specified by keyword 00189 bool remove(const word& keyword); 00190 00191 //- Change the keyword for an entry, 00192 // optionally forcing overwrite of an existing entry 00193 bool changeKeyword 00194 ( 00195 const word& oldKeyword, 00196 const word& newKeyword, 00197 bool forceOverwrite = false 00198 ); 00199 00200 00201 // Write 00202 00203 void write(Ostream& os, bool subDict = true) const; 00204 00205 00206 // Member Operators 00207 00208 //- Find and return entry 00209 ITstream& operator[](const word&) const; 00210 00211 void operator=(const dictionary&); 00212 00213 //- Include entries from the given dictionary. 00214 // Warn, but do not overwrite existing entries 00215 void operator+=(const dictionary&); 00216 00217 //- Conditionally include entries from the given dictionary. 00218 // Do not overwrite existing entries. 00219 void operator|=(const dictionary&); 00220 00221 //- Unconditionally include entries from the given dictionary. 00222 // Overwrite existing entries. 00223 void operator<<=(const dictionary&); 00224 00225 00226 // IOstream operators 00227 00228 //- Read dictionary from Istream 00229 friend Istream& operator>>(Istream&, dictionary&); 00230 00231 //- Write dictionary to Ostream 00232 friend Ostream& operator<<(Ostream&, const dictionary&); 00233 }; 00234 00235 00236 // Global Operators 00237 00238 // Combine dictionaries starting from the entries in dict one and then including 00239 // those from dict2. 00240 // Warn, but do not overwrite the entries from dict1. 00241 dictionary operator+(const dictionary& dict1, const dictionary& dict2); 00242 00243 // Combine dictionaries starting from the entries in dict one and then including 00244 // those from dict2. 00245 // Do not overwrite the entries from dict1. 00246 dictionary operator|(const dictionary& dict1, const dictionary& dict2); 00247 00248 00249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00250 00251 } // End namespace Foam 00252 00253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00254 00255 #ifdef NoRepository 00256 # include "dictionaryTemplates.C" 00257 #endif 00258 00259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00260 00261 #endif 00262 00263 // ************************************************************************* // |