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