[ VIGRA Homepage | Class Index | Function Index | File Index | Main Page ]
![]() |
vigra/metaprogramming.hxx | ![]() |
---|
00001 /************************************************************************/ 00002 /* */ 00003 /* Copyright 1998-2002 by Ullrich Koethe */ 00004 /* Cognitive Systems Group, University of Hamburg, Germany */ 00005 /* */ 00006 /* This file is part of the VIGRA computer vision library. */ 00007 /* ( Version 1.3.3, Aug 18 2005 ) */ 00008 /* You may use, modify, and distribute this software according */ 00009 /* to the terms stated in the LICENSE file included in */ 00010 /* the VIGRA distribution. */ 00011 /* */ 00012 /* The VIGRA Website is */ 00013 /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ 00014 /* Please direct questions, bug reports, and contributions to */ 00015 /* koethe@informatik.uni-hamburg.de */ 00016 /* */ 00017 /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ 00018 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ 00019 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ 00020 /* */ 00021 /************************************************************************/ 00022 00023 #ifndef VIGRA_METAPROGRAMMING_HXX 00024 #define VIGRA_METAPROGRAMMING_HXX 00025 00026 namespace vigra { 00027 00028 template <int N> 00029 class MetaInt 00030 { 00031 public: 00032 enum { value = N }; 00033 }; 00034 00035 struct VigraTrueType 00036 { 00037 enum { asBool = true }; 00038 }; 00039 00040 struct VigraFalseType 00041 { 00042 enum { asBool = false }; 00043 }; 00044 00045 /** \addtogroup MultiArrayTags Multi-dimensional Array Tags 00046 Meta-programming tags to mark array's as strided or unstrided. 00047 */ 00048 00049 //@{ 00050 00051 /********************************************************/ 00052 /* */ 00053 /* StridedArrayTag */ 00054 /* */ 00055 /********************************************************/ 00056 00057 /** tag for marking a MultiArray strided. 00058 00059 <b>\#include</b> 00060 "<a href="multi__array_8hxx-source.html">vigra/multi_array.hxx</a>" 00061 00062 Namespace: vigra 00063 */ 00064 struct StridedArrayTag {}; 00065 00066 /********************************************************/ 00067 /* */ 00068 /* UnstridedArrayTag */ 00069 /* */ 00070 /********************************************************/ 00071 00072 /** tag for marking a MultiArray unstrided. 00073 00074 <b>\#include</b> 00075 "<a href="multi__array_8hxx-source.html">vigra/multi_array.hxx</a>" 00076 00077 Namespace: vigra 00078 */ 00079 struct UnstridedArrayTag {}; 00080 00081 template<class T> 00082 class TypeTraits 00083 { 00084 public: 00085 typedef VigraFalseType isConst; 00086 typedef VigraFalseType isPOD; 00087 typedef VigraFalseType isBuiltinType; 00088 }; 00089 00090 #ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION 00091 00092 template<class T> 00093 class TypeTraits<T const> 00094 : public TypeTraits<T> 00095 { 00096 public: 00097 typedef VigraTrueType isConst; 00098 }; 00099 00100 template<class T> 00101 class TypeTraits<T *> 00102 { 00103 public: 00104 typedef VigraFalseType isConst; 00105 typedef VigraTrueType isPOD; 00106 typedef VigraTrueType isBuiltinType; 00107 }; 00108 00109 template<class T> 00110 class TypeTraits<T const *> 00111 { 00112 public: 00113 typedef VigraFalseType isConst; 00114 typedef VigraTrueType isPOD; 00115 typedef VigraTrueType isBuiltinType; 00116 }; 00117 00118 #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION 00119 00120 #define VIGRA_TYPE_TRAITS(type) \ 00121 template<> \ 00122 class TypeTraits<type> \ 00123 { \ 00124 public: \ 00125 typedef VigraFalseType isConst; \ 00126 typedef VigraTrueType isPOD; \ 00127 typedef VigraTrueType isBuiltinType; \ 00128 }; 00129 00130 VIGRA_TYPE_TRAITS(char) 00131 VIGRA_TYPE_TRAITS(signed char) 00132 VIGRA_TYPE_TRAITS(unsigned char) 00133 VIGRA_TYPE_TRAITS(short) 00134 VIGRA_TYPE_TRAITS(unsigned short) 00135 VIGRA_TYPE_TRAITS(int) 00136 VIGRA_TYPE_TRAITS(unsigned int) 00137 VIGRA_TYPE_TRAITS(long) 00138 VIGRA_TYPE_TRAITS(unsigned long) 00139 VIGRA_TYPE_TRAITS(float) 00140 VIGRA_TYPE_TRAITS(double) 00141 VIGRA_TYPE_TRAITS(long double) 00142 00143 #undef VIGRA_TYPE_TRAITS 00144 00145 //@} 00146 00147 template <class L, class R> 00148 struct And; 00149 00150 template <> 00151 struct And<VigraFalseType, VigraFalseType> 00152 { 00153 typedef VigraFalseType result; 00154 static const bool boolResult = false; 00155 }; 00156 00157 template <> 00158 struct And<VigraFalseType, VigraTrueType> 00159 { 00160 typedef VigraFalseType result; 00161 static const bool boolResult = false; 00162 }; 00163 00164 template <> 00165 struct And<VigraTrueType, VigraFalseType> 00166 { 00167 typedef VigraFalseType result; 00168 static const bool boolResult = false; 00169 }; 00170 00171 template <> 00172 struct And<VigraTrueType, VigraTrueType> 00173 { 00174 typedef VigraTrueType result; 00175 static const bool boolResult = true; 00176 }; 00177 00178 template <class L, class R> 00179 struct Or; 00180 00181 template <> 00182 struct Or<VigraFalseType, VigraFalseType> 00183 { 00184 typedef VigraFalseType result; 00185 static const bool boolResult = false; 00186 }; 00187 00188 template <> 00189 struct Or<VigraTrueType, VigraFalseType> 00190 { 00191 typedef VigraTrueType result; 00192 static const bool boolResult = true; 00193 }; 00194 00195 template <> 00196 struct Or<VigraFalseType, VigraTrueType> 00197 { 00198 typedef VigraTrueType result; 00199 static const bool boolResult = true; 00200 }; 00201 00202 template <> 00203 struct Or<VigraTrueType, VigraTrueType> 00204 { 00205 typedef VigraTrueType result; 00206 static const bool boolResult = true; 00207 }; 00208 00209 #ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION 00210 00211 template <class PREDICATE, class TRUECASE, class FALSECASE> 00212 struct If; 00213 00214 template <class TRUECASE, class FALSECASE> 00215 struct If<VigraTrueType, TRUECASE, FALSECASE> 00216 { 00217 typedef TRUECASE type; 00218 }; 00219 00220 template <class TRUECASE, class FALSECASE> 00221 struct If<VigraFalseType, TRUECASE, FALSECASE> 00222 { 00223 typedef FALSECASE type; 00224 }; 00225 00226 template <bool PREDICATE, class TRUECASE, class FALSECASE> 00227 struct IfBool; 00228 00229 template <class TRUECASE, class FALSECASE> 00230 struct IfBool<true, TRUECASE, FALSECASE> 00231 { 00232 typedef TRUECASE type; 00233 }; 00234 00235 template <class TRUECASE, class FALSECASE> 00236 struct IfBool<false, TRUECASE, FALSECASE> 00237 { 00238 typedef FALSECASE type; 00239 }; 00240 00241 template <class L, class R> 00242 struct IsSameType 00243 { 00244 typedef VigraFalseType result; 00245 static const bool boolResult = false; 00246 }; 00247 00248 template <class T> 00249 struct IsSameType<T, T> 00250 { 00251 typedef VigraTrueType result; 00252 static const bool boolResult = true; 00253 }; 00254 00255 template <class DERIVED, class BASE> 00256 struct IsDerivedFrom 00257 { 00258 typedef char falseResult[1]; 00259 typedef char trueResult[2]; 00260 00261 static falseResult * testIsDerivedFrom(...); 00262 static trueResult * testIsDerivedFrom(BASE const *); 00263 00264 enum { resultSize = sizeof(*testIsDerivedFrom((DERIVED const *)0)) }; 00265 00266 static const bool boolResult = (resultSize == 2); 00267 typedef typename 00268 IfBool<boolResult, VigraTrueType, VigraFalseType>::type 00269 result; 00270 }; 00271 00272 #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION 00273 00274 } // namespace vigra 00275 00276 #endif /* VIGRA_METAPROGRAMMING_HXX */
© Ullrich Köthe (koethe@informatik.uni-hamburg.de) |
html generated using doxygen and Python
|