aGrUM  0.16.0
projectionRegister4MultiDim_tpl.h
Go to the documentation of this file.
1 
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 
33 # include <agrum/agrum.h>
34 
36 
37 namespace gum {
38 
39  // adds a new entry into the register
40  template < typename GUM_SCALAR >
42  const std::string& projection_name,
43  const std::string& type_multidim,
45  newFunction) {
46  // insert the new entry
47  ProjectionSet* theset;
48 
49  if (!__set.exists(projection_name)) {
50  theset = __set.insert(projection_name, new ProjectionSet).second;
51 # ifdef GUM_DEBUG_MODE
52  // for debugging purposes, we should inform the aGrUM's debugger that
53  // the hashtable contained within the ProjectionRegister4MultiDim will be
54  // 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[projection_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& projection_name, const std::string& type_multidim) {
69  if (!__set.exists(projection_name)) return;
70 
71  ProjectionSet* theset = __set[projection_name];
72 
73  theset->erase(type_multidim);
74  }
75 
76  // indicates whether a given entry exists in the register
77  template < typename GUM_SCALAR >
79  const std::string& projection_name, const std::string& type_multidim) const {
80  if (!__set.exists(projection_name)) return false;
81 
82  return __set[projection_name].exists(type_multidim);
83  }
84 
87  template < typename GUM_SCALAR >
90  const std::string& projection_name,
91  const std::string& type_multidim) const {
92  ProjectionSet* theset = __set[projection_name];
93  return theset->operator[](type_multidim);
94  }
95 
96  // a named constructor that constructs one and only one Register per data
97  // type
98  template < typename GUM_SCALAR >
99  ProjectionRegister4MultiDim< GUM_SCALAR >&
101  static ProjectionRegister4MultiDim container;
102 
103 # ifdef GUM_DEBUG_MODE
104  static bool first = true;
105 
106  if (first) {
107  first = false;
108  // for debugging purposes, we should inform the aGrUM's debugger that
109  // the hashtable contained within the ProjectionRegister4MultiDim will be
110  // 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 projection functions in MultiDims
139  template < typename GUM_SCALAR >
140  void registerProjection(
141  const std::string& projection_name,
142  const std::string& type_multidim,
145  projection_name, type_multidim, function);
146  }
147 
148 } /* namespace gum */
149 
150 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
static ProjectionRegister4MultiDim & Register()
a named constructor that constructs one and only one Register per data type
MultiDimImplementation< GUM_SCALAR > *(* ProjectionPtr)(const MultiDimImplementation< GUM_SCALAR > *, const Set< const DiscreteVariable * > &)
the type of functions used by the register
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void erase(const std::string &projection_name, const std::string &type_multidim)
removes a given entry from the register
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
bool exists(const std::string &projection_name, const std::string &type_multidim) const
indicates whether a given entry exists in the register
ProjectionPtr get(const std::string &projection_name, const std::string &type_multidim) const
returns the specialized projection operator assigned to a given type of MultiDimImplementation ...
HashTableIteratorSafe< Key, Val > iterator_safe
Types for STL compliance.
Definition: hashTable.h:695
void registerProjection(const std::string &projection_name, const std::string &type_multidim, typename ProjectionRegister4MultiDim< GUM_SCALAR >::ProjectionPtr function)
A function to more easily register new projection functions in MultiDims.
void insert(const std::string &projection_name, const std::string &type_multidim, ProjectionPtr newFunction)
adds a new entry into the register
~ProjectionRegister4MultiDim()
Destructor.
ProjectionRegister4MultiDim()
Default constructor: creates an empty register.