initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / containers / HashTables / HashPtrTable / HashPtrTable.C
blob99e73ad22fc1647de64bcb7732e5ea47bb3b7372
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "error.H"
28 #include "HashPtrTable.H"
30 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
32 // Construct given initial table size
33 template<class T, class Key, class Hash>
34 Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(const label size)
36     HashTable<T*, Key, Hash>(size)
40 // Construct as copy
41 template<class T, class Key, class Hash>
42 Foam::HashPtrTable<T, Key, Hash>::HashPtrTable
44     const HashPtrTable<T, Key, Hash>& ht
47     HashTable<T*, Key, Hash>()
49     for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter)
50     {
51         insert(iter.key(), new T(**iter));
52     }
56 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
58 template<class T, class Key, class Hash>
59 Foam::HashPtrTable<T, Key, Hash>::~HashPtrTable()
61     clear();
65 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
67 template<class T, class Key, class Hash>
68 T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& it)
70     T* elemPtr = *it;
71     HashTable<T*, Key, Hash>::erase(it);
72     return elemPtr;
76 template<class T, class Key, class Hash>
77 bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& it)
79     T* elemPtr = *it;
81     if (HashTable<T*, Key, Hash>::erase(it))
82     {
83         if (elemPtr)
84         {
85             delete elemPtr;
86         }
88         return true;
89     }
90     else
91     {
92         return false;
93     }
97 template<class T, class Key, class Hash>
98 void Foam::HashPtrTable<T, Key, Hash>::clear()
100     for
101     (
102         iterator iter = this->begin();
103         iter != this->end();
104         ++iter
105     )
106     {
107         delete *iter;
108     }
110     HashTable<T*, Key, Hash>::clear();
114 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
116 template<class T, class Key, class Hash>
117 void Foam::HashPtrTable<T, Key, Hash>::operator=
119     const HashPtrTable<T, Key, Hash>& rhs
122     // Check for assignment to self
123     if (this == &rhs)
124     {
125         FatalErrorIn
126         (
127             "HashPtrTable<T, Key, Hash>::operator="
128             "(const HashPtrTable<T, Key, Hash>&)"
129         )   << "attempted assignment to self"
130             << abort(FatalError);
131     }
133     clear();
135     for (const_iterator iter = rhs.begin(); iter != rhs.end(); ++iter)
136     {
137         insert(iter.key(), new T(**iter));
138     }
141 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
143 #include "HashPtrTableIO.C"
145 // ************************************************************************* //