aGrUM 2.3.2
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-2025 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-2025 *
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#pragma once
41
42
50
51#ifndef DOXYGEN_SHOULD_SKIP_THIS
52
53# include <agrum/agrum.h>
54
56
57namespace gum {
58
59 // adds a new entry into the register
60 template < typename GUM_SCALAR >
62 const std::string& projection_name,
63 const std::string& type_multidim,
65 newFunction) {
66 // insert the new entry
67 CompleteProjectionSet* theset;
68
69 if (!_set_.exists(projection_name)) {
70 theset = _set_.insert(projection_name, new CompleteProjectionSet).second;
71# ifdef GUM_DEBUG_MODE
72 // for debugging purposes, we should inform the aGrUM's debugger that
73 // the hashtable contained within the CompleteProjectionRegister4MultiDim
74 // will be removed at the end of the program's execution.
75 __debug__::_inc_deletion_("HashTable", __FILE__, __LINE__, "destructor of", (void*)theset);
76# endif /* GUM_DEBUG_MODE */
77 } else {
78 theset = _set_[projection_name];
79 }
80
81 theset->insert(type_multidim, newFunction);
82 }
83
84 // removes a given entry from the register
85 template < typename GUM_SCALAR >
86 void CompleteProjectionRegister4MultiDim< GUM_SCALAR >::erase(const std::string& projection_name,
87 const std::string& type_multidim) {
88 if (!_set_.exists(projection_name)) return;
89
90 CompleteProjectionSet* theset = _set_[projection_name];
91
92 theset->erase(type_multidim);
93 }
94
95 // indicates whether a given entry exists in the register
96 template < typename GUM_SCALAR >
98 const std::string& projection_name,
99 const std::string& type_multidim) const {
100 if (!_set_.exists(projection_name)) return false;
101
102 const CompleteProjectionSet& theset = *(_set_[projection_name]);
103 return theset.exists(type_multidim);
104 }
105
108 template < typename GUM_SCALAR >
111 const std::string& projection_name,
112 const std::string& type_multidim) const {
113 const CompleteProjectionSet& theset = *(_set_[projection_name]);
114 return theset[type_multidim];
115 }
116
117 // a named constructor that constructs one and only one Register per data
118 // type
119 template < typename GUM_SCALAR >
122 // Here, this initialization is thread-safe due to Meyer’s Singleton property
124
125# ifdef GUM_DEBUG_MODE
126 static std::atomic_flag first = ATOMIC_FLAG_INIT;
127 if (!first.test_and_set()) {
128 // for debugging purposes, we should inform the aGrUM's debugger that
129 // the hashtable contained within the CompleteProjectionRegister4MultiDim
130 // will be removed at the end of the program's execution.
131 __debug__::_inc_deletion_("HashTable",
132 __FILE__,
133 __LINE__,
134 "destructor of",
135 (void*)&container._set_);
136 }
137# endif /* GUM_DEBUG_MODE */
138
139 return container;
140 }
141
142 // Default constructor: creates an empty register
143 template < typename GUM_SCALAR >
145
146 // destructor
147 template < typename GUM_SCALAR >
149 // remove all the sets
151 = _set_.beginSafe();
152 iter != _set_.endSafe();
153 ++iter)
154 delete iter.val();
155 }
156
157 // a function to more easily register new projection functions in MultiDims
158 template < typename GUM_SCALAR >
160 const std::string& projection_name,
161 const std::string& type_multidim,
164 type_multidim,
165 function);
166 }
167
168} /* namespace gum */
169
170#endif /* DOXYGEN_SHOULD_SKIP_THIS */
A container for registering complete projection functions on multiDimImplementations,...
static CompleteProjectionRegister4MultiDim & Register()
A named constructor that constructs one and only one Register per data type.
CompleteProjectionPtr get(const std::string &projection_name, const std::string &type_multidim) const
returns the specialized projection operator assigned to a given type of MultiDimImplementation
void erase(const std::string &projection_name, const std::string &type_multidim)
Removes a given entry from the register.
bool exists(const std::string &projection_name, const std::string &type_multidim) const
Indicates whether a given entry exists in the register.
CompleteProjectionRegister4MultiDim()
Default constructor: creates an empty register.
void insert(const std::string &projection_name, const std::string &type_multidim, CompleteProjectionPtr newFunction)
Adds a new entry into the register.
GUM_SCALAR(*)(const MultiDimImplementation< GUM_SCALAR > *, Instantiation *instantiation) CompleteProjectionPtr
the type of functions used by the register
HashTableIteratorSafe< Key, Val > iterator_safe
Types for STL compliance.
Definition hashTable.h:652
A container for registering complete projection functions on multiDimImplementations,...
void registerCompleteProjection(const std::string &projection_name, const std::string &type_multidim, typename CompleteProjectionRegister4MultiDim< GUM_SCALAR >::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