aGrUM  0.14.2
operatorPattern4MultiDimImplementation.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 // check if we allowed these patterns to be used
28 #ifndef GUM_OPERATOR_PATTERN_ALLOWED
29 
30 // #warning To use operatorPattern4MultiDimImplementation.h, you must define
31 // GUM_OPERATOR_PATTERN_ALLOWED
32 
33 #else
34 
35 namespace gum {
36 
37 # ifdef GUM_MULTI_DIM_OPERATOR_NAME
38  template < typename T >
39  MultiDimImplementation< T >*
40  GUM_MULTI_DIM_OPERATOR_NAME(const MultiDimImplementation< T >& impl1,
41  const MultiDimImplementation< T >& impl2) {
42 # endif
43 
45  bool swapped_names = false;
46 
47  // get the appropriate function to perform the operation
48  try {
49  // try to find +(impl1,impl2) in the register
51  GUM_MULTI_DIM_OPERATOR_FUNC_NAME, impl1.name(), impl2.name());
52  } catch (NotFound&) {
53 
54 # ifdef GUM_MULTI_DIM_SYMMETRIC_OPERATOR
55 
56  try {
57  // the function could not be found but, as additions are symmetric, it
58  // may be the case that +(impl2,impl1) does exist in the register. For
59  // instance, we wrote +(MultiDimArray,MultiDimSparse) but not
60  // +(MultiDimSparse,MultiDimArray) and we called
61  // +(MultiDimSparse,MultiDimArray)
63  GUM_MULTI_DIM_OPERATOR_FUNC_NAME, impl2.name(), impl1.name());
64  swapped_names = true;
65  } catch (NotFound&) {
66 # endif /* GUM_MULTI_DIM_SYMMETRIC_OPERATOR */
67 
69  GUM_MULTI_DIM_OPERATOR_FUNC_NAME, impl1.basename(), impl2.basename());
70 
71 # ifdef GUM_MULTI_DIM_SYMMETRIC_OPERATOR
72  }
73 
74 # endif /* GUM_MULTI_DIM_SYMMETRIC_OPERATOR */
75  }
76 
77  // perform the addition
78  if (swapped_names)
79  return func(&impl2, &impl1);
80  else
81  return func(&impl1, &impl2);
82  }
83 } // namespace gum
84 #endif /* GUM_OPERATOR_PATTERN_ALLOWED */
gum is the global namespace for all aGrUM entities
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.