aGrUM  0.16.0
partialInstantiationRegister4MultiDim_tpl.h
Go to the documentation of this file.
1 
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 
32 # include <agrum/agrum.h>
34 
35 namespace gum {
36 
37  // adds a new entry into the register
38  template < typename GUM_SCALAR >
40  const std::string& instantiation_func_name,
41  const std::string& type_multidim,
42  typename PartialInstantiationRegister4MultiDim<
43  GUM_SCALAR >::PartialInstantiationPtr newFunction) {
44  // insert the new entry
45  PartialInstantiationSet* theset;
46 
47  if (!__set.exists(instantiation_func_name)) {
48  theset =
49  __set.insert(instantiation_func_name, new PartialInstantiationSet).second;
50 # ifdef GUM_DEBUG_MODE
51  // for debugging purposes, we should inform the aGrUM's debugger that
52  // the hashtable contained within the
53  // PartialInstantiationRegister4MultiDim
54  // will be removed at the end of the program's execution.
55  __debug__::__inc_deletion(
56  "HashTable", __FILE__, __LINE__, "destructor of", (void*)theset);
57 # endif /* GUM_DEBUG_MODE */
58  } else {
59  theset = __set[instantiation_func_name];
60  }
61 
62  theset->insert(type_multidim, newFunction);
63  }
64 
65  // removes a given entry from the register
66  template < typename GUM_SCALAR >
68  const std::string& instantiation_func_name,
69  const std::string& type_multidim) {
70  if (!__set.exists(instantiation_func_name)) return;
71 
72  PartialInstantiationSet* theset = __set[instantiation_func_name];
73 
74  theset->erase(type_multidim);
75  }
76 
77  // indicates whether a given entry exists in the register
78  template < typename GUM_SCALAR >
80  const std::string& instantiation_func_name,
81  const std::string& type_multidim) const {
82  if (!__set.exists(instantiation_func_name)) return false;
83 
84  return __set[instantiation_func_name].exists(type_multidim);
85  }
86 
89  template < typename GUM_SCALAR >
90  INLINE typename PartialInstantiationRegister4MultiDim<
91  GUM_SCALAR >::PartialInstantiationPtr
93  const std::string& instantiation_func_name,
94  const std::string& type_multidim) const {
95  PartialInstantiationSet* theset = __set[instantiation_func_name];
96  return theset-> operator[](type_multidim);
97  }
98 
99  // a named constructor that constructs one and only one Register per data
100  // type
101  template < typename GUM_SCALAR >
102  PartialInstantiationRegister4MultiDim< GUM_SCALAR >&
104  static PartialInstantiationRegister4MultiDim container;
105 
106 # ifdef GUM_DEBUG_MODE
107  static bool first = true;
108 
109  if (first) {
110  first = false;
111  // for debugging purposes, we should inform the aGrUM's debugger that
112  // the hashtable contained within the
113  // PartialInstantiationRegister4MultiDim
114  // will be 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 >
129  PartialInstantiationRegister4MultiDim<
130  GUM_SCALAR >::PartialInstantiationRegister4MultiDim() {}
131 
132  // destructor
133  template < typename GUM_SCALAR >
134  PartialInstantiationRegister4MultiDim<
135  GUM_SCALAR >::~PartialInstantiationRegister4MultiDim() {
136  // remove all the sets
138  iter = __set.beginSafe();
139  iter != __set.endSafe();
140  ++iter)
141  delete iter.val();
142  }
143 
144  // a function to more easily register new instantiation functions in
145  // MultiDims
146  template < typename GUM_SCALAR >
148  const std::string& instantiation_func_name,
149  const std::string& type_multidim,
150  typename PartialInstantiationRegister4MultiDim<
151  GUM_SCALAR >::PartialInstantiationPtr function) {
153  instantiation_func_name, type_multidim, function);
154  }
155 
156 } /* namespace gum */
157 
158 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
static PartialInstantiationRegister4MultiDim & Register()
A named constructor that constructs one and only one Register per data type.
PartialInstantiationPtr get(const std::string &instantiation_func_name, const std::string &type_multidim) const
Returns the specialized partial instantiation operator assigned to a given type of MultiDimImplementa...
void erase(const std::string &instantiation_func_name, const std::string &type_multidim)
Removes a given entry from the register.
bool exists(const std::string &instantiation_func_name, const std::string &type_multidim) const
Indicates whether a given entry exists in the register.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
HashTableIteratorSafe< Key, Val > iterator_safe
Types for STL compliance.
Definition: hashTable.h:695
void registerPartialInstantiation(const std::string &instantiation_func_name, const std::string &type_multidim, typename PartialInstantiationRegister4MultiDim< GUM_SCALAR >::PartialInstantiationPtr function)
A function to more easily register new instantiation functions in MultiDims.
void insert(const std::string &instantiation_func_name, const std::string &type_multidim, PartialInstantiationPtr newFunction)
Adds a new entry into the register.