aGrUM  0.16.0
operatorRegister4MultiDim_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& operation_name,
43  const std::string& type1,
44  const std::string& type2,
46  // insert the new entry
47  OperatorSet* theset;
48 
49  if (!__set.exists(operation_name)) {
50  theset = __set.insert(operation_name, new OperatorSet).second;
51 # ifdef GUM_DEBUG_MODE
52  // for debugging purposes, we should inform the aGrUM's debugger that
53  // the hashtable contained within the OperatorRegister4MultiDim 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[operation_name];
60  }
61 
62  std::pair< std::string, std::string > thepair(type1, type2);
63 
64  theset->insert(thepair, newFunction);
65  }
66 
67  // removes a given entry from the register
68  template < typename GUM_SCALAR >
70  const std::string& operation_name,
71  const std::string& type1,
72  const std::string& type2) {
73  if (!__set.exists(operation_name)) return;
74 
75  OperatorSet* theset = __set[operation_name];
76 
77  theset->erase(std::pair< std::string, std::string >(type1, type2));
78  }
79 
80  // indicates whether a given entry exists in the register
81  template < typename GUM_SCALAR >
83  const std::string& operation_name,
84  const std::string& type1,
85  const std::string& type2) const {
86  if (!__set.exists(operation_name)) return false;
87  OperatorSet* theset = __set[operation_name];
88  return theset->exists(std::pair< std::string, std::string >(type1, type2));
89  }
90 
93  template < typename GUM_SCALAR >
96  const std::string& operation_name,
97  const std::string& type1,
98  const std::string& type2) const {
99  OperatorSet* theset = __set[operation_name];
100  return (*theset)[std::pair< std::string, std::string >(type1, type2)];
101  }
102 
103  // a named constructor that constructs one and only one Register per data
104  // type
105  template < typename GUM_SCALAR >
106  OperatorRegister4MultiDim< GUM_SCALAR >&
108  static OperatorRegister4MultiDim< GUM_SCALAR >* container = nullptr;
109  static bool first = true;
110 
111  if (first) {
112  first = false;
113  container = new OperatorRegister4MultiDim< GUM_SCALAR >;
114 
115 # ifdef GUM_DEBUG_MODE
116  // for debugging purposes, we should inform the aGrUM's debugger that
117  // the hashtable contained within the OperatorRegister4MultiDim will be
118  // removed at the end of the program's execution.
119  __debug__::__inc_deletion("HashTable",
120  __FILE__,
121  __LINE__,
122  "destructor of",
123  (void*)&container->__set);
124 # endif /* GUM_DEBUG_MODE */
125  }
126 
127  return *container;
128  }
129 
130 
131  // Default constructor: creates an empty register
132  template < typename GUM_SCALAR >
134 
135  // destructor
136  template < typename GUM_SCALAR >
138  // remove all the sets
140  __set.beginSafe();
141  iter != __set.endSafe();
142  ++iter)
143  delete iter.val();
144  }
145 
146  // a function to more easily register new operators in MultiDims
147  template < typename GUM_SCALAR >
148  void registerOperator(
149  const std::string& operation_name,
150  const std::string& type1,
151  const std::string& type2,
154  operation_name, type1, type2, function);
155  }
156 
157 } /* namespace gum */
158 
159 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
void registerOperator(const std::string &operation_name, const std::string &type1, const std::string &type2, typename OperatorRegister4MultiDim< GUM_SCALAR >::OperatorPtr function)
A function to more easily register new operators in MultiDims.
HashTableIteratorSafe< Key, Val > iterator_safe
Types for STL compliance.
Definition: hashTable.h:695
bool exists(const std::string &operation_name, const std::string &type1, const std::string &type2) const
Indicates whether a given entry exists in the register.
void erase(const std::string &operation_name, const std::string &type1, const std::string &type2)
removes a given entry from the register
void insert(const std::string &operation_name, const std::string &type1, const std::string &type2, OperatorPtr newFunction)
adds a new entry into the register
static OperatorRegister4MultiDim< GUM_SCALAR > & Register()
A named constructor that constructs one and only one Register per data type.
MultiDimImplementation< GUM_SCALAR > *(* OperatorPtr)(const MultiDimImplementation< GUM_SCALAR > *, const MultiDimImplementation< GUM_SCALAR > *)
The type of functions used by the register.
OperatorRegister4MultiDim()
Default constructor: creates an empty register.
OperatorPtr get(const std::string &operation_name, const std::string &type1, const std::string &type2) const
returns the specialized operator assigned to a given pair of MultiDimImplementations ...
~OperatorRegister4MultiDim()
Destructor.