aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
completeProjectionRegister4MultiDim_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 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,
44  newFunction) {
45  // insert the new entry
47 
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", __FILE__, __LINE__, "destructor of", (void*)theset);
55 # endif /* GUM_DEBUG_MODE */
56  } else {
58  }
59 
61  }
62 
63  // removes a given entry from the register
64  template < typename GUM_SCALAR >
66  const std::string& type_multidim) {
67  if (!_set_.exists(projection_name)) return;
68 
70 
72  }
73 
74  // indicates whether a given entry exists in the register
75  template < typename GUM_SCALAR >
77  const std::string& projection_name,
78  const std::string& type_multidim) const {
79  if (!_set_.exists(projection_name)) return false;
80 
82  }
83 
84  /** @brief returns the specialized operator assigned to a given subtype of
85  * MultiDimImplementation */
86  template < typename GUM_SCALAR >
89  const std::string& projection_name,
90  const std::string& type_multidim) const {
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 >
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 CompleteProjectionRegister4MultiDim
109  // will be removed at the end of the program's execution.
110  __debug__::_inc_deletion_("HashTable",
111  __FILE__,
112  __LINE__,
113  "destructor of",
114  (void*)&container._set_);
115  }
116 
117 # endif /* GUM_DEBUG_MODE */
118 
119  return container;
120  }
121 
122  // Default constructor: creates an empty register
123  template < typename GUM_SCALAR >
125 
126  // destructor
127  template < typename GUM_SCALAR >
129  // remove all the sets
131  = _set_.beginSafe();
132  iter != _set_.endSafe();
133  ++iter)
134  delete iter.val();
135  }
136 
137  // a function to more easily register new projection functions in MultiDims
138  template < typename GUM_SCALAR >
140  const std::string& projection_name,
141  const std::string& type_multidim,
145  function);
146  }
147 
148 } /* namespace gum */
149 
150 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643