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) 2011-2016 OpenFOAM Foundation
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 "error.H"
27 #include "HashPtrTable.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class T, class Key, class Hash>
33 :
34  HashTable<T*, Key, Hash>(size)
35 {}
36 
37 
38 template<class T, class Key, class Hash>
40 (
42 )
43 :
45 {
46  for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter)
47  {
48  this->insert(iter.key(), new T(**iter));
49  }
50 }
51 
52 
53 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
54 
55 template<class T, class Key, class Hash>
57 {
58  clear();
59 }
60 
61 
62 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
63 
64 template<class T, class Key, class Hash>
66 {
67  T* elemPtr = *it;
69  return elemPtr;
70 }
71 
72 
73 template<class T, class Key, class Hash>
75 {
76  T* elemPtr = *it;
77 
79  {
80  if (elemPtr)
81  {
82  delete elemPtr;
83  }
84 
85  return true;
86  }
87  else
88  {
89  return false;
90  }
91 }
92 
93 
94 template<class T, class Key, class Hash>
96 {
97  for
98  (
99  iterator iter = this->begin();
100  iter != this->end();
101  ++iter
102  )
103  {
104  delete *iter;
105  }
106 
108 }
109 
110 
111 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
112 
113 template<class T, class Key, class Hash>
114 void Foam::HashPtrTable<T, Key, Hash>::operator=
115 (
116  const HashPtrTable<T, Key, Hash>& rhs
117 )
118 {
119  // Check for assignment to self
120  if (this == &rhs)
121  {
123  << "attempted assignment to self"
124  << abort(FatalError);
125  }
126 
127  this->clear();
128 
129  for (const_iterator iter = rhs.begin(); iter != rhs.end(); ++iter)
130  {
131  this->insert(iter.key(), new T(**iter));
132  }
133 }
134 
135 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
136 
137 #include "HashPtrTableIO.C"
138 
139 // ************************************************************************* //
~HashPtrTable()
Destructor.
Definition: HashPtrTable.C:56
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
HashPtrTable(const label size=128)
Construct given initial table size.
Definition: HashPtrTable.C:32
An STL-conforming const_iterator.
Definition: HashTable.H:470
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:106
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
void clear()
Clear all entries from table.
Definition: HashPtrTable.C:95
bool erase(const iterator &)
Erase a hashedEntry specified by given iterator.
Definition: HashTable.C:367
bool insert(const Key &, const T *&newElmt)
Insert a new hashedEntry.
void clear()
Clear all entries from table.
Definition: HashTable.C:464
iterator begin()
Iterator set to the beginning of the HashTable.
An STL-conforming hash table.
Definition: HashTable.H:61
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const volScalarField & T
Hash function class for primitives. All non-primitives used to hash entries on hash tables likely nee...
Definition: Hash.H:54
T * remove(iterator &)
Remove and return the pointer specified by given iterator.
Definition: HashPtrTable.C:65
HashTable< T *, Key, Hash >::iterator iterator
Definition: HashPtrTable.H:82
bool erase(iterator &)
Erase an hashedEntry specified by given iterator.
Definition: HashPtrTable.C:74