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::DictionaryBase 00026 00027 Description 00028 Base dictionary class templated on both the form of doubly-linked list 00029 it uses as well as the type it holds. 00030 00031 The double templating allows for the instantiation of forms with or 00032 without storage management. 00033 00034 Note 00035 The IDLListType parameter should itself be a template but this confused 00036 gcc 2.95.2 so it has to be instantiated for T when an instantiation of 00037 DictionaryBase is requested 00038 00039 See Also 00040 Dictionary and UDictionary 00041 00042 SourceFiles 00043 DictionaryBase.C 00044 DictionaryBaseIO.C 00045 00046 \*---------------------------------------------------------------------------*/ 00047 00048 #ifndef DictionaryBase_H 00049 #define DictionaryBase_H 00050 00051 #include <OpenFOAM/HashTable.H> 00052 #include <OpenFOAM/wordList.H> 00053 00054 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00055 00056 namespace Foam 00057 { 00058 00059 // Forward declaration of friend functions and operators 00060 00061 template<class IDLListType, class T> 00062 class DictionaryBase; 00063 00064 template<class IDLListType, class T> 00065 Ostream& operator<<(Ostream&, const DictionaryBase<IDLListType, T>&); 00066 00067 00068 /*---------------------------------------------------------------------------*\ 00069 Class DictionaryBase Declaration 00070 \*---------------------------------------------------------------------------*/ 00071 00072 template<class IDLListType, class T> 00073 class DictionaryBase 00074 : 00075 public IDLListType 00076 { 00077 // Private data 00078 00079 //- HashTable of the entries held on the IDLListType for quick lookup 00080 HashTable<T*> hashedTs_; 00081 00082 00083 // Private Member functions 00084 00085 // Add the IDLListType entries into the HashTable 00086 void addEntries(); 00087 00088 00089 public: 00090 00091 // Constructors 00092 00093 //- Null constructor 00094 DictionaryBase(); 00095 00096 //- Copy construct 00097 DictionaryBase(const DictionaryBase&); 00098 00099 //- Construct from Istream using given Istream constructor class 00100 template<class INew> 00101 DictionaryBase(Istream&, const INew&); 00102 00103 //- Construct from Istream using default Istream constructor class 00104 DictionaryBase(Istream&); 00105 00106 00107 // Member functions 00108 00109 // Search and lookup 00110 00111 //- Search DictionaryBase for given keyword 00112 bool found(const word&) const; 00113 00114 //- Find and return an entry if present, otherwise return NULL 00115 const T* lookupPtr(const word&) const; 00116 00117 //- Find and return an entry if present, otherwise return NULL 00118 T* lookupPtr(const word&); 00119 00120 //- Find and return entry 00121 const T* lookup(const word&) const; 00122 00123 //- Find and return entry 00124 T* lookup(const word&); 00125 00126 //- Return the table of contents 00127 wordList toc() const; 00128 00129 00130 // Editing 00131 00132 //- Add at head of dictionary 00133 void insert(const word&, T*); 00134 00135 //- Add at tail of dictionary 00136 void append(const word&, T*); 00137 00138 //- Remove and return entry specified by keyword. 00139 // Return NULL if the keyword was not found. 00140 T* remove(const word&); 00141 00142 //- Clear the dictionary 00143 void clear(); 00144 00145 //- Transfer the contents of the argument into this DictionaryBase 00146 // and annull the argument. 00147 void transfer(DictionaryBase<IDLListType, T>&); 00148 00149 // Member operators 00150 00151 void operator=(const DictionaryBase&); 00152 00153 //- Find and return entry 00154 const T* operator[](const word& key) const 00155 { 00156 return lookup(key); 00157 } 00158 00159 //- Find and return entry 00160 T* operator[](const word& key) 00161 { 00162 return lookup(key); 00163 } 00164 00165 00166 // Ostream operator 00167 00168 friend Ostream& operator<< <IDLListType, T> 00169 ( 00170 Ostream&, 00171 const DictionaryBase<IDLListType, T>& 00172 ); 00173 }; 00174 00175 00176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00177 00178 } // End namespace Foam 00179 00180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00181 00182 #ifdef NoRepository 00183 # include <OpenFOAM/DictionaryBase.C> 00184 #endif 00185 00186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00187 00188 #endif 00189 00190 // ************************ vim: set sw=4 sts=4 et: ************************ //