aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
projectionRegister4MultiDim_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 projection functions on
25  * multiDimImplementations
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/projectionRegister4MultiDim.h>
35 
36 namespace gum {
37 
38  // adds a new entry into the register
39  template < typename GUM_SCALAR >
40  void ProjectionRegister4MultiDim< 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 ProjectionRegister4MultiDim will be
53  // 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 {
62  }
63 
65  }
66 
67  // removes a given entry from the register
68  template < typename GUM_SCALAR >
70  const std::string& projection_name,
71  const std::string& type_multidim) {
72  if (!set__.exists(projection_name)) return;
73 
75 
77  }
78 
79  // indicates whether a given entry exists in the register
80  template < typename GUM_SCALAR >
82  const std::string& projection_name,
83  const std::string& type_multidim) const {
84  if (!set__.exists(projection_name)) return false;
85 
87  }
88 
89  /** @brief returns the specialized operator assigned to a given subtype of
90  * MultiDimImplementation */
91  template < typename GUM_SCALAR >
94  const std::string& projection_name,
95  const std::string& type_multidim) const {
97  return theset->operator[](type_multidim);
98  }
99 
100  // a named constructor that constructs one and only one Register per data
101  // type
102  template < typename GUM_SCALAR >
106 
107 # ifdef GUM_DEBUG_MODE
108  static bool first = true;
109 
110  if (first) {
111  first = false;
112  // for debugging purposes, we should inform the aGrUM's debugger that
113  // the hashtable contained within the ProjectionRegister4MultiDim will be
114  // removed at the end of the program's execution.
115  __debug__::inc_deletion__("HashTable",
116  __FILE__,
117  __LINE__,
118  "destructor of",
119  (void*)&container.set__);
120  }
121 
122 # endif /* GUM_DEBUG_MODE */
123 
124  return container;
125  }
126 
127  // Default constructor: creates an empty register
128  template < typename GUM_SCALAR >
130 
131  // destructor
132  template < typename GUM_SCALAR >
134  // remove all the sets
135  for (typename HashTable< std::string, ProjectionSet* >::iterator_safe iter
136  = set__.beginSafe();
137  iter != set__.endSafe();
138  ++iter)
139  delete iter.val();
140  }
141 
142  // a function to more easily register new projection functions in MultiDims
143  template < typename GUM_SCALAR >
144  void registerProjection(
145  const std::string& projection_name,
146  const std::string& type_multidim,
150  function);
151  }
152 
153 } /* namespace gum */
154 
155 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669