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-2015 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 // 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 (
43  const HashPtrTable<T, Key, Hash>& ht
44 )
45 :
46  HashTable<T*, Key, Hash>()
47 {
48  for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter)
49  {
50  this->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  << "attempted assignment to self"
126  << abort(FatalError);
127  }
128 
129  this->clear();
130 
131  for (const_iterator iter = rhs.begin(); iter != rhs.end(); ++iter)
132  {
133  this->insert(iter.key(), new T(**iter));
134  }
135 }
136 
137 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
138 
139 #include "HashPtrTableIO.C"
140 
141 // ************************************************************************* //
Foam::HashTable::iterator
An STL-conforming iterator.
Definition: HashTable.H:415
clear
UEqn clear()
Foam::HashPtrTable::~HashPtrTable
~HashPtrTable()
Destructor.
Definition: HashPtrTable.C:58
Foam::HashPtrTable::HashPtrTable
HashPtrTable(const label size=128)
Construct given initial table size.
Foam::HashTable::const_iterator
An STL-conforming const_iterator.
Definition: HashTable.H:470
erase
srcOptions erase("case")
Foam::HashPtrTable::clear
void clear()
Clear all entries from table.
Definition: HashPtrTable.C:97
Foam::DictionaryBase< DLList< T * >, T >::insert
void insert(const word &, T *)
Add at head of dictionary.
Definition: DictionaryBase.C:193
Foam::label
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
error.H
HashPtrTableIO.C
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:55
Foam::HashTable::erase
bool erase(const iterator &)
Erase a hashedEntry specified by given iterator.
Foam::HashPtrTable::remove
T * remove(iterator &)
Remove and return the pointer specified by given iterator.
Definition: HashPtrTable.C:67
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::HashTable
An STL-conforming hash table.
Definition: HashTable.H:61
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
T
const volScalarField & T
Definition: createFields.H:25
Foam::HashTable::clear
void clear()
Clear all entries from table.
Definition: HashTable.C:473
Foam::HashPtrTable
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
Foam::HashPtrTable::erase
bool erase(iterator &)
Erase an hashedEntry specified by given iterator.
Definition: HashPtrTable.C:76
HashPtrTable.H
insert
timeIndices insert(timeIndex, timeDirs[timeI].value())