TVirtualCollectionProxy.h

Go to the documentation of this file.
00001 // @(#)root/cont:$Id: TVirtualCollectionProxy.h 36061 2010-10-04 16:05:51Z pcanal $
00002 // Author: Philippe Canal 20/08/2003
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2003, Rene Brun, Fons Rademakers and al.           *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TVirtualCollectionProxy
00013 #define ROOT_TVirtualCollectionProxy
00014 
00015 //////////////////////////////////////////////////////////////////////////
00016 //                                                                      //
00017 // TVirtualCollectionProxy                                              //
00018 //                                                                      //
00019 // Virtual interface of a proxy object for a collection class           //
00020 // In particular this is used to implement splitting, emulation,        //
00021 // and TTreeFormula access to STL containers.                           //
00022 //                                                                      //
00023 //////////////////////////////////////////////////////////////////////////
00024 
00025 #ifndef ROOT_TObject
00026 #include "TObject.h"
00027 #endif
00028 #include "TClassRef.h"
00029 #include "TDataType.h"
00030 
00031 // Macro indicating the version of the Collection Proxy interface followed
00032 // by this ROOT build (See also Reflex/Builder/CollectionProxy.h).
00033 
00034 #define ROOT_COLLECTIONPROXY_VERSION 3
00035 
00036 class TClass;
00037 namespace TStreamerInfoActions {
00038    class TActionSequence;
00039 }
00040 
00041 class TVirtualCollectionProxy {
00042 private:
00043    TVirtualCollectionProxy(const TVirtualCollectionProxy&); // Not implemented
00044    TVirtualCollectionProxy& operator=(const TVirtualCollectionProxy&); // Not implemented
00045 
00046 protected:
00047    TClassRef fClass;
00048    UInt_t    fProperties;
00049    virtual void SetValueClass(TClass *newcl) = 0;
00050    friend class TClass;
00051 
00052 public:
00053    enum EProperty {
00054       kIsInitialized = BIT(1),
00055       kIsAssociative = BIT(2),
00056       kIsEmulated    = BIT(3)
00057    };
00058    
00059    class TPushPop {
00060       // Helper class that insures that push and pop are done when entering
00061       // and leaving a C++ context (even in the presence of exceptions)
00062    public:
00063       TVirtualCollectionProxy *fProxy;
00064       inline TPushPop(TVirtualCollectionProxy *proxy, 
00065          void *objectstart) : fProxy(proxy) { fProxy->PushProxy(objectstart); }
00066       inline ~TPushPop() { fProxy->PopProxy(); }
00067    private:
00068       TPushPop(const TPushPop&); // Not implemented
00069       TPushPop& operator=(const TPushPop&); // Not implemented
00070    };
00071 
00072    TVirtualCollectionProxy() : fClass(), fProperties(0) {};
00073    TVirtualCollectionProxy(TClass *cl) : fClass(cl), fProperties(0) {};
00074   
00075    virtual TVirtualCollectionProxy* Generate() const = 0; // Returns an object of the actual CollectionProxy class
00076    virtual ~TVirtualCollectionProxy() {};
00077 
00078    virtual TClass   *GetCollectionClass() { return fClass; } 
00079    // Return a pointer to the TClass representing the container
00080    
00081    virtual Int_t     GetCollectionType() = 0;                
00082    // Return the type of collection see TClassEdit::ESTLType
00083    
00084    virtual ULong_t   GetIncrement() = 0;
00085    // Return the offset between two consecutive value_types (memory layout).
00086 
00087    virtual Int_t     GetProperties() { return fProperties; } 
00088    // Return miscallenous properties of the proxy see TVirtualCollectionProxy::EProperty
00089 
00090    virtual void     *New() const {
00091       // Return a new container object
00092       return fClass.GetClass()==0 ? 0 : fClass->New();
00093    }
00094    virtual void     *New(void *arena) const {
00095       // Execute the container constructor
00096       return fClass.GetClass()==0 ? 0 : fClass->New(arena);
00097    }
00098 
00099    virtual void     *NewArray(Int_t nElements) const {
00100       // Return a new container object
00101       return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements);
00102    }
00103    virtual void     *NewArray(Int_t nElements, void *arena) const {
00104       // Execute the container constructor
00105       return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements, arena);
00106    }
00107 
00108    virtual void      Destructor(void *p, Bool_t dtorOnly = kFALSE) {
00109       // Execute the container destructor
00110       TClass* cl = fClass.GetClass();
00111       if (cl) cl->Destructor(p, dtorOnly);
00112    }
00113 
00114    virtual void      DeleteArray(void *p, Bool_t dtorOnly = kFALSE) { 
00115       // Execute the container array destructor
00116       TClass* cl = fClass.GetClass();
00117       if (cl) cl->DeleteArray(p, dtorOnly);
00118    }
00119 
00120    virtual UInt_t    Sizeof() const = 0;
00121    // Return the sizeof the collection object.
00122    
00123    virtual void      PushProxy(void *objectstart) = 0;
00124    // Set the address of the container being proxied and keep track of the previous one.
00125    
00126    virtual void      PopProxy() = 0;             
00127    // Reset the address of the container being proxied to the previous container
00128 
00129    virtual Bool_t    HasPointers() const = 0;
00130    // Return true if the content is of type 'pointer to'
00131 
00132    virtual TClass   *GetValueClass() = 0;
00133    // Return a pointer to the TClass representing the content.
00134 
00135    virtual EDataType GetType() = 0;
00136    // If the content is a simple numerical value, return its type (see TDataType)
00137 
00138    virtual void     *At(UInt_t idx) = 0;
00139    // Return the address of the value at index 'idx'
00140 
00141    virtual void      Clear(const char *opt = "") = 0;
00142    // Clear the container
00143    
00144    virtual UInt_t    Size() const = 0;
00145    // Return the current size of the container
00146 
00147    virtual void*     Allocate(UInt_t n, Bool_t forceDelete) = 0;
00148    
00149    virtual void      Commit(void*) = 0;
00150 
00151            char     *operator[](UInt_t idx) const { return (char*)(const_cast<TVirtualCollectionProxy*>(this))->At(idx); }
00152    
00153    // MemberWise actions
00154    virtual TStreamerInfoActions::TActionSequence *GetConversionReadMemberWiseActions(TClass *oldClass, Int_t version) = 0;
00155    virtual TStreamerInfoActions::TActionSequence *GetReadMemberWiseActions(Int_t version) = 0;
00156    virtual TStreamerInfoActions::TActionSequence *GetWriteMemberWiseActions() = 0;
00157    
00158    // Set of functions to iterate easily throught the collection
00159    static const Int_t fgIteratorArenaSize = 16; // greater than sizeof(void*) + sizeof(UInt_t)
00160 
00161    typedef void (*CreateIterators_t)(void *collection, void **begin_arena, void **end_arena);
00162    virtual CreateIterators_t GetFunctionCreateIterators(Bool_t read = kTRUE) = 0; 
00163    // begin_arena and end_arena should contain the location of a memory arena of size fgIteratorSize. 
00164    // If the collection iterator are of that size or less, the iterators will be constructed in place in those location (new with placement)
00165    // Otherwise the iterators will be allocated via a regular new and their address returned by modifying the value of begin_arena and end_arena.
00166    
00167    typedef void* (*CopyIterator_t)(void *dest, const void *source);
00168    virtual CopyIterator_t GetFunctionCopyIterator(Bool_t read = kTRUE) = 0;
00169    // Copy the iterator source, into dest.   dest should contain the location of a memory arena of size fgIteratorSize.
00170    // If the collection iterator is of that size or less, the iterator will be constructed in place in this location (new with placement)
00171    // Otherwise the iterator will be allocated via a regular new and its address returned by modifying the value of dest.
00172    
00173    typedef void* (*Next_t)(void *iter, const void *end);
00174    virtual Next_t GetFunctionNext(Bool_t read = kTRUE) = 0;
00175    // iter and end should be pointers to respectively an iterator to be incremented and the result of collection.end()
00176    // If the iterator has not reached the end of the collection, 'Next' increment the iterator 'iter' and return 0 if 
00177    // the iterator reached the end.
00178    // If the end was not reached, 'Next' returns the address of the content pointed to by the iterator before the 
00179    // incrementation ; if the collection contains pointers, 'Next' will return the value of the pointer.
00180    
00181    typedef void (*DeleteIterator_t)(void *iter);
00182    typedef void (*DeleteTwoIterators_t)(void *begin, void *end);
00183 
00184    virtual DeleteIterator_t GetFunctionDeleteIterator(Bool_t read = kTRUE) = 0;
00185    virtual DeleteTwoIterators_t GetFunctionDeleteTwoIterators(Bool_t read = kTRUE) = 0;
00186    // If the size of the iterator is greater than fgIteratorArenaSize, call delete on the addresses,
00187    // Otherwise just call the iterator's destructor.
00188    
00189 };
00190 
00191 #endif

Generated on Tue Jul 5 14:11:28 2011 for ROOT_528-00b_version by  doxygen 1.5.1