aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
completeProjectionRegister4MultiDim_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 A container for registering complete projection functions on
25
* multiDimImplementations, i.e., projections over all variables
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
/
completeProjectionRegister4MultiDim
.
h
>
35
36
namespace
gum
{
37
38
// adds a new entry into the register
39
template
<
typename
GUM_SCALAR >
40
void
CompleteProjectionRegister4MultiDim<
GUM_SCALAR
>::
insert
(
41
const
std
::
string
&
projection_name
,
42
const
std
::
string
&
type_multidim
,
43
typename
CompleteProjectionRegister4MultiDim
<
44
GUM_SCALAR
>::
CompleteProjectionPtr
newFunction
) {
45
// insert the new entry
46
CompleteProjectionSet
*
theset
;
47
48
if
(!
set__
.
exists
(
projection_name
)) {
49
theset
=
set__
.
insert
(
projection_name
,
new
CompleteProjectionSet
).
second
;
50
#
ifdef
GUM_DEBUG_MODE
51
// for debugging purposes, we should inform the aGrUM's debugger that
52
// the hashtable contained within the CompleteProjectionRegister4MultiDim
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__
[
projection_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
CompleteProjectionRegister4MultiDim
<
GUM_SCALAR
>::
erase
(
70
const
std
::
string
&
projection_name
,
71
const
std
::
string
&
type_multidim
) {
72
if
(!
set__
.
exists
(
projection_name
))
return
;
73
74
CompleteProjectionSet
*
theset
=
set__
[
projection_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
CompleteProjectionRegister4MultiDim
<
GUM_SCALAR
>::
exists
(
82
const
std
::
string
&
projection_name
,
83
const
std
::
string
&
type_multidim
)
const
{
84
if
(!
set__
.
exists
(
projection_name
))
return
false
;
85
86
return
set__
[
projection_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
CompleteProjectionRegister4MultiDim
<
93
GUM_SCALAR
>::
CompleteProjectionPtr
94
CompleteProjectionRegister4MultiDim
<
GUM_SCALAR
>::
get
(
95
const
std
::
string
&
projection_name
,
96
const
std
::
string
&
type_multidim
)
const
{
97
CompleteProjectionSet
*
theset
=
set__
[
projection_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
CompleteProjectionRegister4MultiDim
<
GUM_SCALAR
>&
105
CompleteProjectionRegister4MultiDim
<
GUM_SCALAR
>::
Register
() {
106
static
CompleteProjectionRegister4MultiDim
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 CompleteProjectionRegister4MultiDim
115
// will be removed at the end of the program's execution.
116
__debug__
::
inc_deletion__
(
"HashTable"
,
117
__FILE__
,
118
__LINE__
,
119
"destructor of"
,
120
(
void
*)&
container
.
set__
);
121
}
122
123
#
endif
/* GUM_DEBUG_MODE */
124
125
return
container
;
126
}
127
128
// Default constructor: creates an empty register
129
template
<
typename
GUM_SCALAR
>
130
CompleteProjectionRegister4MultiDim
<
131
GUM_SCALAR
>::
CompleteProjectionRegister4MultiDim
() {}
132
133
// destructor
134
template
<
typename
GUM_SCALAR
>
135
CompleteProjectionRegister4MultiDim
<
136
GUM_SCALAR
>::~
CompleteProjectionRegister4MultiDim
() {
137
// remove all the sets
138
for
(
typename
HashTable
<
std
::
string
,
CompleteProjectionSet
* >::
iterator_safe
139
iter
140
=
set__
.
beginSafe
();
141
iter
!=
set__
.
endSafe
();
142
++
iter
)
143
delete
iter
.
val
();
144
}
145
146
// a function to more easily register new projection functions in MultiDims
147
template
<
typename
GUM_SCALAR
>
148
void
149
registerCompleteProjection
(
const
std
::
string
&
projection_name
,
150
const
std
::
string
&
type_multidim
,
151
typename
CompleteProjectionRegister4MultiDim
<
152
GUM_SCALAR
>::
CompleteProjectionPtr
function
) {
153
CompleteProjectionRegister4MultiDim
<
GUM_SCALAR
>::
Register
().
insert
(
154
projection_name
,
155
type_multidim
,
156
function
);
157
}
158
159
}
/* namespace gum */
160
161
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669