aGrUM  0.16.0
completeProjectionRegister4MultiDim_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,
44  typename CompleteProjectionRegister4MultiDim<
45  GUM_SCALAR >::CompleteProjectionPtr newFunction) {
46  // insert the new entry
47  CompleteProjectionSet* theset;
48 
49  if (!__set.exists(projection_name)) {
50  theset = __set.insert(projection_name, new CompleteProjectionSet).second;
51 # ifdef GUM_DEBUG_MODE
52  // for debugging purposes, we should inform the aGrUM's debugger that
53  // the hashtable contained within the CompleteProjectionRegister4MultiDim
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[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  CompleteProjectionSet* 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 >
88  INLINE typename CompleteProjectionRegister4MultiDim<
89  GUM_SCALAR >::CompleteProjectionPtr
91  const std::string& projection_name,
92  const std::string& type_multidim) const {
93  CompleteProjectionSet* theset = __set[projection_name];
94  return theset-> operator[](type_multidim);
95  }
96 
97  // a named constructor that constructs one and only one Register per data
98  // type
99  template < typename GUM_SCALAR >
100  CompleteProjectionRegister4MultiDim< GUM_SCALAR >&
102  static CompleteProjectionRegister4MultiDim container;
103 
104 # ifdef GUM_DEBUG_MODE
105  static bool first = true;
106 
107  if (first) {
108  first = false;
109  // for debugging purposes, we should inform the aGrUM's debugger that
110  // the hashtable contained within the CompleteProjectionRegister4MultiDim
111  // will be removed at the end of the program's execution.
112  __debug__::__inc_deletion("HashTable",
113  __FILE__,
114  __LINE__,
115  "destructor of",
116  (void*)&container.__set);
117  }
118 
119 # endif /* GUM_DEBUG_MODE */
120 
121  return container;
122  }
123 
124  // Default constructor: creates an empty register
125  template < typename GUM_SCALAR >
126  CompleteProjectionRegister4MultiDim<
127  GUM_SCALAR >::CompleteProjectionRegister4MultiDim() {}
128 
129  // destructor
130  template < typename GUM_SCALAR >
131  CompleteProjectionRegister4MultiDim<
132  GUM_SCALAR >::~CompleteProjectionRegister4MultiDim() {
133  // remove all the sets
135  iter = __set.beginSafe();
136  iter != __set.endSafe();
137  ++iter)
138  delete iter.val();
139  }
140 
141  // a function to more easily register new projection functions in MultiDims
142  template < typename GUM_SCALAR >
143  void
144  registerCompleteProjection(const std::string& projection_name,
145  const std::string& type_multidim,
146  typename CompleteProjectionRegister4MultiDim<
147  GUM_SCALAR >::CompleteProjectionPtr function) {
149  projection_name, type_multidim, function);
150  }
151 
152 } /* namespace gum */
153 
154 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
static CompleteProjectionRegister4MultiDim & Register()
A named constructor that constructs one and only one Register per data type.
void erase(const std::string &projection_name, const std::string &type_multidim)
Removes a given entry from the register.
bool exists(const std::string &projection_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
void registerCompleteProjection(const std::string &projection_name, const std::string &type_multidim, typename CompleteProjectionRegister4MultiDim< GUM_SCALAR >::CompleteProjectionPtr function)
A function to more easily register new projection functions in MultiDims.
void insert(const std::string &projection_name, const std::string &type_multidim, CompleteProjectionPtr newFunction)
Adds a new entry into the register.
CompleteProjectionPtr 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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.