aimstil  5.0.5
labelClasses.h
Go to the documentation of this file.
1 #ifndef TIL_LABEL_CLASSES_H
2 #define TIL_LABEL_CLASSES_H
3 
15 
16 
17 // includes from TIL library
18 #include "til/templateTools.h"
19 
20 
21 namespace til
22 {
23 
24  // Predeclarations
25  template < typename T > struct PointerTraits;
26 
27  // TODO: isn't it better to just have traits somewhere?
28  // Especially since inheritance here is never used...
29 
30 
31 // This macro declares both a label class and the associated test class
32 // to test whether a class has this label or not.
33 // NB: to be undef at the end of the file
34 #define DEFINE_LABEL_CLASS(name) DEFINE_LABEL_CLASS_WITH_INHERITANCE(name, )
35 
36 #define DEFINE_LABEL_CLASS_WITH_INHERITANCE(name, inherit) \
37 DEFINE_LABEL_CLASS_FULL(name##_label, Is##name) \
38 DEFINE_TEST_CLASS_FULL(is_##name, Is##name, inherit) \
39 
40 #define DEFINE_LABEL_CLASS_FULL(labelname, memtypename) \
41 class labelname { public: typedef void memtypename; }; \
42 
43 
44 // Same as above, with possible inheritance
45 // NB: to be undef at the end of the file
46 // NB: using an enum instead of a static const bool brings in somw problems with template
47 // argument deduction, especially in CPPUNIT macros.
48 // NB: I used protected instead of private just to have gcc shut up that "all member functions
49 // in class X are private"
50 #ifdef _MSC_VER
51 #define DEFINE_TEST_CLASS_FULL(testname, memtypename, inherit) \
52 template <typename T> \
53 class testname inherit \
54 { \
55 protected: \
56  typedef char Yes; \
57  struct No { char a[2]; }; \
58  template <typename U> static Yes testfunc (typename U::memtypename const*); \
59  template <typename U> static No testfunc (...); \
60 public: \
61  static const bool value = (sizeof(testfunc <T>(0)) == sizeof(Yes)); \
62 };
63 #else
64 #define DEFINE_TEST_CLASS_FULL(testname, memtypename, inherit) \
65 template <typename T> \
66 class testname inherit \
67 { \
68 protected: \
69  typedef char Yes; \
70  struct No { char a[2]; }; \
71  template <typename U> static Yes testfunc (typename U:: memtypename const*); \
72  template <typename U> static No testfunc (...); \
73 public: \
74  enum { \
75  value = (sizeof(testname <T>::template testfunc <T>(0)) == sizeof(Yes)) \
76  }; \
77 };
78 #endif
79 
80  DEFINE_TEST_CLASS_FULL(has_result_type, result_type, );
81 
82 template < typename T >
84 {
85 protected:
86  typedef char Yes;
87  struct No { char a[2]; };
88  template <typename U> static Yes isImagePointer(typename PointerTraits<U>::DataType::IsImagePointer const*);
89  template <typename U> static No isImagePointer(...);
90 public:
91  enum {
92  value = (sizeof(is_ImagePointer<T>::template isImagePointer<T>(0)) == sizeof(Yes))
93  };
94 };
95 /*
96 template < typename T >
97 class is_detemplated_functor
98 {
99 private:
100  typedef char Yes;
101  struct No { char a[2]; };
102  template
103  template <typename U> static Yes zztest(typename U::TypeStruct<double>::type const*);
104  template <typename U> static Yes zztest(typename U::TypeStruct<double,double>::type const*);
105  template <typename U> static No zztest(...);
106 public:
107  / *
108  enum {
109  value = (sizeof(is_detemplated_functor<T>::template zztest<T>(0)) == sizeof(Yes))
110  };
111  * /
112  static const bool value = (sizeof(zztest<T>(0)) == sizeof(Yes));
113 };
114 */
115 
116  // Definitions begin here
117 
121  DEFINE_LABEL_CLASS(Image);
123  DEFINE_LABEL_CLASS(ImageExtrapolator);
125  DEFINE_LABEL_CLASS(ImageFunctor);
127  DEFINE_LABEL_CLASS(ImageIterator);
129  DEFINE_LABEL_CLASS(Interpolator);
131  DEFINE_LABEL_CLASS(Mapping);
133  //DEFINE_LABEL_CLASS(SmartPtr);
135  DEFINE_LABEL_CLASS_WITH_INHERITANCE(VolumetricImageIterator, : public ImageIterator_label);
137  //DEFINE_LABEL_CLASS(Neighborhood);
138  DEFINE_LABEL_CLASS(detemplated_functor);
140  DEFINE_LABEL_CLASS(minimization_algorithm_nd);
141 
142 
143 class Neighborhood_label { typedef void IsNeighborhood; };
144 template <typename T>
146 {
147 protected:
148  typedef char Yes;
149  struct No { char a[2]; };
150  template <typename U> static Yes isNeighborhood (typename U::IsNeighborhood const*);
151  template <typename U> static No isNeighborhood (...);
152 public:
153  //static const bool value = (sizeof(isNeighborhood <T>(0)) == 1);
154  enum {
155 #ifdef _MSC_VER
156  value = (sizeof(isNeighborhood <T>(0)) == 1)
157 #else
158  value = (sizeof(is_Neighborhood<T>::template isNeighborhood<T>(0)) == sizeof(Yes))
159 #endif
160 
161  };
162 };
163 
164 
165 #undef DEFINE_LABEL_CLASS
166 #undef DEFINE_LABEL_CLASS_WITH_INHERITANCE
167 } // namespace
168 
169 #endif
170 
static Yes isImagePointer(typename PointerTraits< U >::DataType::IsImagePointer const *)
DEFINE_TEST_CLASS_FULL(has_result_type, result_type,)
Enable image extrapolation by overloading the getValue function.
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
Pointer traits.
Definition: labelClasses.h:25
Collects template tools used for library implementation.
DEFINE_LABEL_CLASS(ExtrapolableImage)
Label for extrapolable images.
DEFINE_LABEL_CLASS_WITH_INHERITANCE(VolumetricImageIterator, :public ImageIterator_label)
Label for TIL smart pointers.