Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TestMatrixInterface.cpp
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8 
9  BIAS is free software; you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation; either version 2.1 of the License, or
12  (at your option) any later version.
13 
14  BIAS is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with BIAS; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
22 
23 /** @file MatrixInterfaceCheck.cpp
24  * @ingroup g_tests
25  @brief Class capsulating the checks for interfaces of Matrix* classes
26  without using inheritance and thus avoiding the overhead induced by the
27  vtable.
28  @relates Matrix, Matrix2x2, Matrix3x3, Matrix3x4, Matrix4x4, ...
29  @author woelk 05/2008 (c) www.vision-n.de */
30 
31 #include <Base/Math/Matrix.hh>
32 #include <Base/Math/Matrix2x2.hh>
33 #include <Base/Math/Matrix3x3.hh>
34 #include <Base/Math/SymmetricMatrix3x3.hh>
35 #include <Base/Math/Matrix3x4.hh>
36 #include <Base/Math/Matrix4x4.hh>
37 
38 using namespace BIAS;
39 
40 /// macro for checking the existence of a specific function with signature
41 /// RESULT FUNCTION(__VA_ARGS__) CONST. The check is conducted by trying to
42 /// assign a pointer to the member-function in question to the
43 /// variable 'p'
44 #define MATRIX_INTERFACE(RESULT, FUNCTION, CONST, ARG)\
45  { RESULT (MATRIX_CLASS<T>::* p)(ARG) CONST = &MATRIX_CLASS<T>::FUNCTION; \
46  p=0; }
47 
48 #define MATRIX_INTERFACE2(RESULT, FUNCTION, CONST, ARG1, ARG2)\
49  { RESULT (MATRIX_CLASS<T>::* p)(ARG1, ARG2) CONST = &MATRIX_CLASS<T>::FUNCTION; \
50  p=0; }
51 
52 #define MATRIX_INTERFACE3(RESULT, FUNCTION, CONST)\
53  { RESULT (MATRIX_CLASS<T>::* p)() CONST = &MATRIX_CLASS<T>::FUNCTION; \
54  p=0; }
55 
56 #define MATRIX_INTERFACE4(RESULT, FUNCTION)\
57  { RESULT (MATRIX_CLASS<T>::* p)() = &MATRIX_CLASS<T>::FUNCTION; \
58  p=0; }
59 
60 
61 #define MATRIX_INTERFACE5(RESULT, FUNCTION, ARG)\
62  { RESULT (MATRIX_CLASS<T>::* p)(ARG) = &MATRIX_CLASS<T>::FUNCTION; \
63  p=0; }
64 
65 template <template <typename> class MATRIX_CLASS,
66  template <typename> class VECTOR_CLASS, class T>
67 class MatrixInterfaceCheck
68 {
69 public:
70  static void Constraints()
71  {
72  MATRIX_CLASS<T> m;
73 
74  // T* operator[](const unsigned)
75 #if __GNUC_PREREQ(4,6)
76  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
77 #endif
78  MATRIX_INTERFACE5(T* , operator[], const unsigned);
79 
80  // const T* operator[](const unsigned) const
81 #if __GNUC_PREREQ(4,6)
82  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
83 #endif
84  MATRIX_INTERFACE(const T* , operator[], const, const unsigned);
85 
86  // T* GetData()
87 #if __GNUC_PREREQ(4,6)
88  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
89 #endif
90  MATRIX_INTERFACE4(T* , GetData);
91 
92  // const T* GetData() const
93 #if __GNUC_PREREQ(4,6)
94  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
95 #endif
96  MATRIX_INTERFACE3(const T* , GetData, const);
97 
98  // unsigned GetNumElements() const
99 #if __GNUC_PREREQ(4,6)
100  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
101 #endif
102  MATRIX_INTERFACE3(unsigned , GetNumElements, const);
103 
104  // void SetZero()
105 #if __GNUC_PREREQ(4,6)
106  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
107 #endif
108  MATRIX_INTERFACE4(void, SetZero);
109 
110  // void SetIdentity()
111 #if __GNUC_PREREQ(4,6)
112  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
113 #endif
114  MATRIX_INTERFACE4(void, SetIdentity);
115 
116  // void Mult(const VECTOR_CLASS &, VECTOR_CLASS &) const
117 #if __GNUC_PREREQ(4,6)
118  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
119 #endif
120  MATRIX_INTERFACE2(void, Mult, const, const VECTOR_CLASS<T> &, VECTOR_CLASS<T> &);
121 
122  // void TransposedMult(const VECTOR_CLASS &, VECTOR_CLASS &) const
123 #if __GNUC_PREREQ(4,6)
124  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
125 #endif
126  MATRIX_INTERFACE2(void, TransposedMult, const, const VECTOR_CLASS<T> &, VECTOR_CLASS<T> &);
127 
128  // void Mult(const MATRIX_CLASS &, MATRIX_CLASS &) const
129 #if __GNUC_PREREQ(4,6)
130  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
131 #endif
132  MATRIX_INTERFACE2(void, Mult, const, const MATRIX_CLASS<T> &, MATRIX_CLASS<T> &);
133 
134  // MATRIX_CLASS& operator*=(const MATRIX_CLASS &)
135 #if __GNUC_PREREQ(4,6)
136  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
137 #endif
138  MATRIX_INTERFACE5(MATRIX_CLASS<T>&, operator*= , const MATRIX_CLASS<T> &);
139 
140  // void Scale(const T &, MATRIX_CLASS &) const
141 #if __GNUC_PREREQ(4,6)
142  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
143 #endif
144  MATRIX_INTERFACE2(void, Scale, const, const T &, MATRIX_CLASS<T> &);
145 
146  // bool Load(const std::string &)
147 #if __GNUC_PREREQ(4,6)
148  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
149 #endif
150  MATRIX_INTERFACE5(bool, Load , const std::string &);
151 
152  // bool Save(const std::string &) const
153 #if __GNUC_PREREQ(4,6)
154  #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
155 #endif
156  MATRIX_INTERFACE(bool, Save, const , const std::string &);
157 
158  // bool Save2(const std::string &) const does not exist
159  // MATRIX_INTERFACE(bool, Save2, const, const std::string &);
160 
161  // ....... unfinished
162  }
163 
164  MatrixInterfaceCheck()
165  {
166  void(*p)() = Constraints; p=0;
167  }
168 
169 
170 };
171 
172 int main(int argc, char *argv[])
173 {
174  // if one of the lines below does not compile, the interface of the
175  // matrix class in question is not conformal with this check. Either the
176  //
177 
178  //MatrixInterfaceCheck<Matrix, Vector, double> m;
179  //MatrixInterfaceCheck<Matrix2x2, Vector2, double > m2x2;
180  MatrixInterfaceCheck<Matrix3x3, Vector3, double > m3x3;
181  //MatrixInterfaceCheck<Matrix3x4, Vector4, double> m3x4;
182  //MatrixInterfaceCheck<Matrix4x4, Vector4, double> m4x4;
183  //MatrixInterfaceCheck<SymmetricMatrix3x3, Vector3, double> m4x4;
184  return 0;
185 }