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

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