aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
completeProjectionRegister4MultiDim_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41#pragma once
42
43
51
53#ifndef DOXYGEN_SHOULD_SKIP_THIS
54
55# include <agrum/agrum.h>
56
58
59namespace gum {
60
61 // adds a new entry into the register
62 template < typename GUM_ELEMENT >
64 std::string_view projection_name,
65 std::string_view type_multidim,
67 newFunction) {
68 // insert the new entry
69 CompleteProjectionSet* theset;
70
71 if (!_set_.exists(projection_name)) {
72 theset = _set_.insert(std::string{projection_name}, new CompleteProjectionSet).second;
73# ifdef GUM_DEBUG_MODE
74 // for debugging purposes, we should inform the aGrUM's debugger that
75 // the hashtable contained within the CompleteProjectionRegister4MultiDim
76 // will be removed at the end of the program's execution.
77 __debug__::_inc_deletion_("HashTable", __FILE__, __LINE__, "destructor of", (void*)theset);
78# endif /* GUM_DEBUG_MODE */
79 } else {
80 theset = _set_[projection_name];
81 }
82
83 theset->insert(std::string{type_multidim}, newFunction);
84 }
85
86 // removes a given entry from the register
87 template < typename GUM_ELEMENT >
88 void CompleteProjectionRegister4MultiDim< GUM_ELEMENT >::erase(std::string_view projection_name,
89 std::string_view type_multidim) {
90 if (!_set_.exists(projection_name)) return;
91
92 CompleteProjectionSet* theset = _set_[projection_name];
93
94 theset->erase(type_multidim);
95 }
96
97 // indicates whether a given entry exists in the register
98 template < typename GUM_ELEMENT >
100 std::string_view projection_name,
101 std::string_view type_multidim) const {
102 if (!_set_.exists(projection_name)) return false;
103
104 const CompleteProjectionSet& theset = *(_set_[projection_name]);
105 return theset.exists(type_multidim);
106 }
107
110 template < typename GUM_ELEMENT >
113 std::string_view projection_name,
114 std::string_view type_multidim) const {
115 const CompleteProjectionSet& theset = *(_set_[projection_name]);
116 return theset[type_multidim];
117 }
118
119 // a named constructor that constructs one and only one Register per data
120 // type
121 template < typename GUM_ELEMENT >
124 // Here, this initialization is thread-safe due to Meyer’s Singleton property
126
127# ifdef GUM_DEBUG_MODE
128 static std::atomic_flag first = ATOMIC_FLAG_INIT;
129 if (!first.test_and_set()) {
130 // for debugging purposes, we should inform the aGrUM's debugger that
131 // the hashtable contained within the CompleteProjectionRegister4MultiDim
132 // will be removed at the end of the program's execution.
133 __debug__::_inc_deletion_("HashTable",
134 __FILE__,
135 __LINE__,
136 "destructor of",
137 (void*)&container._set_);
138 }
139# endif /* GUM_DEBUG_MODE */
140
141 return container;
142 }
143
144 // Default constructor: creates an empty register
145 template < typename GUM_ELEMENT >
147 = default;
148
149 // destructor
150 template < typename GUM_ELEMENT >
152 // remove all the sets
154 = _set_.beginSafe();
155 iter != _set_.endSafe();
156 ++iter)
157 delete iter.val();
158 }
159
160 // a function to more easily register new projection functions in MultiDims
161 template < typename GUM_ELEMENT >
163 std::string_view projection_name,
164 std::string_view type_multidim,
167 type_multidim,
168 function);
169 }
170
171} /* namespace gum */
172
173#endif /* DOXYGEN_SHOULD_SKIP_THIS */
A container for registering complete projection functions on multiDimImplementations,...
void insert(std::string_view projection_name, std::string_view type_multidim, CompleteProjectionPtr newFunction)
Adds a new entry into the register.
static CompleteProjectionRegister4MultiDim & Register()
A named constructor that constructs one and only one Register per data type.
CompleteProjectionRegister4MultiDim()
Default constructor: creates an empty register.
bool exists(std::string_view projection_name, std::string_view type_multidim) const
Indicates whether a given entry exists in the register.
void erase(std::string_view projection_name, std::string_view type_multidim)
Removes a given entry from the register.
GUM_ELEMENT(*)(const MultiDimImplementation< GUM_ELEMENT > *, Instantiation *instantiation) CompleteProjectionPtr
the type of functions used by the register
CompleteProjectionPtr get(std::string_view projection_name, std::string_view type_multidim) const
returns the specialized projection operator assigned to a given type of MultiDimImplementation
HashTableIteratorSafe< Key, Val > iterator_safe
Types for STL compliance.
Definition hashTable.h:655
A container for registering complete projection functions on multiDimImplementations,...
void registerCompleteProjection(std::string_view projection_name, std::string_view type_multidim, typename CompleteProjectionRegister4MultiDim< GUM_ELEMENT >::CompleteProjectionPtr function)
A function to more easily register new projection functions in MultiDims.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46