OpenFOAM
7
The OpenFOAM Foundation
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
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>
32
Foam::HashPtrTable<T, Key, Hash>::HashPtrTable
(
const
label
size)
33
:
34
HashTable
<
T
*, Key,
Hash
>(size)
35
{}
36
37
38
template
<
class
T,
class
Key,
class
Hash>
39
Foam::HashPtrTable<T, Key, Hash>::HashPtrTable
40
(
41
const
HashPtrTable<T, Key, Hash>
& ht
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>
54
Foam::HashPtrTable<T, Key, Hash>::HashPtrTable
55
(
56
HashPtrTable<T, Key, Hash>
&& ht
57
)
58
:
59
HashTable<T*, Key, Hash>
(move(ht))
60
{}
61
62
63
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
64
65
template
<
class
T,
class
Key,
class
Hash>
66
Foam::HashPtrTable<T, Key, Hash>::~HashPtrTable
()
67
{
68
clear
();
69
}
70
71
72
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
73
74
template
<
class
T,
class
Key,
class
Hash>
75
T
*
Foam::HashPtrTable<T, Key, Hash>::remove
(
iterator
& it)
76
{
77
T
* elemPtr = *it;
78
HashTable<T*, Key, Hash>::erase
(it);
79
return
elemPtr;
80
}
81
82
83
template
<
class
T,
class
Key,
class
Hash>
84
bool
Foam::HashPtrTable<T, Key, Hash>::erase
(
iterator
& it)
85
{
86
T
* elemPtr = *it;
87
88
if
(
HashTable<T*, Key, Hash>::erase
(it))
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>
105
void
Foam::HashPtrTable<T, Key, Hash>::clear
()
106
{
107
for
108
(
109
iterator
iter = this->begin();
110
iter != this->end();
111
++iter
112
)
113
{
114
delete
*iter;
115
}
116
117
HashTable<T*, Key, Hash>::clear
();
118
}
119
120
121
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
122
123
template
<
class
T,
class
Key,
class
Hash>
124
void
Foam::HashPtrTable<T, Key, Hash>::operator=
125
(
126
const
HashPtrTable<T, Key, Hash>
& rhs
127
)
128
{
129
// Check for assignment to self
130
if
(
this
== &rhs)
131
{
132
FatalErrorInFunction
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>
147
void
Foam::HashPtrTable<T, Key, Hash>::operator=
148
(
149
HashPtrTable<T, Key, Hash>
&& rhs
150
)
151
{
152
// Check for assignment to self
153
if
(
this
== &rhs)
154
{
155
FatalErrorInFunction
156
<<
"attempted assignment to self"
157
<<
abort
(
FatalError
);
158
}
159
160
HashTable<T*, Key, Hash>::operator=
(move(rhs));
161
}
162
163
164
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
165
166
#include "
HashPtrTableIO.C
"
167
168
// ************************************************************************* //
Foam::HashPtrTable::~HashPtrTable
~HashPtrTable()
Destructor.
Definition:
HashPtrTable.C:66
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
Foam::HashPtrTable::HashPtrTable
HashPtrTable(const label size=128)
Construct given initial table size.
Definition:
HashPtrTable.C:32
Foam::HashTable::const_iterator
An STL-conforming const_iterator.
Definition:
HashTable.H:481
Foam::HashTableCore::end
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition:
HashTable.H:112
erase
srcOptions erase("case")
Foam::FatalError
error FatalError
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition:
error.H:319
clear
tUEqn clear()
error.H
Foam::HashPtrTable
A HashTable specialization for hashing pointers.
Definition:
HashPtrTable.H:50
Foam::HashPtrTable::clear
void clear()
Clear all entries from table.
Definition:
HashPtrTable.C:105
Foam::HashTable::iterator
An STL-conforming iterator.
Definition:
HashTable.H:426
insert
timeIndices insert(timeIndex, timeDirs[timeI].value())
Foam::HashTable< T *, Key, Hash >::begin
iterator begin()
Iterator set to the beginning of the HashTable.
Definition:
HashTableI.H:411
Foam::HashTable
An STL-conforming hash table.
Definition:
HashTable.H:61
Foam::abort
errorManip< error > abort(error &err)
Definition:
errorManip.H:131
HashPtrTableIO.C
T
const volScalarField & T
Definition:
createFieldRefs.H:2
Foam::Hash
Hash function class for primitives. All non-primitives used to hash entries on hash tables likely nee...
Definition:
Hash.H:54
Foam::HashPtrTable::remove
T * remove(iterator &)
Remove and return the pointer specified by given iterator.
Definition:
HashPtrTable.C:75
Foam::HashPtrTable::erase
bool erase(iterator &)
Erase an hashedEntry specified by given iterator.
Definition:
HashPtrTable.C:84
HashPtrTable.H
src
OpenFOAM
containers
HashTables
HashPtrTable
HashPtrTable.C
Generated by
1.8.13