OpenFOAM logo
Open Source CFD Toolkit

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