aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
partialInstantiationRegister4MultiDim_tpl.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4
* info_at_agrum_dot_org
5
*
6
* This library is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18
*
19
*/
20
21
22
/**
23
* @file
24
* @brief Implementation of PartialInstantiationRegister4MultiDim.
25
*
26
* @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27
*/
28
29
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
30
31
#
include
<
agrum
/
agrum
.
h
>
32
#
include
<
agrum
/
tools
/
multidim
/
utils
/
partialInstantiationRegister4MultiDim
.
h
>
33
34
namespace
gum
{
35
36
// adds a new entry into the register
37
template
<
typename
GUM_SCALAR >
38
void
PartialInstantiationRegister4MultiDim<
GUM_SCALAR
>::
insert
(
39
const
std
::
string
&
instantiation_func_name
,
40
const
std
::
string
&
type_multidim
,
41
typename
PartialInstantiationRegister4MultiDim
<
42
GUM_SCALAR
>::
PartialInstantiationPtr
newFunction
) {
43
// insert the new entry
44
PartialInstantiationSet
*
theset
;
45
46
if
(!
set__
.
exists
(
instantiation_func_name
)) {
47
theset
=
set__
.
insert
(
instantiation_func_name
,
new
PartialInstantiationSet
)
48
.
second
;
49
#
ifdef
GUM_DEBUG_MODE
50
// for debugging purposes, we should inform the aGrUM's debugger that
51
// the hashtable contained within the
52
// PartialInstantiationRegister4MultiDim
53
// will be removed at the end of the program's execution.
54
__debug__
::
inc_deletion__
(
"HashTable"
,
55
__FILE__
,
56
__LINE__
,
57
"destructor of"
,
58
(
void
*)
theset
);
59
#
endif
/* GUM_DEBUG_MODE */
60
}
else
{
61
theset
=
set__
[
instantiation_func_name
];
62
}
63
64
theset
->
insert
(
type_multidim
,
newFunction
);
65
}
66
67
// removes a given entry from the register
68
template
<
typename
GUM_SCALAR
>
69
void
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::
erase
(
70
const
std
::
string
&
instantiation_func_name
,
71
const
std
::
string
&
type_multidim
) {
72
if
(!
set__
.
exists
(
instantiation_func_name
))
return
;
73
74
PartialInstantiationSet
*
theset
=
set__
[
instantiation_func_name
];
75
76
theset
->
erase
(
type_multidim
);
77
}
78
79
// indicates whether a given entry exists in the register
80
template
<
typename
GUM_SCALAR
>
81
INLINE
bool
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::
exists
(
82
const
std
::
string
&
instantiation_func_name
,
83
const
std
::
string
&
type_multidim
)
const
{
84
if
(!
set__
.
exists
(
instantiation_func_name
))
return
false
;
85
86
return
set__
[
instantiation_func_name
].
exists
(
type_multidim
);
87
}
88
89
/** @brief returns the specialized operator assigned to a given subtype of
90
* MultiDimImplementation */
91
template
<
typename
GUM_SCALAR
>
92
INLINE
typename
PartialInstantiationRegister4MultiDim
<
93
GUM_SCALAR
>::
PartialInstantiationPtr
94
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::
get
(
95
const
std
::
string
&
instantiation_func_name
,
96
const
std
::
string
&
type_multidim
)
const
{
97
PartialInstantiationSet
*
theset
=
set__
[
instantiation_func_name
];
98
return
theset
->
operator
[](
type_multidim
);
99
}
100
101
// a named constructor that constructs one and only one Register per data
102
// type
103
template
<
typename
GUM_SCALAR
>
104
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>&
105
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::
Register
() {
106
static
PartialInstantiationRegister4MultiDim
container
;
107
108
#
ifdef
GUM_DEBUG_MODE
109
static
bool
first
=
true
;
110
111
if
(
first
) {
112
first
=
false
;
113
// for debugging purposes, we should inform the aGrUM's debugger that
114
// the hashtable contained within the
115
// PartialInstantiationRegister4MultiDim
116
// will be removed at the end of the program's execution.
117
__debug__
::
inc_deletion__
(
"HashTable"
,
118
__FILE__
,
119
__LINE__
,
120
"destructor of"
,
121
(
void
*)&
container
.
set__
);
122
}
123
124
#
endif
/* GUM_DEBUG_MODE */
125
126
return
container
;
127
}
128
129
// Default constructor: creates an empty register
130
template
<
typename
GUM_SCALAR
>
131
PartialInstantiationRegister4MultiDim
<
132
GUM_SCALAR
>::
PartialInstantiationRegister4MultiDim
() {}
133
134
// destructor
135
template
<
typename
GUM_SCALAR
>
136
PartialInstantiationRegister4MultiDim
<
137
GUM_SCALAR
>::~
PartialInstantiationRegister4MultiDim
() {
138
// remove all the sets
139
for
(
typename
HashTable
<
std
::
string
,
PartialInstantiationSet
* >::
iterator_safe
140
iter
141
=
set__
.
beginSafe
();
142
iter
!=
set__
.
endSafe
();
143
++
iter
)
144
delete
iter
.
val
();
145
}
146
147
// a function to more easily register new instantiation functions in
148
// MultiDims
149
template
<
typename
GUM_SCALAR
>
150
void
registerPartialInstantiation
(
151
const
std
::
string
&
instantiation_func_name
,
152
const
std
::
string
&
type_multidim
,
153
typename
PartialInstantiationRegister4MultiDim
<
154
GUM_SCALAR
>::
PartialInstantiationPtr
function
) {
155
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::
Register
().
insert
(
156
instantiation_func_name
,
157
type_multidim
,
158
function
);
159
}
160
161
}
/* namespace gum */
162
163
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669