aGrUM
0.21.0
a C++ library for (probabilistic) graphical models
partialInstantiationRegister4MultiDim_tpl.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright (c) 2005-2021 by 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
<
GUM_SCALAR
>::
PartialInstantiationPtr
42
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
).
second
;
48
#
ifdef
GUM_DEBUG_MODE
49
// for debugging purposes, we should inform the aGrUM's debugger that
50
// the hashtable contained within the
51
// PartialInstantiationRegister4MultiDim
52
// will be removed at the end of the program's execution.
53
__debug__
::
_inc_deletion_
(
"HashTable"
,
__FILE__
,
__LINE__
,
"destructor of"
, (
void
*)
theset
);
54
#
endif
/* GUM_DEBUG_MODE */
55
}
else
{
56
theset
=
_set_
[
instantiation_func_name
];
57
}
58
59
theset
->
insert
(
type_multidim
,
newFunction
);
60
}
61
62
// removes a given entry from the register
63
template
<
typename
GUM_SCALAR
>
64
void
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::
erase
(
65
const
std
::
string
&
instantiation_func_name
,
66
const
std
::
string
&
type_multidim
) {
67
if
(!
_set_
.
exists
(
instantiation_func_name
))
return
;
68
69
PartialInstantiationSet
*
theset
=
_set_
[
instantiation_func_name
];
70
71
theset
->
erase
(
type_multidim
);
72
}
73
74
// indicates whether a given entry exists in the register
75
template
<
typename
GUM_SCALAR
>
76
INLINE
bool
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::
exists
(
77
const
std
::
string
&
instantiation_func_name
,
78
const
std
::
string
&
type_multidim
)
const
{
79
if
(!
_set_
.
exists
(
instantiation_func_name
))
return
false
;
80
81
return
_set_
[
instantiation_func_name
].
exists
(
type_multidim
);
82
}
83
84
/** @brief returns the specialized operator assigned to a given subtype of
85
* MultiDimImplementation */
86
template
<
typename
GUM_SCALAR
>
87
INLINE
typename
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::
PartialInstantiationPtr
88
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::
get
(
89
const
std
::
string
&
instantiation_func_name
,
90
const
std
::
string
&
type_multidim
)
const
{
91
PartialInstantiationSet
*
theset
=
_set_
[
instantiation_func_name
];
92
return
theset
->
operator
[](
type_multidim
);
93
}
94
95
// a named constructor that constructs one and only one Register per data
96
// type
97
template
<
typename
GUM_SCALAR
>
98
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>&
99
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::
Register
() {
100
static
PartialInstantiationRegister4MultiDim
container
;
101
102
#
ifdef
GUM_DEBUG_MODE
103
static
bool
first
=
true
;
104
105
if
(
first
) {
106
first
=
false
;
107
// for debugging purposes, we should inform the aGrUM's debugger that
108
// the hashtable contained within the
109
// PartialInstantiationRegister4MultiDim
110
// will be removed at the end of the program's execution.
111
__debug__
::
_inc_deletion_
(
"HashTable"
,
112
__FILE__
,
113
__LINE__
,
114
"destructor of"
,
115
(
void
*)&
container
.
_set_
);
116
}
117
118
#
endif
/* GUM_DEBUG_MODE */
119
120
return
container
;
121
}
122
123
// Default constructor: creates an empty register
124
template
<
typename
GUM_SCALAR
>
125
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::
PartialInstantiationRegister4MultiDim
() {}
126
127
// destructor
128
template
<
typename
GUM_SCALAR
>
129
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::~
PartialInstantiationRegister4MultiDim
() {
130
// remove all the sets
131
for
(
typename
HashTable
<
std
::
string
,
PartialInstantiationSet
* >::
iterator_safe
iter
132
=
_set_
.
beginSafe
();
133
iter
!=
_set_
.
endSafe
();
134
++
iter
)
135
delete
iter
.
val
();
136
}
137
138
// a function to more easily register new instantiation functions in
139
// MultiDims
140
template
<
typename
GUM_SCALAR
>
141
void
registerPartialInstantiation
(
142
const
std
::
string
&
instantiation_func_name
,
143
const
std
::
string
&
type_multidim
,
144
typename
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::
PartialInstantiationPtr
145
function
) {
146
PartialInstantiationRegister4MultiDim
<
GUM_SCALAR
>::
Register
().
insert
(
instantiation_func_name
,
147
type_multidim
,
148
function
);
149
}
150
151
}
/* namespace gum */
152
153
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643