00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ROOT_TGenCollectionProxy
00012 #define ROOT_TGenCollectionProxy
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ROOT_TVirtualCollectionProxy
00029 #include "TVirtualCollectionProxy.h"
00030 #endif
00031
00032 #ifndef ROOT_TCollectionProxyInfo
00033 #include "TCollectionProxyInfo.h"
00034 #endif
00035
00036 #include <typeinfo>
00037 #include <string>
00038 #include <map>
00039 #ifndef __CINT__
00040 #if defined(__APPLE__)
00041 #include <stdlib.h>
00042 #else
00043 #include <malloc.h>
00044 #endif
00045 #endif
00046 class TObjArray;
00047 class TCollectionProxyFactory;
00048
00049 class TGenCollectionProxy
00050 : public TVirtualCollectionProxy
00051 {
00052
00053
00054 friend class TCollectionProxyFactory;
00055
00056 public:
00057
00058 #ifdef R__HPUX
00059 typedef const type_info& Info_t;
00060 #else
00061 typedef const std::type_info& Info_t;
00062 #endif
00063
00064 enum {
00065
00066
00067 kBIT_ISSTRING = 0x20000000,
00068 kBIT_ISTSTRING = 0x40000000,
00069 kBOOL_t = 21
00070 };
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 struct Value {
00082 ROOT::NewFunc_t fCtor;
00083 ROOT::DesFunc_t fDtor;
00084 ROOT::DelFunc_t fDelete;
00085 unsigned int fCase;
00086 TClassRef fType;
00087 EDataType fKind;
00088 size_t fSize;
00089
00090
00091 Value(const Value& inside);
00092
00093 Value(const std::string& info);
00094
00095 void DeleteItem(void* ptr);
00096
00097 Bool_t IsValid();
00098 };
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 union StreamHelper {
00109 Bool_t boolean;
00110 Char_t s_char;
00111 Short_t s_short;
00112 Int_t s_int;
00113 Long_t s_long;
00114 Long64_t s_longlong;
00115 Float_t flt;
00116 Double_t dbl;
00117 UChar_t u_char;
00118 UShort_t u_short;
00119 UInt_t u_int;
00120 ULong_t u_long;
00121 ULong64_t u_longlong;
00122 void* p_void;
00123 void** pp_void;
00124 char* kchar;
00125 TString* tstr;
00126 void* ptr() {
00127 return *(&this->p_void);
00128 }
00129 std::string* str() {
00130 return (std::string*)this;
00131 }
00132 const char* c_str() {
00133 return ((std::string*)this)->c_str();
00134 }
00135 const char* c_pstr() {
00136 return (*(std::string**)this)->c_str();
00137 }
00138 void set(void* p) {
00139 *(&this->p_void) = p;
00140 }
00141 void read_std_string(TBuffer& b) {
00142 TString s;
00143 s.Streamer(b);
00144 ((std::string*)this)->assign(s.Data());
00145 }
00146 void* read_tstring(TBuffer& b) {
00147 *((TString*)this) = "";
00148 ((TString*)this)->Streamer(b);
00149 return this;
00150 }
00151 void read_std_string_pointer(TBuffer& b) {
00152 TString s;
00153 std::string* str2 = (std::string*)ptr();
00154 if (!str2) str2 = new std::string();
00155 s.Streamer(b);
00156 *str2 = s;
00157 set(str2);
00158 }
00159 void write_std_string_pointer(TBuffer& b) {
00160 const char* c;
00161 if (ptr()) {
00162 std::string* strptr = (*(std::string**)this);
00163 c = (const char*)(strptr->c_str());
00164 } else c = "";
00165 TString(c).Streamer(b);
00166 }
00167 void read_any_object(Value* v, TBuffer& b) {
00168 void* p = ptr();
00169 if ( p ) {
00170 if ( v->fDelete ) {
00171 (*v->fDelete)(p);
00172 }
00173 else if ( v->fType ) {
00174 v->fType->Destructor(p);
00175 }
00176 else if ( v->fDtor ) {
00177 (*v->fDtor)(p);
00178 ::operator delete(p);
00179 }
00180 else {
00181 ::operator delete(p);
00182 }
00183 }
00184 set( b.ReadObjectAny(v->fType) );
00185 }
00186
00187 void read_tstring_pointer(Bool_t vsn3, TBuffer& b) {
00188 TString* s = (TString*)ptr();
00189 if ( vsn3 ) {
00190 if ( !s ) s = new TString();
00191 s->Replace(0, s->Length(), 0, 0);
00192 s->Streamer(b);
00193 set(s);
00194 return;
00195 }
00196 if ( s ) delete s;
00197 set( b.ReadObjectAny(TString::Class()) );
00198 }
00199 void write_tstring_pointer(TBuffer& b) {
00200 b.WriteObjectAny(ptr(), TString::Class());
00201 }
00202 };
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 class Method {
00214 public:
00215 typedef void* (*Call_t)(void*);
00216 Call_t call;
00217 Method() : call(0) { }
00218 Method(Call_t c) : call(c) { }
00219 Method(const Method& m) : call(m.call) { }
00220 void* invoke(void* obj) const { return (*call)(obj); }
00221 };
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 class Method0 {
00233 public:
00234 typedef void* (*Call_t)();
00235 Call_t call;
00236 Method0() : call(0) { }
00237 Method0(Call_t c) : call(c) { }
00238 Method0(const Method0& m) : call(m.call) { }
00239 void* invoke() const { return (*call)(); }
00240 };
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 class TStaging {
00253 void *fTarget;
00254 void *fContent;
00255 size_t fReserved;
00256 size_t fSize;
00257 size_t fSizeOf;
00258 public:
00259 TStaging(size_t size, size_t size_of) : fTarget(0), fContent(0), fReserved(0), fSize(size), fSizeOf(size_of)
00260 {
00261
00262 fReserved = fSize;
00263 fContent = ::malloc(fReserved * fSizeOf);
00264 }
00265
00266 ~TStaging() {
00267
00268 ::free(fContent);
00269 }
00270
00271 void *GetContent() {
00272
00273 return fContent;
00274 }
00275 void *GetEnd() {
00276
00277 return ((char*)fContent) + fSize*fSizeOf;
00278 }
00279 size_t GetSize() {
00280
00281 return fSize;
00282 }
00283 void *GetTarget() {
00284
00285 return fTarget;
00286 }
00287 void Resize(size_t nelement) {
00288 if (fReserved < nelement) {
00289 fReserved = nelement;
00290 fContent = ::realloc(fContent,fReserved * fSizeOf);
00291 }
00292 fSize = nelement;
00293 }
00294 void SetTarget(void *target) {
00295
00296 fTarget = target;
00297 }
00298 };
00299
00300 protected:
00301 typedef ROOT::TCollectionProxyInfo::Environ<char[64]> Env_t;
00302 typedef ROOT::TCollectionProxyInfo::EnvironBase EnvironBase_t;
00303 typedef std::vector<TStaging*> Staged_t;
00304 typedef std::vector<EnvironBase_t*> Proxies_t;
00305 mutable TObjArray *fReadMemberWise;
00306 mutable std::map<std::string, TObjArray*> *fConversionReadMemberWise;
00307 typedef void (*Sizing_t)(void *obj, size_t size);
00308 typedef void* (*Feedfunc_t)(void *from, void *to, size_t size);
00309 typedef void* (*ArrIterfunc_t)(void *from, size_t size);
00310
00311 std::string fName;
00312 Bool_t fPointers;
00313 Method fClear;
00314 Method fSize;
00315 Sizing_t fResize;
00316 Method fFirst;
00317 Method fNext;
00318 ArrIterfunc_t fConstruct;
00319 Sizing_t fDestruct;
00320 Feedfunc_t fFeed;
00321 Method fCollect;
00322 Method0 fCreateEnv;
00323 Value* fValue;
00324 Value* fVal;
00325 Value* fKey;
00326 EnvironBase_t*fEnv;
00327 int fValOffset;
00328 int fValDiff;
00329 Proxies_t fProxyList;
00330 Proxies_t fProxyKept;
00331 Staged_t fStaged;
00332 int fSTL_type;
00333 Info_t fTypeinfo;
00334 TClass* fOnFileClass;
00335
00336 CreateIterators_t fFunctionCreateIterators;
00337 DeleteTwoIterators_t fFunctionDeleteTwoIterators;
00338
00339
00340 TGenCollectionProxy* Initialize() const;
00341
00342 virtual TGenCollectionProxy* InitializeEx();
00343
00344 virtual void DeleteItem(Bool_t force, void* ptr) const;
00345
00346 void CheckFunctions() const;
00347 private:
00348 TGenCollectionProxy();
00349
00350 public:
00351
00352
00353 virtual TVirtualCollectionProxy* Generate() const;
00354
00355
00356 TGenCollectionProxy(const TGenCollectionProxy& copy);
00357
00358
00359 TGenCollectionProxy(Info_t typ, size_t iter_size);
00360 TGenCollectionProxy(const ROOT::TCollectionProxyInfo &info, TClass *cl);
00361
00362
00363 virtual ~TGenCollectionProxy();
00364
00365
00366 virtual TClass *GetCollectionClass();
00367
00368
00369 virtual Int_t GetCollectionType();
00370
00371
00372 virtual ULong_t GetIncrement();
00373
00374
00375 virtual UInt_t Sizeof() const;
00376
00377
00378 virtual void PushProxy(void *objstart);
00379
00380
00381 virtual void PopProxy();
00382
00383
00384 virtual Bool_t HasPointers() const;
00385
00386
00387 virtual TClass *GetValueClass();
00388
00389
00390 virtual void SetValueClass(TClass *newcl);
00391
00392
00393 virtual EDataType GetType();
00394
00395
00396 virtual void *At(UInt_t idx);
00397
00398
00399 virtual void Clear(const char *opt = "");
00400
00401
00402 virtual void Resize(UInt_t n, Bool_t force_delete);
00403
00404
00405 virtual UInt_t Size() const;
00406
00407
00408 virtual void* Allocate(UInt_t n, Bool_t forceDelete);
00409
00410
00411 virtual void Commit(void* env);
00412
00413
00414 virtual void Streamer(TBuffer &refBuffer);
00415
00416
00417 virtual void Streamer(TBuffer &refBuffer, void *pObject, int siz);
00418
00419
00420 virtual void operator()(TBuffer &refBuffer, void *pObject);
00421
00422
00423 virtual void ReadBuffer(TBuffer &b, void *obj);
00424 virtual void ReadBuffer(TBuffer &b, void *obj, const TClass *onfileClass);
00425
00426 virtual void SetOnFileClass( TClass* cl ) { fOnFileClass = cl; }
00427 virtual TClass* GetOnFileClass() const { return fOnFileClass; }
00428
00429
00430 virtual TStreamerInfoActions::TActionSequence *GetConversionReadMemberWiseActions(TClass *oldClass, Int_t version);
00431 virtual TStreamerInfoActions::TActionSequence *GetReadMemberWiseActions(Int_t version);
00432 virtual TStreamerInfoActions::TActionSequence *GetWriteMemberWiseActions();
00433
00434
00435
00436 virtual CreateIterators_t GetFunctionCreateIterators(Bool_t read = kTRUE);
00437
00438
00439
00440
00441
00442 virtual CopyIterator_t GetFunctionCopyIterator(Bool_t read = kTRUE);
00443
00444
00445
00446
00447
00448 virtual Next_t GetFunctionNext(Bool_t read = kTRUE);
00449
00450
00451
00452
00453
00454
00455
00456 virtual DeleteIterator_t GetFunctionDeleteIterator(Bool_t read = kTRUE);
00457 virtual DeleteTwoIterators_t GetFunctionDeleteTwoIterators(Bool_t read = kTRUE);
00458
00459
00460
00461
00462
00463 };
00464
00465 template <typename T>
00466 struct AnyCollectionProxy : public TGenCollectionProxy {
00467 AnyCollectionProxy()
00468 : TGenCollectionProxy(typeid(T::Cont_t),sizeof(T::Iter_t))
00469 {
00470
00471 fValDiff = sizeof(T::Value_t);
00472 fValOffset = T::value_offset();
00473 fSize.call = T::size;
00474 fResize = T::resize;
00475 fNext.call = T::next;
00476 fFirst.call = T::first;
00477 fClear.call = T::clear;
00478 fConstruct = T::construct;
00479 fDestruct = T::destruct;
00480 fFeed = T::feed;
00481 CheckFunctions();
00482 }
00483 virtual ~AnyCollectionProxy() { }
00484 };
00485
00486 #endif
00487