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
00048 #ifndef __bbtkAtomicBlackBoxGetSetFunctor_h__
00049 #define __bbtkAtomicBlackBoxGetSetFunctor_h__
00050
00051 #include "bbtkData.h"
00052 #include "bbtkMessageManager.h"
00053
00054 namespace bbtk
00055 {
00056
00057
00058 class AtomicBlackBox;
00059
00060
00061
00062 class BBTK_EXPORT AtomicBlackBoxGetFunctor
00063 {
00064 public:
00066 AtomicBlackBoxGetFunctor() {}
00068 virtual ~AtomicBlackBoxGetFunctor() {}
00070 virtual Data Get(AtomicBlackBox* o) = 0;
00072 virtual TypeInfo GetTypeInfo() const = 0;
00074 virtual std::string GetTypeName() const = 0;
00076 virtual std::string GetHumanTypeName() const = 0;
00078 virtual bool IsPointerType() const = 0;
00079
00080 };
00081
00082
00083
00084
00085 class AtomicBlackBoxSetFunctor
00086 {
00087 public:
00089 AtomicBlackBoxSetFunctor() {}
00091 virtual ~AtomicBlackBoxSetFunctor() {}
00093 virtual void Set(AtomicBlackBox* o, const Data&) = 0;
00095 virtual TypeInfo GetTypeInfo() const = 0;
00097 virtual std::string GetTypeName() const = 0;
00099 virtual std::string GetHumanTypeName() const = 0;
00101 virtual bool IsPointerType() const = 0;
00107 virtual void BruteForceSetPointer(AtomicBlackBox* o, void* p) = 0;
00108
00109 };
00110
00111
00112
00113
00114
00115 template <class UBB, class T, class TRETURN>
00116 class AtomicBlackBoxTGetFunctor : public bbtk::AtomicBlackBoxGetFunctor
00117 {
00118 public:
00120 typedef TRETURN (UBB::*GetMethodPointerType)(void);
00121
00123 AtomicBlackBoxTGetFunctor(GetMethodPointerType g) :
00124 mGetMethodPointer(g)
00125 {
00126 bbtkDebugMessage("data",9,"AtomicBlackBoxTGetFunctor<"<<
00127 TypeName<UBB>()<<","<<
00128 TypeName<T>()<<","<<
00129 TypeName<TRETURN>()<<
00130 ">::AtomicBlackBoxTGetFunctor()"<<std::endl);
00131 }
00132
00134 Data Get(AtomicBlackBox* o)
00135 {
00136 bbtkDebugMessage("data",9,"AtomicBlackBoxTGetFunctor<"<<
00137 TypeName<UBB>()<<","<<
00138 TypeName<T>()<<","<<
00139 TypeName<TRETURN>()<<
00140 ">::Get()"<<std::endl);
00141 return (((UBB*)o)->*mGetMethodPointer)();
00142 }
00144 TypeInfo GetTypeInfo() const { return typeid(T); }
00145 std::string GetTypeName() const { return TypeName<T>(); }
00146 std::string GetHumanTypeName() const { return HumanTypeName<T>(); }
00148 virtual bool IsPointerType() const
00149 {
00150 return boost::is_pointer<T>::value;
00151 }
00152
00153 private:
00155 GetMethodPointerType mGetMethodPointer;
00156 };
00157
00158
00159
00160
00161
00162 template <class UBB, class T, class TACCESS>
00163 class AtomicBlackBoxTSetFunctor : public AtomicBlackBoxSetFunctor
00164 {
00165 public:
00167 typedef void (UBB::*SetMethodPointerType)(TACCESS);
00168
00170 AtomicBlackBoxTSetFunctor(SetMethodPointerType s) :
00171 mSetMethodPointer(s)
00172 {
00173 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetFunctor<"<<
00174 TypeName<UBB>()<<","<<
00175 TypeName<T>()<<","<<
00176 TypeName<TACCESS>()<<
00177 ">::AtomicBlackBoxTSetFunctor()"<<std::endl);
00178 }
00179
00181 void Set(AtomicBlackBox* o, const Data& d)
00182 {
00183 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetfunctor<"<<
00184 TypeName<UBB>()<<","<<
00185 TypeName<T>()<<","<<
00186 TypeName<TACCESS>()<<
00187 ">::Set()"<<std::endl);
00188
00189
00190 T t = d.unsafe_get<T>();
00191 (((UBB*)o)->*mSetMethodPointer)(t);
00192
00193 }
00194
00196 TypeInfo GetTypeInfo() const { return typeid(T); }
00197 std::string GetTypeName() const { return TypeName<T>(); }
00198 std::string GetHumanTypeName() const { return HumanTypeName<T>(); }
00199 virtual bool IsPointerType() const { return false; }
00200 virtual void BruteForceSetPointer(AtomicBlackBox* b, void* p)
00201 {
00202 bbtkInternalError("AtomicBlackBoxTSetFunctor<"
00203 <<TypeName<UBB>()<<","
00204 <<TypeName<T>()<<","
00205 <<TypeName<TACCESS>()
00206 <<">::BruteForceSetPointer("
00207 <<b<<","<<p<<")"
00208 <<" called whereas type '"
00209 <<TypeName<T>()
00210 <<"' is not a pointer type");
00211 }
00212 private:
00214 SetMethodPointerType mSetMethodPointer;
00215 };
00216
00217
00218
00219
00220
00222 template <class UBB, class T, class TACCESS>
00223 class AtomicBlackBoxTSetFunctor<UBB,T*,TACCESS*>
00224 : public AtomicBlackBoxSetFunctor
00225 {
00226 public:
00228 typedef void (UBB::*SetMethodPointerType)(TACCESS*);
00229
00231 AtomicBlackBoxTSetFunctor(SetMethodPointerType s) :
00232 mSetMethodPointer(s)
00233 {
00234 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetFunctor<"<<
00235 TypeName<UBB>()<<","<<
00236 TypeName<T*>()<<","<<
00237 TypeName<TACCESS*>()<<
00238 ">::AtomicBlackBoxTSetFunctor()"<<std::endl);
00239 }
00240
00242 void Set(AtomicBlackBox* o, const Data& d)
00243 {
00244 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetfunctor<"<<
00245 TypeName<UBB>()<<","<<
00246 TypeName<T*>()<<","<<
00247 TypeName<TACCESS*>()<<
00248 ">::Set()"<<std::endl);
00249
00250 (((UBB*)o)->*mSetMethodPointer)(d.unsafe_get<T*>());
00251
00252 }
00253
00255 TypeInfo GetTypeInfo() const { return typeid(T*); }
00256 std::string GetTypeName() const { return TypeName<T*>(); }
00257 std::string GetHumanTypeName() const { return HumanTypeName<T*>(); }
00258 virtual bool IsPointerType() const { return true; }
00259
00260
00261 virtual void BruteForceSetPointer(AtomicBlackBox* o, void* p)
00262 {
00263 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetFunctor<"
00264 <<TypeName<UBB>()<<","
00265 <<TypeName<T*>()<<","
00266 <<TypeName<TACCESS*>()
00267 <<">::BruteForceSetPointer() (pointer specialization)");
00268
00269 (((UBB*)o)->*mSetMethodPointer)((T*)p);
00270
00271 }
00272 private:
00274 SetMethodPointerType mSetMethodPointer;
00275 };
00276
00277
00278 }
00279
00280 #endif