FreeFOAM The Cross-Platform CFD Toolkit
HashPtrTable.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include <OpenFOAM/error.H>
27 #include "HashPtrTable.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 // Construct given initial table size
32 template<class T, class Key, class Hash>
34 :
35  HashTable<T*, Key, Hash>(size)
36 {}
37 
38 
39 // Construct as copy
40 template<class T, class Key, class Hash>
42 (
44 )
45 :
47 {
48  for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter)
49  {
50  insert(iter.key(), new T(**iter));
51  }
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
56 
57 template<class T, class Key, class Hash>
59 {
60  clear();
61 }
62 
63 
64 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65 
66 template<class T, class Key, class Hash>
68 {
69  T* elemPtr = *it;
71  return elemPtr;
72 }
73 
74 
75 template<class T, class Key, class Hash>
77 {
78  T* elemPtr = *it;
79 
81  {
82  if (elemPtr)
83  {
84  delete elemPtr;
85  }
86 
87  return true;
88  }
89  else
90  {
91  return false;
92  }
93 }
94 
95 
96 template<class T, class Key, class Hash>
98 {
99  for
100  (
101  iterator iter = this->begin();
102  iter != this->end();
103  ++iter
104  )
105  {
106  delete *iter;
107  }
108 
110 }
111 
112 
113 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
114 
115 template<class T, class Key, class Hash>
117 (
118  const HashPtrTable<T, Key, Hash>& rhs
119 )
120 {
121  // Check for assignment to self
122  if (this == &rhs)
123  {
125  (
126  "HashPtrTable<T, Key, Hash>::operator="
127  "(const HashPtrTable<T, Key, Hash>&)"
128  ) << "attempted assignment to self"
129  << abort(FatalError);
130  }
131 
132  clear();
133 
134  for (const_iterator iter = rhs.begin(); iter != rhs.end(); ++iter)
135  {
136  insert(iter.key(), new T(**iter));
137  }
138 }
139 
140 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
141 
142 #include "HashPtrTableIO.C"
143 
144 // ************************ vim: set sw=4 sts=4 et: ************************ //