aGrUM
0.21.0
a C++ library for (probabilistic) graphical models
projectionRegister4MultiDim_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 A container for registering projection functions on
25
* multiDimImplementations
26
*
27
* @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
28
*/
29
30
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
31
32
#
include
<
agrum
/
agrum
.
h
>
33
34
#
include
<
agrum
/
tools
/
multidim
/
utils
/
operators
/
projectionRegister4MultiDim
.
h
>
35
36
namespace
gum
{
37
38
// adds a new entry into the register
39
template
<
typename
GUM_SCALAR >
40
void
ProjectionRegister4MultiDim<
GUM_SCALAR
>::
insert
(
41
const
std
::
string
&
projection_name
,
42
const
std
::
string
&
type_multidim
,
43
typename
ProjectionRegister4MultiDim
<
GUM_SCALAR
>::
ProjectionPtr
newFunction
) {
44
// insert the new entry
45
ProjectionSet
*
theset
;
46
47
if
(!
_set_
.
exists
(
projection_name
)) {
48
theset
=
_set_
.
insert
(
projection_name
,
new
ProjectionSet
).
second
;
49
#
ifdef
GUM_DEBUG_MODE
50
// for debugging purposes, we should inform the aGrUM's debugger that
51
// the hashtable contained within the ProjectionRegister4MultiDim will be
52
// 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_
[
projection_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
ProjectionRegister4MultiDim
<
GUM_SCALAR
>::
erase
(
const
std
::
string
&
projection_name
,
65
const
std
::
string
&
type_multidim
) {
66
if
(!
_set_
.
exists
(
projection_name
))
return
;
67
68
ProjectionSet
*
theset
=
_set_
[
projection_name
];
69
70
theset
->
erase
(
type_multidim
);
71
}
72
73
// indicates whether a given entry exists in the register
74
template
<
typename
GUM_SCALAR
>
75
INLINE
bool
76
ProjectionRegister4MultiDim
<
GUM_SCALAR
>::
exists
(
const
std
::
string
&
projection_name
,
77
const
std
::
string
&
type_multidim
)
const
{
78
if
(!
_set_
.
exists
(
projection_name
))
return
false
;
79
80
return
_set_
[
projection_name
].
exists
(
type_multidim
);
81
}
82
83
/** @brief returns the specialized operator assigned to a given subtype of
84
* MultiDimImplementation */
85
template
<
typename
GUM_SCALAR
>
86
INLINE
typename
ProjectionRegister4MultiDim
<
GUM_SCALAR
>::
ProjectionPtr
87
ProjectionRegister4MultiDim
<
GUM_SCALAR
>::
get
(
const
std
::
string
&
projection_name
,
88
const
std
::
string
&
type_multidim
)
const
{
89
ProjectionSet
*
theset
=
_set_
[
projection_name
];
90
return
theset
->
operator
[](
type_multidim
);
91
}
92
93
// a named constructor that constructs one and only one Register per data
94
// type
95
template
<
typename
GUM_SCALAR
>
96
ProjectionRegister4MultiDim
<
GUM_SCALAR
>&
ProjectionRegister4MultiDim
<
GUM_SCALAR
>::
Register
() {
97
static
ProjectionRegister4MultiDim
container
;
98
99
#
ifdef
GUM_DEBUG_MODE
100
static
bool
first
=
true
;
101
102
if
(
first
) {
103
first
=
false
;
104
// for debugging purposes, we should inform the aGrUM's debugger that
105
// the hashtable contained within the ProjectionRegister4MultiDim will be
106
// removed at the end of the program's execution.
107
__debug__
::
_inc_deletion_
(
"HashTable"
,
108
__FILE__
,
109
__LINE__
,
110
"destructor of"
,
111
(
void
*)&
container
.
_set_
);
112
}
113
114
#
endif
/* GUM_DEBUG_MODE */
115
116
return
container
;
117
}
118
119
// Default constructor: creates an empty register
120
template
<
typename
GUM_SCALAR
>
121
ProjectionRegister4MultiDim
<
GUM_SCALAR
>::
ProjectionRegister4MultiDim
() {}
122
123
// destructor
124
template
<
typename
GUM_SCALAR
>
125
ProjectionRegister4MultiDim
<
GUM_SCALAR
>::~
ProjectionRegister4MultiDim
() {
126
// remove all the sets
127
for
(
typename
HashTable
<
std
::
string
,
ProjectionSet
* >::
iterator_safe
iter
=
_set_
.
beginSafe
();
128
iter
!=
_set_
.
endSafe
();
129
++
iter
)
130
delete
iter
.
val
();
131
}
132
133
// a function to more easily register new projection functions in MultiDims
134
template
<
typename
GUM_SCALAR
>
135
void
registerProjection
(
136
const
std
::
string
&
projection_name
,
137
const
std
::
string
&
type_multidim
,
138
typename
ProjectionRegister4MultiDim
<
GUM_SCALAR
>::
ProjectionPtr
function
) {
139
ProjectionRegister4MultiDim
<
GUM_SCALAR
>::
Register
().
insert
(
projection_name
,
140
type_multidim
,
141
function
);
142
}
143
144
}
/* namespace gum */
145
146
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643