InterfaceTraits.h 5.61 KB
Newer Older
Floris Berendsen's avatar
Floris Berendsen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*=========================================================================
 *
 *  Copyright Leiden University Medical Center, Erasmus University Medical 
 *  Center and contributors
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

20
21
22
#ifndef InterfaceTraits_h
#define InterfaceTraits_h

23
24
//TODO: note, maybe this functionality shouldn't be called a Trait, since we use a method ::Get(). Is Policy a better name?

25
#include "Interfaces.h"
26
#include "itkMacro.h"
27
28
29
//#include <boost/static_assert.hpp>
#include <boost/mpl/assert.hpp>
//#include <type_traits>
FBerendsen's avatar
FBerendsen committed
30

Floris Berendsen's avatar
Floris Berendsen committed
31
namespace selx
32
33
{
// Traits to get printable interface name
34
35
36

// In our toolbox for each InterfaceType it is required to implement InterfaceName<InterfaceType>::Get()
// If one omits this, the implementation falls back to the default implementation that provides a compiler error message including the InterfaceType name for which the specialization is missing.
37
38
39
template <typename T>
struct InterfaceName
{
40
41
42
  struct PLEASE_IMPLEMENT_INTERFACENAME_GET_FOR_THIS_TYPE; 
  //TODO message produced by BOOST_MPL_ASSERT_MSG is not yet very clear
  BOOST_MPL_ASSERT_MSG( false, PLEASE_IMPLEMENT_INTERFACENAME_GET_FOR_THIS_TYPE, (T) );
43
  static const char* Get()
FBerendsen's avatar
FBerendsen committed
44
  { 
45
46
    //static_assert(false, "Please implement a template specialization for the appropriate InterfaceName");
    // Exception should never happen since build should fail due to static assert of BOOST_MPL_ASSERT_MSG.
FBerendsen's avatar
FBerendsen committed
47
    itkGenericExceptionMacro("Please implement a template specialization for the appropriate InterfaceName");
48
49
50
51
    return typeid(T).name();
  }
};

52
53
// The specializations for each type of Interface supported by the toolbox

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
template <>
struct InterfaceName < MetricValueInterface >
{
  static const char* Get()
  {
    return "MetricValueInterface";
  }
};
template <>
struct InterfaceName < MetricDerivativeInterface >
{
  static const char* Get()
  {
    return "MetricDerivativeInterface";
  }
};
template <>
struct InterfaceName < OptimizerUpdateInterface >
{
  static const char* Get()
  {
    return "OptimizerUpdateInterface";
  }
};

79
80
81
82
83
84
85
86
87
template <>
struct InterfaceName < ConflictinUpdateInterface >
{
  static const char* Get()
  {
    return "ConflictinUpdateInterface";
  }
};

Floris Berendsen's avatar
Floris Berendsen committed
88
89
90
91
92
93
94
95
96
template <>
struct InterfaceName < TransformedImageInterface >
{
  static const char* Get()
  {
    return "TransformedImageInterface";
  }
};

97

Floris Berendsen's avatar
Floris Berendsen committed
98
// InterfaceName<T>::Get() should return "itkImageSourceInterface" no matter over which arguments itkImageSourceInterface is templated
99
100
101
102
103
104
105
106
107
template <int D, class TPixel>
struct InterfaceName < itkImageInterface <D, TPixel> >
{
  static const char* Get()
  {
    return "itkImageInterface";
  }
};

108
109
110
111
112
113
114
115
template <int D, class TPixel>
struct InterfaceName < itkImageFixedInterface <D, TPixel> >
{
	static const char* Get()
	{
		return "itkImageFixedInterface";
	}
};
116

117
118
119
120
121
122
123
124
125
template <int D>
struct InterfaceName < itkImageDomainFixedInterface <D> >
{
  static const char* Get()
  {
    return "itkImageDomainFixedInterface";
  }
};

126
127
128
129
130
131
132
133
134
template <int D, class TPixel>
struct InterfaceName < itkImageMovingInterface <D, TPixel> >
{
  static const char* Get()
  {
    return "itkImageMovingInterface";
  }
};

135

136
137
138
139
140
141
142
143
144
template <int D, class TPixel>
struct InterfaceName < DisplacementFieldItkImageSourceInterface <D, TPixel> >
{
  static const char* Get()
  {
    return "DisplacementFieldItkImageSourceInterface";
  }
};

Floris Berendsen's avatar
Floris Berendsen committed
145
146
147
148
149
150
151
152
template <int D, class TPixel>
struct InterfaceName < itkMeshInterface <D, TPixel> >
{
  static const char* Get()
  {
    return "itkMeshInterface";
  }
};
153

154

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
template <>
struct InterfaceName < SourceInterface >
{
  static const char* Get()
  {
    return "SourceInterface";
  }
};

template <>
struct InterfaceName < SinkInterface >
{
  static const char* Get()
  {
    return "SinkInterface";
  }
};

173

174
175
176
177
178
179
180
181
182
template <int D, class TPixel>
struct InterfaceName < itkMetricv4Interface <D, TPixel> >
{
  static const char* Get()
  {
    return "itkMetricv4Interface";
  }
};

183
184
185
186
187
188
189
190
191
template <class InternalComputationValueType>
struct InterfaceName < itkOptimizerv4Interface <InternalComputationValueType> >
{
  static const char* Get()
  {
    return "itkOptimizerv4Interface";
  }
};

192
193
194
195
196
197
198
199
200
201
template <class InternalComputationValueType, int D>
struct InterfaceName < itkTransformInterface <InternalComputationValueType, D> >
{
  static const char* Get()
  {
    return "itkTransformInterface";
  }
};


202
203
204
205
206
207
208
209
210
template <>
struct InterfaceName < RunRegistrationInterface >
{
  static const char* Get()
  {
    return "RunRegistrationInterface";
  }
};

211
212
213
214
215
216
217
218
template <>
struct InterfaceName < AfterRegistrationInterface >
{
  static const char* Get()
  {
    return "AfterRegistrationInterface";
  }
};
219

220
221
222
223
224
225
226
227
228
229
template <>
struct InterfaceName < ReconnectTransformInterface >
{
  static const char* Get()
  {
    return "ReconnectTransformInterface";
  }
};


230
// partial specialization of InterfaceName
Floris Berendsen's avatar
Floris Berendsen committed
231
// InterfaceName<T>::Get() should return the same name no matter whether T is an acceptor or provider interface.
232
233
234
235
236
237
238
template<typename T1>
struct InterfaceName < InterfaceAcceptor<T1> > {
  static const char* Get()
  {
    return InterfaceName<T1>::Get();
  }
};
239

Floris Berendsen's avatar
Floris Berendsen committed
240
} // end namespace selx
241
242


243
#endif // #define InterfaceTraits_h