HashPtrTable.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 :
44  HashTable<T*, Key, Hash>()
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 template<class T, class Key, class Hash>
55 (
57 )
58 :
59  HashTable<T*, Key, Hash>(move(ht))
60 {}
61 
62 
63 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
64 
65 template<class T, class Key, class Hash>
67 {
68  clear();
69 }
70 
71 
72 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
73 
74 template<class T, class Key, class Hash>
76 {
77  T* elemPtr = *it;
79  return elemPtr;
80 }
81 
82 
83 template<class T, class Key, class Hash>
85 {
86  T* elemPtr = *it;
87 
89  {
90  if (elemPtr)
91  {
92  delete elemPtr;
93  }
94 
95  return true;
96  }
97  else
98  {
99  return false;
100  }
101 }
102 
103 
104 template<class T, class Key, class Hash>
106 {
107  for
108  (
109  iterator iter = this->begin();
110  iter != this->end();
111  ++iter
112  )
113  {
114  delete *iter;
115  }
116 
118 }
119 
120 
121 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
122 
123 template<class T, class Key, class Hash>
125 (
126  const HashPtrTable<T, Key, Hash>& rhs
127 )
128 {
129  // Check for assignment to self
130  if (this == &rhs)
131  {
133  << "attempted assignment to self"
134  << abort(FatalError);
135  }
136 
137  this->clear();
138 
139  for (const_iterator iter = rhs.begin(); iter != rhs.end(); ++iter)
140  {
141  this->insert(iter.key(), new T(**iter));
142  }
143 }
144 
145 
146 template<class T, class Key, class Hash>
148 (
150 )
151 {
152  // Check for assignment to self
153  if (this == &rhs)
154  {
156  << "attempted assignment to self"
157  << abort(FatalError);
158  }
159 
161 }
162 
163 
164 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
165 
166 #include "HashPtrTableIO.C"
167 
168 // ************************************************************************* //
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:67
bool erase(iterator &)
Erase an hashedEntry specified by given iterator.
Definition: HashPtrTable.C:84
void clear()
Clear all entries from table.
Definition: HashPtrTable.C:105
T * remove(iterator &)
Remove and return the pointer specified by given iterator.
Definition: HashPtrTable.C:75
~HashPtrTable()
Destructor.
Definition: HashPtrTable.C:66
An STL-conforming const_iterator.
Definition: HashTable.H:498
An STL-conforming iterator.
Definition: HashTable.H:443
An STL-conforming hash table.
Definition: HashTable.H:127
bool erase(const iterator &)
Erase a hashedEntry specified by given iterator.
Definition: HashTable.C:445
iterator begin()
Iterator set to the beginning of the HashTable.
Definition: HashTableI.H:411
bool insert(const word &, const T * &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
friend class HashPtrTable
Declare friendship with the HashPtrTable class.
Definition: HashTable.H:184
void operator=(const HashTable< T, Key, Hash > &)
Assignment operator.
Definition: HashTable.C:611
void clear()
Clear all entries from table.
Definition: HashTable.C:542
Hash function class for primitives. All non-primitives used to hash entries on hash tables likely nee...
Definition: Hash.H:53
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
tUEqn clear()
void insert(const scalar, DynamicList< floatScalar > &)
Append scalar to given DynamicList.
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
errorManip< error > abort(error &err)
Definition: errorManip.H:131
error FatalError
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112