aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
partialInstantiationRegister4MultiDim_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 Implementation of PartialInstantiationRegister4MultiDim.
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 
31 # include <agrum/agrum.h>
32 # include <agrum/tools/multidim/utils/partialInstantiationRegister4MultiDim.h>
33 
34 namespace gum {
35 
36  // adds a new entry into the register
37  template < typename GUM_SCALAR >
38  void PartialInstantiationRegister4MultiDim< GUM_SCALAR >::insert(
40  const std::string& type_multidim,
42  newFunction) {
43  // insert the new entry
45 
48 # ifdef GUM_DEBUG_MODE
49  // for debugging purposes, we should inform the aGrUM's debugger that
50  // the hashtable contained within the
51  // PartialInstantiationRegister4MultiDim
52  // will be 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 {
57  }
58 
60  }
61 
62  // removes a given entry from the register
63  template < typename GUM_SCALAR >
66  const std::string& type_multidim) {
67  if (!_set_.exists(instantiation_func_name)) return;
68 
70 
72  }
73 
74  // indicates whether a given entry exists in the register
75  template < typename GUM_SCALAR >
78  const std::string& type_multidim) const {
79  if (!_set_.exists(instantiation_func_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 >
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
109  // PartialInstantiationRegister4MultiDim
110  // will be removed at the end of the program's execution.
111  __debug__::_inc_deletion_("HashTable",
112  __FILE__,
113  __LINE__,
114  "destructor of",
115  (void*)&container._set_);
116  }
117 
118 # endif /* GUM_DEBUG_MODE */
119 
120  return container;
121  }
122 
123  // Default constructor: creates an empty register
124  template < typename GUM_SCALAR >
126 
127  // destructor
128  template < typename GUM_SCALAR >
130  // remove all the sets
132  = _set_.beginSafe();
133  iter != _set_.endSafe();
134  ++iter)
135  delete iter.val();
136  }
137 
138  // a function to more easily register new instantiation functions in
139  // MultiDims
140  template < typename GUM_SCALAR >
143  const std::string& type_multidim,
145  function) {
148  function);
149  }
150 
151 } /* namespace gum */
152 
153 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643