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  virtual TClass::ObjectPtr NewObject() const {
98  // Return a new container object
99  return fClass.GetClass()==0 ? TClass::ObjectPtr{} : fClass->NewObject();
100  }
101  virtual TClass::ObjectPtr NewObject(void *arena) const {
102  // Execute the container constructor
103  return fClass.GetClass()==0 ? TClass::ObjectPtr{} : fClass->NewObject(arena);
104  }
105 
106  virtual void *NewArray(Int_t nElements) const {
107  // Return a new container object
108  return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements);
109  }
110  virtual void *NewArray(Int_t nElements, void *arena) const {
111  // Execute the container constructor
112  return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements, arena);
113  }
114  virtual TClass::ObjectPtr NewObjectArray(Int_t nElements) const {
115  // Return a new container object
116  return fClass.GetClass()==0 ? TClass::ObjectPtr{} : fClass->NewObjectArray(nElements);
117  }
118  virtual TClass::ObjectPtr NewObjectArray(Int_t nElements, void *arena) const {
119  // Execute the container constructor
120  return fClass.GetClass()==0 ? TClass::ObjectPtr{} : fClass->NewObjectArray(nElements, arena);
121  }
122 
123  virtual void Destructor(void *p, Bool_t dtorOnly = kFALSE) const {
124  // Execute the container destructor
125  TClass* cl = fClass.GetClass();
126  if (cl) cl->Destructor(p, dtorOnly);
127  }
128 
129  virtual void DeleteArray(void *p, Bool_t dtorOnly = kFALSE) const {
130  // Execute the container array destructor
131  TClass* cl = fClass.GetClass();
132  if (cl) cl->DeleteArray(p, dtorOnly);
133  }
134 
135  virtual UInt_t Sizeof() const = 0;
136  // Return the sizeof the collection object.
137 
138  virtual void PushProxy(void *objectstart) = 0;
139  // Set the address of the container being proxied and keep track of the previous one.
140 
141  virtual void PopProxy() = 0;
142  // Reset the address of the container being proxied to the previous container
143 
144  virtual Bool_t HasPointers() const = 0;
145  // Return true if the content is of type 'pointer to'
146 
147  virtual TClass *GetValueClass() const = 0;
148  // Return a pointer to the TClass representing the content.
149 
150  virtual EDataType GetType() const = 0;
151  // If the content is a simple numerical value, return its type (see TDataType)
152 
153  virtual void *At(UInt_t idx) = 0;
154  // Return the address of the value at index 'idx'
155 
156  virtual void Clear(const char *opt = "") = 0;
157  // Clear the container
158 
159  virtual UInt_t Size() const = 0;
160  // Return the current size of the container
161 
162  virtual void* Allocate(UInt_t n, Bool_t forceDelete) = 0;
163 
164  virtual void Commit(void*) = 0;
165 
166  virtual void Insert(const void *data, void *container, size_t size) = 0;
167  // Insert data into the container where data is a C-style array of the actual type contained in the collection
168  // of the given size. For associative container (map, etc.), the data type is the pair<key,value>.
169 
170  char *operator[](UInt_t idx) const { return (char*)(const_cast<TVirtualCollectionProxy*>(this))->At(idx); }
171 
172  // MemberWise actions
176 
177  // Set of functions to iterate easily throught the collection
178  static const Int_t fgIteratorArenaSize = 16; // greater than sizeof(void*) + sizeof(UInt_t)
179 
180  typedef void (*CreateIterators_t)(void *collection, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy);
182  // begin_arena and end_arena should contain the location of a memory arena of size fgIteratorSize.
183  // If the collection iterator are of that size or less, the iterators will be constructed in place in those location (new with placement)
184  // Otherwise the iterators will be allocated via a regular new and their address returned by modifying the value of begin_arena and end_arena.
185 
186  typedef void* (*CopyIterator_t)(void *dest, const void *source);
188  // Copy the iterator source, into dest. dest should contain the location of a memory arena of size fgIteratorSize.
189  // If the collection iterator is of that size or less, the iterator will be constructed in place in this location (new with placement)
190  // Otherwise the iterator will be allocated via a regular new.
191  // The actual address of the iterator is returned in both case.
192 
193  typedef void* (*Next_t)(void *iter, const void *end);
194  virtual Next_t GetFunctionNext(Bool_t read = kTRUE) = 0;
195  // iter and end should be pointers to respectively an iterator to be incremented and the result of collection.end()
196  // If the iterator has not reached the end of the collection, 'Next' increment the iterator 'iter' and return 0 if
197  // the iterator reached the end.
198  // If the end was not reached, 'Next' returns the address of the content pointed to by the iterator before the
199  // incrementation ; if the collection contains pointers, 'Next' will return the value of the pointer.
200 
201  typedef void (*DeleteIterator_t)(void *iter);
202  typedef void (*DeleteTwoIterators_t)(void *begin, void *end);
203 
206  // If the size of the iterator is greater than fgIteratorArenaSize, call delete on the addresses,
207  // Otherwise just call the iterator's destructor.
208 
209 };
210 
211 #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
TClass::NewObjectArray
ObjectPtr NewObjectArray(Long_t nElements, ENewType defConstructor=kClassNew) const
Return a pointer to a newly allocated array of objects of this class.
Definition: TClass.cxx:5193
TVirtualCollectionProxy::NewArray
virtual void * NewArray(Int_t nElements) const
Definition: TVirtualCollectionProxy.h:106
TVirtualCollectionProxy::DeleteArray
virtual void DeleteArray(void *p, Bool_t dtorOnly=kFALSE) const
Definition: TVirtualCollectionProxy.h:129
TVirtualCollectionProxy::NewObjectArray
virtual TClass::ObjectPtr NewObjectArray(Int_t nElements) const
Definition: TVirtualCollectionProxy.h:114
dest
#define dest(otri, vertexptr)
Definition: triangle.c:1040
TClass::ObjectPtr
Definition: TClass.h:140
TVirtualCollectionProxy::CopyIterator_t
void *(* CopyIterator_t)(void *dest, const void *source)
Definition: TVirtualCollectionProxy.h:186
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:123
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:110
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:5513
TDataType.h
TClass::NewObject
ObjectPtr NewObject(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Definition: TClass.cxx:4976
TVirtualCollectionProxy::DeleteIterator_t
void(* DeleteIterator_t)(void *iter)
Definition: TVirtualCollectionProxy.h:201
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:4962
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:178
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:5177
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TVirtualCollectionProxy::kIsEmulated
@ kIsEmulated
Definition: TVirtualCollectionProxy.h:53
TVirtualCollectionProxy::NewObject
virtual TClass::ObjectPtr NewObject() const
Definition: TVirtualCollectionProxy.h:97
void
typedef void((*Func_t)())
TVirtualCollectionProxy::Sizeof
virtual UInt_t Sizeof() const =0
unsigned int
TVirtualCollectionProxy::NewObject
virtual TClass::ObjectPtr NewObject(void *arena) const
Definition: TVirtualCollectionProxy.h:101
TVirtualCollectionProxy::CreateIterators_t
void(* CreateIterators_t)(void *collection, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy)
Definition: TVirtualCollectionProxy.h:180
TVirtualCollectionProxy::NewObjectArray
virtual TClass::ObjectPtr NewObjectArray(Int_t nElements, void *arena) const
Definition: TVirtualCollectionProxy.h:118
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:5384
TVirtualCollectionProxy::DeleteTwoIterators_t
void(* DeleteTwoIterators_t)(void *begin, void *end)
Definition: TVirtualCollectionProxy.h:202
TVirtualCollectionProxy::fClass
TClassRef fClass
Definition: TVirtualCollectionProxy.h:44
TVirtualCollectionProxy::Next_t
void *(* Next_t)(void *iter, const void *end)
Definition: TVirtualCollectionProxy.h:193
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:170
int