aGrUM  0.16.0
operatorPattern4MultiDimImplementation.h
Go to the documentation of this file.
1 
30 // check if we allowed these patterns to be used
31 #ifndef GUM_OPERATOR_PATTERN_ALLOWED
32 
33 // #warning To use operatorPattern4MultiDimImplementation.h, you must define
34 // GUM_OPERATOR_PATTERN_ALLOWED
35 
36 #else
37 
38 namespace gum {
39 
40 # ifdef GUM_MULTI_DIM_OPERATOR_NAME
41  template < typename T >
42  MultiDimImplementation< T >*
43  GUM_MULTI_DIM_OPERATOR_NAME(const MultiDimImplementation< T >& impl1,
44  const MultiDimImplementation< T >& impl2) {
45 # endif
46 
48  bool swapped_names = false;
49 
50  // get the appropriate function to perform the operation
51  try {
52  // try to find +(impl1,impl2) in the register
54  GUM_MULTI_DIM_OPERATOR_FUNC_NAME, impl1.name(), impl2.name());
55  } catch (NotFound&) {
56 
57 # ifdef GUM_MULTI_DIM_SYMMETRIC_OPERATOR
58 
59  try {
60  // the function could not be found but, as additions are symmetric, it
61  // may be the case that +(impl2,impl1) does exist in the register. For
62  // instance, we wrote +(MultiDimArray,MultiDimSparse) but not
63  // +(MultiDimSparse,MultiDimArray) and we called
64  // +(MultiDimSparse,MultiDimArray)
66  GUM_MULTI_DIM_OPERATOR_FUNC_NAME, impl2.name(), impl1.name());
67  swapped_names = true;
68  } catch (NotFound&) {
69 # endif /* GUM_MULTI_DIM_SYMMETRIC_OPERATOR */
70 
72  GUM_MULTI_DIM_OPERATOR_FUNC_NAME, impl1.basename(), impl2.basename());
73 
74 # ifdef GUM_MULTI_DIM_SYMMETRIC_OPERATOR
75  }
76 
77 # endif /* GUM_MULTI_DIM_SYMMETRIC_OPERATOR */
78  }
79 
80  // perform the addition
81  if (swapped_names)
82  return func(&impl2, &impl1);
83  else
84  return func(&impl1, &impl2);
85  }
86 } // namespace gum
87 #endif /* GUM_OPERATOR_PATTERN_ALLOWED */
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
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.