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

HashPtrTable.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::HashPtrTable
00027 
00028 Description
00029     A HashTable specialization for hashing pointers.
00030 
00031 SourceFiles
00032     HashPtrTable.C
00033     HashPtrTableIO.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef HashPtrTable_H
00038 #define HashPtrTable_H
00039 
00040 #include "HashTable.H"
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 namespace Foam
00045 {
00046 
00047 class Istream;
00048 class Ostream;
00049 
00050 // Forward declaration of friend functions and operators
00051 
00052 template<class T, class Key, class Hash> class HashPtrTable;
00053 
00054 template<class T, class Key, class Hash>
00055 Istream& operator>>(Istream&, HashPtrTable<T, Key, Hash>&);
00056 
00057 template<class T, class Key, class Hash>
00058 Ostream& operator<<(Ostream&, const HashPtrTable<T, Key, Hash>&);
00059 
00060 
00061 /*---------------------------------------------------------------------------*\
00062                         Class HashPtrTable Declaration
00063 \*---------------------------------------------------------------------------*/
00064 
00065 template<class T, class Key=word, class Hash=string::hash>
00066 class HashPtrTable
00067 :
00068     public HashTable<T*, Key, Hash>
00069 {
00070     // Private member functions
00071 
00072         //- Read from Istream using given Istream constructor class
00073         template<class INew>
00074         void read(Istream&, const INew& inewt);
00075 
00076 
00077 public:
00078 
00079     typedef typename HashTable<T*, Key, Hash>::iterator iterator;
00080     typedef typename HashTable<T*, Key, Hash>::const_iterator const_iterator;
00081 
00082 
00083     // Constructors
00084 
00085         //- Construct given initial table size
00086         HashPtrTable(const label size = 128);
00087 
00088         //- Construct from Istream using given Istream constructor class
00089         template<class INew>
00090         HashPtrTable(Istream&, const INew&);
00091 
00092         //- Construct from Istream using default Istream constructor class
00093         HashPtrTable(Istream&);
00094 
00095         //- Construct as copy
00096         HashPtrTable(const HashPtrTable<T, Key, Hash>&);
00097 
00098 
00099     // Destructor
00100 
00101         ~HashPtrTable();
00102 
00103 
00104     // Member Functions
00105 
00106         // Edit
00107 
00108             //- Remove and return the pointer specified by given iterator
00109             T* remove(iterator&);
00110 
00111             //- Erase an hashedEntry specified by given iterator
00112             bool erase(iterator&);
00113 
00114             //- Clear all entries from table
00115             void clear();
00116 
00117 
00118     // Member Operators
00119 
00120         void operator=(const HashPtrTable<T, Key, Hash>&);
00121 
00122 
00123     // IOstream Operators
00124 
00125         friend Istream& operator>> <T, Key, Hash>
00126         (
00127             Istream&,
00128             HashPtrTable<T, Key, Hash>&
00129         );
00130 
00131         friend Ostream& operator<< <T, Key, Hash>
00132         (
00133             Ostream&,
00134             const HashPtrTable<T, Key, Hash>&
00135         );
00136 };
00137 
00138 
00139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00140 
00141 } // End namespace Foam
00142 
00143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00144 
00145 #ifdef NoRepository
00146 #   include "HashPtrTable.C"
00147 #endif
00148 
00149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00150 
00151 #endif
00152 
00153 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd