00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef IMG_IMAGE_STATE_DISPATCH_HH
00026 #define IMG_IMAGE_STATE_DISPATCH_HH
00027
00028 #include <ost/message.hh>
00029 #include <string>
00030
00031 #include <ost/message.hh>
00032
00033 #include "image_state_impl.hh"
00034 #include "image_state_def.hh"
00035
00036 namespace ost { namespace img { namespace image_state {
00037
00038 class DLLEXPORT DispatchException: public Error {
00039 public:
00040 DispatchException(const String& m):
00041 Error(m)
00042 {}
00043 };
00044
00045 template <typename T, class D>
00046 class ImageStateImpl;
00047
00048 namespace dispatch {
00049
00051
00052
00053
00055
00066 template <template <typename T, class D> class FNC>
00067 struct unary_dispatch_ip {
00068
00069 #define ISI_UNARY_DISPATCH_IP_CALL(TYPE,fnc,isb) \
00070 else if(TYPE * is = dynamic_cast<TYPE *>(isb)) fnc(is)
00071
00072 void operator()(ImageStateBase* isb) {
00073 if(false);
00074 ISI_UNARY_DISPATCH_IP_CALL(RealSpatialImageState,call,isb);
00075 ISI_UNARY_DISPATCH_IP_CALL(ComplexSpatialImageState,call,isb);
00076 ISI_UNARY_DISPATCH_IP_CALL(RealFrequencyImageState,call,isb);
00077 ISI_UNARY_DISPATCH_IP_CALL(ComplexFrequencyImageState,call,isb);
00078 ISI_UNARY_DISPATCH_IP_CALL(ComplexHalfFrequencyImageState,call,isb);
00079 ISI_UNARY_DISPATCH_IP_CALL(WordSpatialImageState,call,isb);
00080 else throw DispatchException("unknown image state in unary_dispatch_ip");
00081 }
00082
00083 #undef ISI_UNARY_DISPATCH_IP_CALL
00084
00085 template <typename T, class D>
00086 void call(ImageStateImpl<T,D>* isi) {
00087 static FNC<T,D> fnc;
00088 fnc(isi);
00089 }
00090
00091 };
00092
00093
00095
00106 template <template <typename T, class D> class FNC>
00107 struct unary_dispatch_op {
00108
00109 #define ISI_UNARY_DISPATCH_OP_CALL(TYPE,fnc,isb) \
00110 else if(const TYPE * is = dynamic_cast<const TYPE *>(isb)) return fnc(is)
00111
00112 ImageStateBasePtr operator()(const ImageStateBase* isb) {
00113 if(false);
00114 ISI_UNARY_DISPATCH_OP_CALL(RealSpatialImageState,call,isb);
00115 ISI_UNARY_DISPATCH_OP_CALL(ComplexSpatialImageState,call,isb);
00116 ISI_UNARY_DISPATCH_OP_CALL(RealFrequencyImageState,call,isb);
00117 ISI_UNARY_DISPATCH_OP_CALL(ComplexFrequencyImageState,call,isb);
00118 ISI_UNARY_DISPATCH_OP_CALL(ComplexHalfFrequencyImageState,call,isb);
00119 ISI_UNARY_DISPATCH_OP_CALL(WordSpatialImageState,call,isb);
00120 else throw DispatchException("unknown image state in unary_dispatch_op");
00121 }
00122
00123 #undef ISI_UNARY_DISPATCH_OP_CALL
00124
00125 template <typename T, class D>
00126 ImageStateBasePtr call(const ImageStateImpl<T,D>* isi) {
00127 static FNC<T,D> fnc;
00128 return fnc(isi);
00129 }
00130 };
00131
00133
00134
00136
00150 template <template <typename T1, class D1, typename T2, class D2> class FNC>
00151 struct binary_dispatch_ip {
00152
00153 #define ISI_BINARY_DISPATCH_IP_CALL_LEFT(TYPE,fnc,lhs,rhs) \
00154 else if(TYPE * is = dynamic_cast<TYPE *>(lhs)) fnc(is,rhs)
00155
00156 void operator()(ImageStateBase* lhs, const ImageStateBase* rhs) {
00157 if(false);
00158 ISI_BINARY_DISPATCH_IP_CALL_LEFT(RealSpatialImageState,left,lhs,rhs);
00159 ISI_BINARY_DISPATCH_IP_CALL_LEFT(ComplexSpatialImageState,left,lhs,rhs);
00160 ISI_BINARY_DISPATCH_IP_CALL_LEFT(RealFrequencyImageState,left,lhs,rhs);
00161 ISI_BINARY_DISPATCH_IP_CALL_LEFT(ComplexFrequencyImageState,left,lhs,rhs);
00162 ISI_BINARY_DISPATCH_IP_CALL_LEFT(ComplexHalfFrequencyImageState,left,lhs,rhs);
00163 ISI_BINARY_DISPATCH_IP_CALL_LEFT(WordSpatialImageState,left,lhs,rhs);
00164 else {
00165 throw DispatchException("unknown lhs image state in binary_dispatch_ip");
00166 }
00167 }
00168
00169 #undef ISI_BINARY_DISPATCH_IP_CALL_LEFT
00170
00171 #define ISI_BINARY_DISPATCH_IP_CALL_RIGHT(TYPE,fnc,lhs,rhs) \
00172 else if(const TYPE * is = dynamic_cast<const TYPE *>(rhs)) fnc(lhs,is)
00173
00174 template <typename T1, class D1>
00175 void left(ImageStateImpl<T1,D1>* lhs, const ImageStateBase* rhs) {
00176 if(false);
00177 ISI_BINARY_DISPATCH_IP_CALL_RIGHT(RealSpatialImageState,right,lhs,rhs);
00178 ISI_BINARY_DISPATCH_IP_CALL_RIGHT(ComplexSpatialImageState,right,lhs,rhs);
00179 ISI_BINARY_DISPATCH_IP_CALL_RIGHT(RealFrequencyImageState,right,lhs,rhs);
00180 ISI_BINARY_DISPATCH_IP_CALL_RIGHT(ComplexFrequencyImageState,right,lhs,rhs);
00181 ISI_BINARY_DISPATCH_IP_CALL_RIGHT(ComplexHalfFrequencyImageState,right,lhs,rhs);
00182 ISI_BINARY_DISPATCH_IP_CALL_RIGHT(WordSpatialImageState,right,lhs,rhs);
00183 else {
00184 throw DispatchException("unknown rhs image state in binary_dispatch_ip");
00185 }
00186 }
00187
00188 #undef ISI_BINARY_DISPATCH_IP_CALL_RIGHT
00189
00190 template <typename T1, class D1, typename T2, class D2>
00191 void right(ImageStateImpl<T1,D1>* lhs, const ImageStateImpl<T2,D2>* rhs) {
00192 static FNC<T1,D1,T2,D2> fnc;
00193 fnc(lhs,rhs);
00194 }
00195 };
00196
00197
00198
00200
00213 template <template <typename T1, class D1, typename T2, class D2> class FNC>
00214 struct binary_dispatch_op {
00215
00216 #define ISI_BINARY_DISPATCH_OP_CALL_LEFT(TYPE,fnc,lhs,rhs) \
00217 else if(const TYPE * is = dynamic_cast<const TYPE *>(lhs)) return fnc(is,rhs)
00218
00219 ImageStateBasePtr operator()(const ImageStateBase* lhs, const ImageStateBase* rhs) {
00220 if(false);
00221 ISI_BINARY_DISPATCH_OP_CALL_LEFT(RealSpatialImageState,left,lhs,rhs);
00222 ISI_BINARY_DISPATCH_OP_CALL_LEFT(ComplexSpatialImageState,left,lhs,rhs);
00223 ISI_BINARY_DISPATCH_OP_CALL_LEFT(RealFrequencyImageState,left,lhs,rhs);
00224 ISI_BINARY_DISPATCH_OP_CALL_LEFT(ComplexFrequencyImageState,left,lhs,rhs);
00225 ISI_BINARY_DISPATCH_OP_CALL_LEFT(ComplexHalfFrequencyImageState,left,lhs,rhs);
00226 ISI_BINARY_DISPATCH_OP_CALL_LEFT(WordSpatialImageState,left,lhs,rhs);
00227 else throw DispatchException("unknown lhs image state in binary_dispatch_op");
00228 }
00229
00230 #undef ISI_BINARY_DISPATCH_OP_CALL_LEFT
00231
00232 #define ISI_BINARY_DISPATCH_OP_CALL_RIGHT(TYPE,fnc,lhs,rhs) \
00233 else if(const TYPE * is = dynamic_cast<const TYPE *>(rhs)) return fnc(lhs,is)
00234
00235 template <typename T1, class D1>
00236 ImageStateBasePtr left(const ImageStateImpl<T1,D1>* lhs, const ImageStateBase* rhs) {
00237 if(false);
00238 ISI_BINARY_DISPATCH_OP_CALL_RIGHT(RealSpatialImageState,right,lhs,rhs);
00239 ISI_BINARY_DISPATCH_OP_CALL_RIGHT(ComplexSpatialImageState,right,lhs,rhs);
00240 ISI_BINARY_DISPATCH_OP_CALL_RIGHT(RealFrequencyImageState,right,lhs,rhs);
00241 ISI_BINARY_DISPATCH_OP_CALL_RIGHT(ComplexFrequencyImageState,right,lhs,rhs);
00242 ISI_BINARY_DISPATCH_OP_CALL_RIGHT(ComplexHalfFrequencyImageState,right,lhs,rhs);
00243 ISI_BINARY_DISPATCH_OP_CALL_RIGHT(WordSpatialImageState,right,lhs,rhs);
00244 else throw DispatchException("unknown rhs image state in binary_dispatch_op");
00245 }
00246
00247 #undef ISI_BINARY_DISPATCH_OP_CALL_RIGHT
00248
00249 template <typename T1, class D1, typename T2, class D2>
00250 ImageStateBasePtr right(const ImageStateImpl<T1,D1>* lhs, const ImageStateImpl<T2,D2>* rhs) {
00251 static FNC<T1,D1,T2,D2> fnc;
00252 return fnc(lhs,rhs);
00253 }
00254
00255
00256 };
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 }}}}
00288
00289 #endif