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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _OSGFUNCTORBASE_H_
00040 #define _OSGFUNCTORBASE_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045
00046
00047
00048
00049 #include <OSGBaseTypes.h>
00050
00051 OSG_BEGIN_NAMESPACE
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00069 struct DefaultFunctorSizeTraits
00070 {
00071 typedef
00072 void ( *FuncPointerT )(void *);
00073 typedef
00074 void (DefaultFunctorSizeTraits::*InstanceFuncPointerT)(void *);
00075
00076 enum SizesE
00077 {
00078 _uiFuncPointerSize = osgStaticMax<sizeof(FuncPointerT),
00079 sizeof(InstanceFuncPointerT) >::iMax,
00080
00081 _uiObjectSize = 64
00082 };
00083 };
00084
00089 template <class Argument1T>
00090 struct ArgsCollector
00091 {
00092 typedef Argument1T ArgType;
00093 typedef Argument1T Arg1T;
00094 };
00095
00100 template <class Argument1T, class Argument2T>
00101 struct ArgsCollector2
00102 {
00103 typedef Argument1T Arg1T;
00104 typedef Argument2T Arg2T;
00105 };
00106
00111 template <class ArgT>
00112 struct ObjCallArg
00113 {
00114 typedef ArgT ObjType;
00115 typedef ArgT ArgType;
00116
00117 typedef ArgsCollector<ArgType> ArgsC;
00118 };
00119
00124 template <class ArgT>
00125 struct RefCallArg
00126 {
00127 typedef ArgT ObjType;
00128 typedef ArgT &ArgType;
00129
00130 static ObjType *getPtr(ObjType &obj)
00131 {
00132 return &obj;
00133 }
00134 };
00135
00140 template <class ArgT>
00141 struct PtrCallArg
00142 {
00143 typedef ArgT ObjType;
00144 typedef ArgT *ArgType;
00145
00146 typedef ArgsCollector<ArgType> ArgsC;
00147
00148 static ObjType *getPtr(ObjType *pObj)
00149 {
00150 return pObj;
00151 }
00152 };
00153
00158 template <class ArgT>
00159 struct CPtrCallArg
00160 {
00161 typedef typename ArgT::StoredObjectType ObjType;
00162 typedef ArgT ArgType;
00163
00164 typedef ArgsCollector<ArgType> ArgsC;
00165
00166 static ObjType *getPtr(ArgType obj)
00167 {
00168 return (&(*obj));
00169 }
00170 };
00171
00176 template <class ArgT>
00177 struct CPtrRefCallArg
00178 {
00179 typedef typename ArgT::StoredObjectType ObjType;
00180 typedef ArgT &ArgType;
00181
00182 typedef ArgsCollector<ArgType> ArgsC;
00183
00184 static ObjType *getPtr(ArgType obj)
00185 {
00186 return (&(*obj));
00187 }
00188 };
00189
00194 template <class RetT, class ClassT>
00195 struct ClassMemFunc
00196 {
00197 typedef RetT (ClassT::*MemFunc)(void);
00198 };
00199
00204 template <class RetT, class ClassT, class ArgsT>
00205 struct ClassMemFunc1
00206 {
00207 typedef typename ArgsT::Arg1T Arg1T;
00208
00209 typedef RetT (ClassT::*MemFunc)(Arg1T);
00210 };
00211
00216 template <class RetT, class ClassT, class ArgsT>
00217 struct ClassMemFunc2
00218 {
00219 typedef typename ArgsT::Arg1T Arg1T;
00220 typedef typename ArgsT::Arg2T Arg2T;
00221
00222 typedef RetT (ClassT::*MemFunc)(Arg1T, Arg2T);
00223 };
00224
00229 template <class RetT, class CallArgT>
00230 struct FunctorBuildFuncType1
00231 {
00232 typedef typename CallArgT::ArgType CallArgType;
00233 typedef typename CallArgT::ObjType ObjType;
00234
00235 typedef typename ClassMemFunc<RetT, ObjType>::MemFunc ObjFuncType;
00236
00237 typedef RetT (*FuncFunctionType)(CallArgType);
00238 };
00239
00244 template <class RetT, class CallArgT, class ArgsT>
00245 struct FunctorBuildObjFuncType1
00246 {
00247 typedef typename CallArgT ::ObjType ObjType;
00248 typedef typename ArgsT ::Arg1T ArgType;
00249
00250 typedef ArgsCollector<ArgType> ArgColl;
00251
00252 typedef typename ClassMemFunc1<RetT,
00253 ObjType,
00254 ArgColl>::MemFunc ObjFuncType;
00255 };
00256
00261 template <class RetT, class CallArgT, class ArgsT>
00262 struct FunctorBuildFuncType2
00263 {
00264 typedef typename CallArgT ::ArgType CallArgType;
00265 typedef typename CallArgT ::ObjType ObjType;
00266
00267 typedef typename ArgsT ::Arg1T ArgType;
00268
00269 typedef ArgsCollector<ArgType> ArgColl;
00270
00271 typedef typename ClassMemFunc1<RetT,
00272 ObjType,
00273 ArgColl>::MemFunc ObjFuncType;
00274
00275 typedef RetT (*FuncFunctionType)(CallArgType, ArgType);
00276 };
00277
00282 template <class RetT, class ObjCallArgT, class CallArgT, class ArgsT>
00283 struct FunctorBuildObjFuncType2
00284 {
00285 typedef typename ObjCallArgT::ObjType ObjType;
00286 typedef typename CallArgT ::ArgType Arg1T;
00287 typedef typename ArgsT ::Arg1T Arg2T;
00288
00289 typedef ArgsCollector2<Arg1T, Arg2T> ArgColl;
00290
00291 typedef typename ClassMemFunc2<RetT,
00292 ObjType,
00293 ArgColl>::MemFunc ObjFuncType;
00294 };
00295
00296
00297
00298
00299
00300
00305 template <class SizeTraitsT = DefaultFunctorSizeTraits>
00306 class FunctorBase
00307 {
00308
00309
00310 public:
00311
00312
00316 virtual ~FunctorBase(void);
00317
00319
00320
00321 protected:
00322
00323
00327 static const UInt8 ObjectValid = 0x01;
00328 static const UInt8 FuncPtrValid = 0x02;
00329
00330 static const UInt8 FunctorActive = 0x80;
00331
00333
00337 UInt8 _data1[SizeTraitsT::_uiObjectSize];
00338 UInt8 _data2[SizeTraitsT::_uiFuncPointerSize];
00339 UInt8 _flags;
00340
00342
00346 FunctorBase(void);
00347 FunctorBase(const FunctorBase &source);
00348
00350
00351
00352 private:
00353
00355 void operator =(const FunctorBase &source);
00356 };
00357
00358 OSG_END_NAMESPACE
00359
00360 #include <OSGFunctorBase.inl>
00361
00362 #endif
00363
00364