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)
00080 >::iMax * 2,
00081
00082
00083 _uiObjectSize = 64
00084 };
00085 };
00086
00091 template <class Argument1T>
00092 struct ArgsCollector
00093 {
00094 typedef Argument1T ArgType;
00095 typedef Argument1T Arg1T;
00096 };
00097
00102 template <class Argument1T, class Argument2T>
00103 struct ArgsCollector2
00104 {
00105 typedef Argument1T Arg1T;
00106 typedef Argument2T Arg2T;
00107 };
00108
00113 template <class ArgT>
00114 struct ObjCallArg
00115 {
00116 typedef ArgT ObjType;
00117 typedef ArgT ArgType;
00118
00119 typedef ArgsCollector<ArgType> ArgsC;
00120 };
00121
00126 template <class ArgT>
00127 struct RefCallArg
00128 {
00129 typedef ArgT ObjType;
00130 typedef ArgT &ArgType;
00131
00132 static ObjType *getPtr(ObjType &obj)
00133 {
00134 return &obj;
00135 }
00136 };
00137
00142 template <class ArgT>
00143 struct PtrCallArg
00144 {
00145 typedef ArgT ObjType;
00146 typedef ArgT *ArgType;
00147
00148 typedef ArgsCollector<ArgType> ArgsC;
00149
00150 static ObjType *getPtr(ObjType *pObj)
00151 {
00152 return pObj;
00153 }
00154 };
00155
00160 template <class ArgT>
00161 struct CPtrCallArg
00162 {
00163 typedef typename ArgT::StoredObjectType ObjType;
00164 typedef ArgT ArgType;
00165
00166 typedef ArgsCollector<ArgType> ArgsC;
00167
00168 static ObjType *getPtr(ArgType obj)
00169 {
00170 return (&(*obj));
00171 }
00172 };
00173
00178 template <class ArgT>
00179 struct CPtrRefCallArg
00180 {
00181 typedef typename ArgT::StoredObjectType ObjType;
00182 typedef ArgT &ArgType;
00183
00184 typedef ArgsCollector<ArgType> ArgsC;
00185
00186 static ObjType *getPtr(ArgType obj)
00187 {
00188 return (&(*obj));
00189 }
00190 };
00191
00196 template <class RetT, class ClassT>
00197 struct ClassMemFunc
00198 {
00199 typedef RetT (ClassT::*MemFunc)(void);
00200 };
00201
00206 template <class RetT, class ClassT, class ArgsT>
00207 struct ClassMemFunc1
00208 {
00209 typedef typename ArgsT::Arg1T Arg1T;
00210
00211 typedef RetT (ClassT::*MemFunc)(Arg1T);
00212 };
00213
00218 template <class RetT, class ClassT, class ArgsT>
00219 struct ClassMemFunc2
00220 {
00221 typedef typename ArgsT::Arg1T Arg1T;
00222 typedef typename ArgsT::Arg2T Arg2T;
00223
00224 typedef RetT (ClassT::*MemFunc)(Arg1T, Arg2T);
00225 };
00226
00231 template <class RetT, class CallArgT>
00232 struct FunctorBuildFuncType1
00233 {
00234 typedef typename CallArgT::ArgType CallArgType;
00235 typedef typename CallArgT::ObjType ObjType;
00236
00237 typedef typename ClassMemFunc<RetT, ObjType>::MemFunc ObjFuncType;
00238
00239 typedef RetT (*FuncFunctionType)(CallArgType);
00240 };
00241
00246 template <class RetT, class CallArgT, class ArgsT>
00247 struct FunctorBuildObjFuncType1
00248 {
00249 typedef typename CallArgT ::ObjType ObjType;
00250 typedef typename ArgsT ::Arg1T ArgType;
00251
00252 typedef ArgsCollector<ArgType> ArgColl;
00253
00254 typedef typename ClassMemFunc1<RetT,
00255 ObjType,
00256 ArgColl>::MemFunc ObjFuncType;
00257 };
00258
00263 template <class RetT, class CallArgT, class ArgsT>
00264 struct FunctorBuildFuncType2
00265 {
00266 typedef typename CallArgT ::ArgType CallArgType;
00267 typedef typename CallArgT ::ObjType ObjType;
00268
00269 typedef typename ArgsT ::Arg1T ArgType;
00270
00271 typedef ArgsCollector<ArgType> ArgColl;
00272
00273 typedef typename ClassMemFunc1<RetT,
00274 ObjType,
00275 ArgColl>::MemFunc ObjFuncType;
00276
00277 typedef RetT (*FuncFunctionType)(CallArgType, ArgType);
00278 };
00279
00284 template <class RetT, class ObjCallArgT, class CallArgT, class ArgsT>
00285 struct FunctorBuildObjFuncType2
00286 {
00287 typedef typename ObjCallArgT::ObjType ObjType;
00288 typedef typename CallArgT ::ArgType Arg1T;
00289 typedef typename ArgsT ::Arg1T Arg2T;
00290
00291 typedef ArgsCollector2<Arg1T, Arg2T> ArgColl;
00292
00293 typedef typename ClassMemFunc2<RetT,
00294 ObjType,
00295 ArgColl>::MemFunc ObjFuncType;
00296 };
00297
00298
00299
00300
00301
00302
00307 template <class SizeTraitsT = DefaultFunctorSizeTraits>
00308 class FunctorBase
00309 {
00310
00311
00312 public:
00313
00314
00318 virtual ~FunctorBase(void);
00319
00321
00322
00323 protected:
00324
00325
00329 static const UInt8 ObjectValid = 0x01;
00330 static const UInt8 FuncPtrValid = 0x02;
00331
00332 static const UInt8 FunctorActive = 0x80;
00333
00335
00339 UInt8 _data1[SizeTraitsT::_uiObjectSize];
00340 UInt8 _data2[SizeTraitsT::_uiFuncPointerSize];
00341 UInt8 _flags;
00342
00344
00348 FunctorBase(void);
00349 FunctorBase(const FunctorBase &source);
00350
00352
00353
00354 private:
00355
00357 void operator =(const FunctorBase &source);
00358 };
00359
00360 OSG_END_NAMESPACE
00361
00362 #include <OSGFunctorBase.inl>
00363
00364 #endif
00365
00366