00001 # ifndef _XVFUNCTOID_H_
00002 # define _XVFUNCTOID_H_
00003
00004
00005
00006
00007
00008 template<class F, class R>
00009 class XVAbsFunctoid {
00010 public:
00011 typedef F Function ;
00012 typedef R Result ;
00013 protected:
00014 F f ;
00015 public:
00016 explicit XVAbsFunctoid( const F& fn ) : f(fn) {}
00017 virtual operator bool(void) { return f ; }
00018 };
00019
00020
00021
00022 template<class F, class R>
00023 class XVFunctoid0 : public XVAbsFunctoid<F,R> {
00024 typedef XVAbsFunctoid<F,R> Base ;
00025 public:
00026 explicit XVFunctoid0( const F& fn ) : Base(fn) {}
00027 virtual R operator () (void) = 0 ;
00028 };
00029
00030 template<class F, class R>
00031 class XVDirectFun0 : public XVFunctoid0<F,R> {
00032 typedef XVFunctoid0<F,R> Base ;
00033 public:
00034 explicit XVDirectFun0( const F& fn ) : Base(fn) {}
00035 virtual R operator () (void) { return f() ; }
00036 };
00037
00038 template<class F, class R>
00039 class XVImplicitFun0 : public XVFunctoid0<F,R> {
00040 typedef XVFunctoid0<F,R> Base ;
00041 public:
00042 explicit XVImplicitFun0( const F& fn ) : Base(fn) {}
00043 virtual R operator () (void) { R r ; f(r) ; return r ; }
00044 };
00045
00046 template<class F, class R>
00047 class XVImpClassFun0 : public XVFunctoid0<F,R> {
00048 typedef XVFunctoid0<F,R> Base ;
00049 public:
00050 explicit XVImpClassFun0( const F& fn ) : Base(fn) {}
00051 virtual R operator () (void) { R r ; (r.*f)() ; return r ; }
00052 };
00053
00054 template<class F, class R, class C>
00055 class XVClassFun0 : public XVFunctoid0<F,R> {
00056 typedef XVFunctoid0<F,R> Base ;
00057 protected:
00058 C c ;
00059 public:
00060 explicit XVClassFun0( const F& fn, const C& host ) : Base(fn), c(host) {}
00061 virtual R operator () (void) { return (c.*f)() ; }
00062 C * operator -> (void) { return &c ; }
00063 const C * operator -> (void) const { return &c ; }
00064 };
00065
00066 template<class F, class R, class C>
00067 class XVClassPtrFun0 : public XVFunctoid0<F,R> {
00068 typedef XVFunctoid0<F,R> Base ;
00069 protected:
00070 C * c ;
00071 public:
00072 explicit XVClassPtrFun0( const F& fn, C * host ) : Base(fn), c(host) {}
00073 virtual R operator () (void) { return (c->*f)() ; }
00074 C * operator -> (void) { return c ; }
00075 const C * operator -> (void) const { return c ; }
00076 };
00077
00078
00079
00080 template<class F, class R, class A1>
00081 class XVFunctoid1 : public XVAbsFunctoid<F,R> {
00082 typedef XVAbsFunctoid<F,R> Base ;
00083 public:
00084 typedef A1 Argument1 ;
00085 public:
00086 explicit XVFunctoid1( const F& fn ) : Base(fn) {}
00087 virtual R operator () ( const A1& a1 ) = 0 ;
00088 };
00089
00090 template<class F, class R, class A1>
00091 class XVDirectFun1 : public XVFunctoid1<F,R,A1> {
00092 typedef XVFunctoid1<F,R,A1> Base ;
00093 public:
00094 explicit XVDirectFun1( const F& fn ) : Base(fn) {}
00095 virtual R operator () ( const A1& a1 ) { return f(a1) ; }
00096 };
00097
00098 template<class F, class R, class A1>
00099 class XVImplicitFun1a : public XVFunctoid1<F,R,A1> {
00100 typedef XVFunctoid1<F,R,A1> Base ;
00101 public:
00102 explicit XVImplicitFun1a( const F& fn ) : Base(fn) {}
00103 virtual R operator () ( const A1& a1 ) { R r ; f(r,a1) ; return r ; }
00104 };
00105
00106 template<class F, class R, class A1>
00107 class XVImplicitFun1b : public XVFunctoid1<F,R,A1> {
00108 typedef XVFunctoid1<F,R,A1> Base ;
00109 public:
00110 explicit XVImplicitFun1b( const F& fn ) : Base(fn) {}
00111 virtual R operator () ( const A1& a1 ) { R r ; f(a1,r) ; return r ; }
00112 };
00113
00114 template<class F, class R, class A1>
00115 class XVImpClassFun1 : public XVFunctoid1<F,R,A1> {
00116 typedef XVFunctoid1<F,R,A1> Base ;
00117 public:
00118 explicit XVImpClassFun1( const F& fn ) : Base(fn) {}
00119 virtual R operator () ( const A1& a1 ) { R r ; (r.*f)(a1) ; return r ; }
00120 };
00121
00122 template<class F, class R, class A1>
00123 class XVMemberFun1 : public XVFunctoid1<F,R,A1> {
00124 typedef XVFunctoid1<F,R,A1> Base ;
00125 public:
00126 explicit XVMemberFun1( const F& fn ) : Base(fn) {}
00127 virtual R operator () ( const A1& a1 ) { return (a1.*f)() ; }
00128 };
00129
00130 template<class F, class R, class A1>
00131 class XVDataMemFun : public XVFunctoid1<F,R,A1> {
00132 typedef XVFunctoid1<F,R,A1> Base ;
00133 public:
00134 explicit XVDataMemFun( const F& fn ) : Base(fn) {}
00135 virtual R operator () ( const A1& a1 ) { return a1.*f ; }
00136 };
00137
00138 template<class F, class R, class A1, class C>
00139 class XVClassFun1 : public XVFunctoid1<F,R,A1> {
00140 typedef XVFunctoid1<F,R,A1> Base ;
00141 protected:
00142 C c ;
00143 public:
00144 explicit XVClassFun1( const F& fn, const C& host ) : Base(fn), c(host) {}
00145 virtual R operator () ( const A1& a1 ) { return (c.*f)(a1) ; }
00146 C * operator -> (void) { return &c ; }
00147 const C * operator -> (void) const { return &c ; }
00148 };
00149
00150 template<class F, class R, class A1, class C>
00151 class XVClassPtrFun1 : public XVFunctoid1<F,R,A1> {
00152 typedef XVFunctoid1<F,R,A1> Base ;
00153 protected:
00154 C * c ;
00155 public:
00156 explicit XVClassPtrFun1( const F& fn, C * host ) : Base(fn), c(host) {}
00157 virtual R operator () ( const A1& a1 ) { return (c->*f)(a1) ; }
00158 C * operator -> (void) { return c ; }
00159 const C * operator -> (void) const { return c ; }
00160 };
00161
00162
00163
00164 template<class F, class R, class A1, class A2>
00165 class XVFunctoid2 : public XVAbsFunctoid<F,R> {
00166 typedef XVAbsFunctoid<F,R> Base ;
00167 public:
00168 typedef A1 Argument1 ;
00169 typedef A2 Argument2 ;
00170 public:
00171 explicit XVFunctoid2( const F& fn ) : Base(fn) {}
00172 virtual R operator () ( const A1& a1, const A2& a2 ) = 0 ;
00173 };
00174
00175 template<class F, class R, class A1, class A2>
00176 class XVDirectFun2 : public XVFunctoid2<F,R,A1,A2> {
00177 typedef XVFunctoid2<F,R,A1,A2> Base ;
00178 public:
00179 explicit XVDirectFun2( const F& fn ) : Base(fn) {}
00180 virtual R operator () ( const A1& a1, const A2& a2 ) { return f(a1,a2) ; }
00181 };
00182
00183 template<class F, class R, class A1, class A2>
00184 class XVImplicitFun2a : public XVFunctoid2<F,R,A1,A2> {
00185 typedef XVFunctoid2<F,R,A1,A2> Base ;
00186 public:
00187 explicit XVImplicitFun2a( const F& fn ) : Base(fn) {}
00188 virtual R operator () ( const A1& a1, const A2& a2 )
00189 { R r ; f(r,a1,a2) ; return r ; }
00190 };
00191
00192 template<class F, class R, class A1, class A2>
00193 class XVImplicitFun2b : public XVFunctoid2<F,R,A1,A2> {
00194 typedef XVFunctoid2<F,R,A1,A2> Base ;
00195 public:
00196 explicit XVImplicitFun2b( const F& fn ) : Base(fn) {}
00197 virtual R operator () ( const A1& a1, const A2& a2 )
00198 { R r ; f(a1,a2,r) ; return r ; }
00199 };
00200
00201 template<class F, class R, class A1, class A2>
00202 class XVImpClassFun2 : public XVFunctoid2<F,R,A1,A2> {
00203 typedef XVFunctoid2<F,R,A1,A2> Base ;
00204 public:
00205 explicit XVImpClassFun2( const F& fn ) : Base(fn) {}
00206 virtual R operator () ( const A1& a1, const A2& a2 )
00207 { R r ; (r.*f)(a1,a2) ; return r ; }
00208 };
00209
00210 template<class F, class R, class A1, class A2>
00211 class XVMemberFun2a : public XVFunctoid2<F,R,A1,A2> {
00212 typedef XVFunctoid2<F,R,A1,A2> Base ;
00213 public:
00214 explicit XVMemberFun2a( const F& fn ) : Base(fn) {}
00215 virtual R operator () ( const A1& a1, const A2& a2 ) { return (a1.*f)(a2); }
00216 };
00217
00218 template<class F, class R, class A1, class A2>
00219 class XVMemberFun2b : public XVFunctoid2<F,R,A1,A2> {
00220 typedef XVFunctoid2<F,R,A1,A2> Base ;
00221 public:
00222 explicit XVMemberFun2b( const F& fn ) : Base(fn) {}
00223 virtual R operator () ( const A1& a1, const A2& a2 ) { return (a2.*f)(a1); }
00224 };
00225
00226 template<class F, class R, class A1, class A2, class C>
00227 class XVClassFun2 : public XVFunctoid2<F,R,A1,A2> {
00228 typedef XVFunctoid2<F,R,A1,A2> Base ;
00229 protected:
00230 C c ;
00231 public:
00232 explicit XVClassFun2( const F& fn, const C& host ) : Base(fn), c(host) {}
00233 virtual R operator () ( const A1& a1, const A2& a2 )
00234 { return (c.*f)(a1,a2) ; }
00235 C * operator -> (void) { return &c ; }
00236 const C * operator -> (void) const { return &c ; }
00237 };
00238
00239 template<class F, class R, class A1, class A2, class C>
00240 class XVClassPtrFun2 : public XVFunctoid2<F,R,A1,A2> {
00241 typedef XVFunctoid2<F,R,A1,A2> Base ;
00242 protected:
00243 C * c ;
00244 public:
00245 explicit XVClassPtrFun2( const F& fn, C * host ) : Base(fn), c(host) {}
00246 virtual R operator () ( const A1& a1, const A2& a2 )
00247 { return (c->*f)(a1,a2) ; }
00248 C * operator -> (void) { return c ; }
00249 const C * operator -> (void) const { return c ; }
00250 };
00251
00252
00253
00254
00255 template<class F, class R, class A1, class A2, class A3>
00256 class XVFunctoid3 : public XVAbsFunctoid<F,R> {
00257 typedef XVAbsFunctoid<F,R> Base ;
00258 public:
00259 typedef A1 Argument1 ;
00260 typedef A2 Argument2 ;
00261 typedef A3 Argument3 ;
00262 public:
00263 explicit XVFunctoid3( const F& fn ) : Base(fn) {}
00264 virtual R operator () ( const A1& a1, const A2& a2, const A3& a3 ) = 0 ;
00265 };
00266
00267 template<class F, class R, class A1, class A2, class A3>
00268 class XVDirectFun3 : public XVFunctoid3<F,R,A1,A2,A3> {
00269 typedef XVFunctoid3<F,R,A1,A2,A3> Base ;
00270 public:
00271 explicit XVDirectFun3( const F& fn ) : Base(fn) {}
00272 virtual R operator () ( const A1& a1, const A2& a2, const A3& a3 )
00273 { return f(a1,a2,a3) ; }
00274 };
00275
00276 template<class F, class R, class A1, class A2, class A3>
00277 class XVImplicitFun3a : public XVFunctoid3<F,R,A1,A2,A3> {
00278 typedef XVFunctoid3<F,R,A1,A2,A3> Base ;
00279 public:
00280 explicit XVImplicitFun3a( const F& fn ) : Base(fn) {}
00281 virtual R operator () ( const A1& a1, const A2& a2, const A3& a3 )
00282 { R r ; f(r,a1,a2,a3) ; return r ; }
00283 };
00284
00285 template<class F, class R, class A1, class A2, class A3>
00286 class XVImplicitFun3b : public XVFunctoid3<F,R,A1,A2,A3> {
00287 typedef XVFunctoid3<F,R,A1,A2,A3> Base ;
00288 public:
00289 explicit XVImplicitFun3b( const F& fn ) : Base(fn) {}
00290 virtual R operator () ( const A1& a1, const A2& a2, const A3& a3 )
00291 { R r ; f(a1,a2,a3,r) ; return r ; }
00292 };
00293
00294 template<class F, class R, class A1, class A2, class A3>
00295 class XVImpClassFun3 : public XVFunctoid3<F,R,A1,A2,A3> {
00296 typedef XVFunctoid3<F,R,A1,A2,A3> Base ;
00297 public:
00298 explicit XVImpClassFun3( const F& fn ) : Base(fn) {}
00299 virtual R operator () ( const A1& a1, const A2& a2, const A3& a3 )
00300 { R r ; (r.*f)(a1,a2,a3) ; return r ; }
00301 };
00302
00303 template<class F, class R, class A1, class A2, class A3>
00304 class XVMemberFun3a : public XVFunctoid3<F,R,A1,A2,A3> {
00305 typedef XVFunctoid3<F,R,A1,A2,A3> Base ;
00306 public:
00307 explicit XVMemberFun3a( const F& fn ) : Base(fn) {}
00308 virtual R operator () ( const A1& a1, const A2& a2, const A3& a3 )
00309 { return (a1.*f)(a2,a3); }
00310 };
00311
00312 template<class F, class R, class A1, class A2, class A3>
00313 class XVMemberFun3b : public XVFunctoid3<F,R,A1,A2,A3> {
00314 typedef XVFunctoid3<F,R,A1,A2,A3> Base ;
00315 public:
00316 explicit XVMemberFun3b( const F& fn ) : Base(fn) {}
00317 virtual R operator () ( const A1& a1, const A2& a2, const A3& a3 )
00318 { return (a3.*f)(a1,a2); }
00319 };
00320
00321
00322 template<class F, class R, class A1, class A2, class A3,class C>
00323 class XVClassFun3 : public XVFunctoid3<F,R,A1,A2,A3> {
00324 typedef XVFunctoid3<F,R,A1,A2,A3> Base ;
00325 protected:
00326 C c ;
00327 public:
00328 explicit XVClassFun3( const F& fn, const C& host ) : Base(fn), c(host) {}
00329 virtual R operator () ( const A1& a1, const A2& a2, const A3& a3 )
00330 { return (c.*f)(a1,a2,a3) ; }
00331 C * operator -> (void) { return &c ; }
00332 const C * operator -> (void) const { return &c ; }
00333 };
00334
00335
00336 template<class F, class R, class A1, class A2, class A3, class C>
00337 class XVClassPtrFun3 : public XVFunctoid3<F,R,A1,A2,A3> {
00338 typedef XVFunctoid3<F,R,A1,A2,A3> Base ;
00339 protected:
00340 C * c ;
00341 public:
00342 explicit XVClassPtrFun3( const F& fn, C * host ) : Base(fn), c(host) {}
00343 virtual R operator () ( const A1& a1, const A2& a2, const A3& a3 )
00344 { return (c->*f)(a1,a2,a3) ; }
00345 C * operator -> (void) { return c ; }
00346 const C * operator -> (void) const { return c ; }
00347 };
00348
00349
00350
00351 template<class F1, class F2, class R, class A1>
00352 class XVComposeFun1 : public XVFunctoid1<F1,R,A1> {
00353 typedef XVFunctoid1<F1,R,A1> Base ;
00354 protected:
00355 F2 g ;
00356 public:
00357 explicit XVComposeFun1( const F1& fn, const F2& gn ) : Base(fn), g(gn) {}
00358 virtual R operator () ( const A1& a1 ) { return f(g(a1)); }
00359 };
00360
00361 # endif //_XVFUNCTOID_H_