Logo ROOT  
Reference Guide
TVirtualCollectionProxy.h
Go to the documentation of this file.
1 // @(#)root/cont:$Id$
2 // Author: Philippe Canal 20/08/2003
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2003, Rene Brun, Fons Rademakers and al. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TVirtualCollectionProxy
13 #define ROOT_TVirtualCollectionProxy
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TVirtualCollectionProxy //
18 // //
19 // Virtual interface of a proxy object for a collection class //
20 // In particular this is used to implement splitting, emulation, //
21 // and TTreeFormula access to STL containers. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #include "TClassRef.h"
26 #include "TDataType.h"
27 
28 // Macro indicating the version of the Collection Proxy interface followed
29 // by this ROOT build (See also Reflex/Builder/CollectionProxy.h).
30 
31 #define ROOT_COLLECTIONPROXY_VERSION 3
32 
33 class TClass;
34 namespace TStreamerInfoActions {
35  class TActionSequence;
36 }
37 
39 private:
42 
43 protected:
46  friend class TClass;
47 
48 public:
49  enum EProperty {
50  // No longer used
51  // kIsInitialized = BIT(1),
54  kNeedDelete = BIT(4), // Flag to indicate that this collection that contains directly or indirectly (only via other collection) some pointers that will need explicit deletions.
55  kCustomAlloc = BIT(5) // The collection has a custom allocator.
56  };
57 
58  class TPushPop {
59  // Helper class that insures that push and pop are done when entering
60  // and leaving a C++ context (even in the presence of exceptions)
61  public:
64  void *objectstart) : fProxy(proxy) { fProxy->PushProxy(objectstart); }
65  inline ~TPushPop() { fProxy->PopProxy(); }
66  private:
67  TPushPop(const TPushPop&); // Not implemented
68  TPushPop& operator=(const TPushPop&); // Not implemented
69  };
70 
73 
74  virtual TVirtualCollectionProxy* Generate() const = 0; // Returns an object of the actual CollectionProxy class
76 
77  virtual TClass *GetCollectionClass() const { return fClass; }
78  // Return a pointer to the TClass representing the container
79 
80  virtual Int_t GetCollectionType() const = 0;
81  // Return the type of collection see TClassEdit::ESTLType
82 
83  virtual ULong_t GetIncrement() const = 0;
84  // Return the offset between two consecutive value_types (memory layout).
85 
86  virtual Int_t GetProperties() const { return fProperties; }
87  // Return miscallenous properties of the proxy see TVirtualCollectionProxy::EProperty
88 
89  virtual void *New() const {
90  // Return a new container object
91  return fClass.GetClass()==0 ? 0 : fClass->New();
92  }
93  virtual void *New(void *arena) const {
94  // Execute the container constructor
95  return fClass.GetClass()==0 ? 0 : fClass->New(arena);
96  }
97 
98  virtual void *NewArray(Int_t nElements) const {
99  // Return a new container object
100  return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements);
101  }
102  virtual void *NewArray(Int_t nElements, void *arena) const {
103  // Execute the container constructor
104  return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements, arena);
105  }
106 
107  virtual void Destructor(void *p, Bool_t dtorOnly = kFALSE) const {
108  // Execute the container destructor
109  TClass* cl = fClass.GetClass();
110  if (cl) cl->Destructor(p, dtorOnly);
111  }
112 
113  virtual void DeleteArray(void *p, Bool_t dtorOnly = kFALSE) const {
114  // Execute the container array destructor
115  TClass* cl = fClass.GetClass();
116  if (cl) cl->DeleteArray(p, dtorOnly);
117  }
118 
119  virtual UInt_t Sizeof() const = 0;
120  // Return the sizeof the collection object.
121 
122  virtual void PushProxy(void *objectstart) = 0;
123  // Set the address of the container being proxied and keep track of the previous one.
124 
125  virtual void PopProxy() = 0;
126  // Reset the address of the container being proxied to the previous container
127 
128  virtual Bool_t HasPointers() const = 0;
129  // Return true if the content is of type 'pointer to'
130 
131  virtual TClass *GetValueClass() const = 0;
132  // Return a pointer to the TClass representing the content.
133 
134  virtual EDataType GetType() const = 0;
135  // If the content is a simple numerical value, return its type (see TDataType)
136 
137  virtual void *At(UInt_t idx) = 0;
138  // Return the address of the value at index 'idx'
139 
140  virtual void Clear(const char *opt = "") = 0;
141  // Clear the container
142 
143  virtual UInt_t Size() const = 0;
144  // Return the current size of the container
145 
146  virtual void* Allocate(UInt_t n, Bool_t forceDelete) = 0;
147 
148  virtual void Commit(void*) = 0;
149 
150  virtual void Insert(const void *data, void *container, size_t size) = 0;
151  // Insert data into the container where data is a C-style array of the actual type contained in the collection
152  // of the given size. For associative container (map, etc.), the data type is the pair<key,value>.
153 
154  char *operator[](UInt_t idx) const { return (char*)(const_cast<TVirtualCollectionProxy*>(this))->At(idx); }
155 
156  // MemberWise actions
160 
161  // Set of functions to iterate easily throught the collection
162  static const Int_t fgIteratorArenaSize = 16; // greater than sizeof(void*) + sizeof(UInt_t)
163 
164  typedef void (*CreateIterators_t)(void *collection, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy);
166  // begin_arena and end_arena should contain the location of a memory arena of size fgIteratorSize.
167  // If the collection iterator are of that size or less, the iterators will be constructed in place in those location (new with placement)
168  // Otherwise the iterators will be allocated via a regular new and their address returned by modifying the value of begin_arena and end_arena.
169 
170  typedef void* (*CopyIterator_t)(void *dest, const void *source);
172  // Copy the iterator source, into dest. dest should contain the location of a memory arena of size fgIteratorSize.
173  // If the collection iterator is of that size or less, the iterator will be constructed in place in this location (new with placement)
174  // Otherwise the iterator will be allocated via a regular new.
175  // The actual address of the iterator is returned in both case.
176 
177  typedef void* (*Next_t)(void *iter, const void *end);
178  virtual Next_t GetFunctionNext(Bool_t read = kTRUE) = 0;
179  // iter and end should be pointers to respectively an iterator to be incremented and the result of collection.end()
180  // If the iterator has not reached the end of the collection, 'Next' increment the iterator 'iter' and return 0 if
181  // the iterator reached the end.
182  // If the end was not reached, 'Next' returns the address of the content pointed to by the iterator before the
183  // incrementation ; if the collection contains pointers, 'Next' will return the value of the pointer.
184 
185  typedef void (*DeleteIterator_t)(void *iter);
186  typedef void (*DeleteTwoIterators_t)(void *begin, void *end);
187 
190  // If the size of the iterator is greater than fgIteratorArenaSize, call delete on the addresses,
191  // Otherwise just call the iterator's destructor.
192 
193 };
194 
195 #endif
TVirtualCollectionProxy::GetReadMemberWiseActions
virtual TStreamerInfoActions::TActionSequence * GetReadMemberWiseActions(Int_t version)=0
TVirtualCollectionProxy::GetProperties
virtual Int_t GetProperties() const
Definition: TVirtualCollectionProxy.h:86
n
const Int_t n
Definition: legend1.C:16
TVirtualCollectionProxy::Generate
virtual TVirtualCollectionProxy * Generate() const =0
TVirtualCollectionProxy::GetCollectionClass
virtual TClass * GetCollectionClass() const
Definition: TVirtualCollectionProxy.h:77
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TVirtualCollectionProxy::Clear
virtual void Clear(const char *opt="")=0
TVirtualCollectionProxy::TVirtualCollectionProxy
TVirtualCollectionProxy(TClass *cl)
Definition: TVirtualCollectionProxy.h:72
TVirtualCollectionProxy::PushProxy
virtual void PushProxy(void *objectstart)=0
TVirtualCollectionProxy::NewArray
virtual void * NewArray(Int_t nElements) const
Definition: TVirtualCollectionProxy.h:98
TVirtualCollectionProxy::DeleteArray
virtual void DeleteArray(void *p, Bool_t dtorOnly=kFALSE) const
Definition: TVirtualCollectionProxy.h:113
dest
#define dest(otri, vertexptr)
Definition: triangle.c:1040
TVirtualCollectionProxy::CopyIterator_t
void *(* CopyIterator_t)(void *dest, const void *source)
Definition: TVirtualCollectionProxy.h:170
TVirtualCollectionProxy::kCustomAlloc
@ kCustomAlloc
Definition: TVirtualCollectionProxy.h:55
TVirtualCollectionProxy::TPushPop::fProxy
TVirtualCollectionProxy * fProxy
Definition: TVirtualCollectionProxy.h:62
TVirtualCollectionProxy::kNeedDelete
@ kNeedDelete
Definition: TVirtualCollectionProxy.h:54
TVirtualCollectionProxy::GetFunctionNext
virtual Next_t GetFunctionNext(Bool_t read=kTRUE)=0
TVirtualCollectionProxy::kIsAssociative
@ kIsAssociative
Definition: TVirtualCollectionProxy.h:52
TVirtualCollectionProxy::Destructor
virtual void Destructor(void *p, Bool_t dtorOnly=kFALSE) const
Definition: TVirtualCollectionProxy.h:107
TVirtualCollectionProxy::GetValueClass
virtual TClass * GetValueClass() const =0
TVirtualCollectionProxy::GetConversionReadMemberWiseActions
virtual TStreamerInfoActions::TActionSequence * GetConversionReadMemberWiseActions(TClass *oldClass, Int_t version)=0
TVirtualCollectionProxy::TPushPop::operator=
TPushPop & operator=(const TPushPop &)
TVirtualCollectionProxy::New
virtual void * New() const
Definition: TVirtualCollectionProxy.h:89
TVirtualCollectionProxy::GetFunctionDeleteTwoIterators
virtual DeleteTwoIterators_t GetFunctionDeleteTwoIterators(Bool_t read=kTRUE)=0
TVirtualCollectionProxy::Commit
virtual void Commit(void *)=0
TClassRef::GetClass
TClass * GetClass() const
Definition: TClassRef.h:70
bool
TVirtualCollectionProxy::operator=
TVirtualCollectionProxy & operator=(const TVirtualCollectionProxy &)
TVirtualCollectionProxy::TPushPop::TPushPop
TPushPop(const TPushPop &)
TVirtualCollectionProxy::NewArray
virtual void * NewArray(Int_t nElements, void *arena) const
Definition: TVirtualCollectionProxy.h:102
TVirtualCollectionProxy::TVirtualCollectionProxy
TVirtualCollectionProxy()
Definition: TVirtualCollectionProxy.h:71
TVirtualCollectionProxy::TPushPop::TPushPop
TPushPop(TVirtualCollectionProxy *proxy, void *objectstart)
Definition: TVirtualCollectionProxy.h:63
TVirtualCollectionProxy::GetFunctionDeleteIterator
virtual DeleteIterator_t GetFunctionDeleteIterator(Bool_t read=kTRUE)=0
TVirtualCollectionProxy::GetFunctionCreateIterators
virtual CreateIterators_t GetFunctionCreateIterators(Bool_t read=kTRUE)=0
TVirtualCollectionProxy::GetType
virtual EDataType GetType() const =0
TVirtualCollectionProxy::HasPointers
virtual Bool_t HasPointers() const =0
TClass::DeleteArray
void DeleteArray(void *ary, Bool_t dtorOnly=kFALSE)
Explicitly call operator delete[] for an array.
Definition: TClass.cxx:5409
TDataType.h
TVirtualCollectionProxy::DeleteIterator_t
void(* DeleteIterator_t)(void *iter)
Definition: TVirtualCollectionProxy.h:185
TVirtualCollectionProxy::EProperty
EProperty
Definition: TVirtualCollectionProxy.h:49
TVirtualCollectionProxy::TPushPop::~TPushPop
~TPushPop()
Definition: TVirtualCollectionProxy.h:65
TClass::New
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition: TClass.cxx:4935
TVirtualCollectionProxy::fProperties
UInt_t fProperties
Definition: TVirtualCollectionProxy.h:45
TStreamerInfoActions
Definition: TBuffer.h:39
TVirtualCollectionProxy::GetWriteMemberWiseActions
virtual TStreamerInfoActions::TActionSequence * GetWriteMemberWiseActions()=0
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TVirtualCollectionProxy::Insert
virtual void Insert(const void *data, void *container, size_t size)=0
TVirtualCollectionProxy::TVirtualCollectionProxy
TVirtualCollectionProxy(const TVirtualCollectionProxy &)
TVirtualCollectionProxy::fgIteratorArenaSize
static const Int_t fgIteratorArenaSize
Definition: TVirtualCollectionProxy.h:162
TVirtualCollectionProxy::At
virtual void * At(UInt_t idx)=0
BIT
#define BIT(n)
Definition: Rtypes.h:85
TClass::NewArray
void * NewArray(Long_t nElements, ENewType defConstructor=kClassNew) const
Return a pointer to a newly allocated array of objects of this class.
Definition: TClass.cxx:5117
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TVirtualCollectionProxy::kIsEmulated
@ kIsEmulated
Definition: TVirtualCollectionProxy.h:53
void
typedef void((*Func_t)())
TVirtualCollectionProxy::Sizeof
virtual UInt_t Sizeof() const =0
unsigned int
TVirtualCollectionProxy::CreateIterators_t
void(* CreateIterators_t)(void *collection, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy)
Definition: TVirtualCollectionProxy.h:164
TVirtualCollectionProxy::GetIncrement
virtual ULong_t GetIncrement() const =0
TVirtualCollectionProxy::GetFunctionCopyIterator
virtual CopyIterator_t GetFunctionCopyIterator(Bool_t read=kTRUE)=0
TVirtualCollectionProxy::New
virtual void * New(void *arena) const
Definition: TVirtualCollectionProxy.h:93
TClassRef.h
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
EDataType
EDataType
Definition: TDataType.h:28
TVirtualCollectionProxy::TPushPop
Definition: TVirtualCollectionProxy.h:58
TClass::Destructor
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition: TClass.cxx:5292
TVirtualCollectionProxy::DeleteTwoIterators_t
void(* DeleteTwoIterators_t)(void *begin, void *end)
Definition: TVirtualCollectionProxy.h:186
TVirtualCollectionProxy::fClass
TClassRef fClass
Definition: TVirtualCollectionProxy.h:44
TVirtualCollectionProxy::Next_t
void *(* Next_t)(void *iter, const void *end)
Definition: TVirtualCollectionProxy.h:177
TVirtualCollectionProxy::PopProxy
virtual void PopProxy()=0
TVirtualCollectionProxy::~TVirtualCollectionProxy
virtual ~TVirtualCollectionProxy()
Definition: TVirtualCollectionProxy.h:75
TClassRef
TClassRef is used to implement a permanent reference to a TClass object.
Definition: TClassRef.h:28
TVirtualCollectionProxy::GetCollectionType
virtual Int_t GetCollectionType() const =0
TStreamerInfoActions::TActionSequence
Definition: TStreamerInfoActions.h:172
TVirtualCollectionProxy::Allocate
virtual void * Allocate(UInt_t n, Bool_t forceDelete)=0
TVirtualCollectionProxy
Definition: TVirtualCollectionProxy.h:38
TVirtualCollectionProxy::Size
virtual UInt_t Size() const =0
TVirtualCollectionProxy::operator[]
char * operator[](UInt_t idx) const
Definition: TVirtualCollectionProxy.h:154
int