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 "TObject.h"
26#include "TClassRef.h"
27#include "TDataType.h"
28
29// Macro indicating the version of the Collection Proxy interface followed
30// by this ROOT build (See also Reflex/Builder/CollectionProxy.h).
31
32#define ROOT_COLLECTIONPROXY_VERSION 3
33
34class TClass;
35namespace TStreamerInfoActions {
36 class TActionSequence;
37}
38
40private:
43
44protected:
47 friend class TClass;
48
49public:
50 enum EProperty {
51 // No longer used
52 // kIsInitialized = BIT(1),
55 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.
56 kCustomAlloc = BIT(5) // The collection has a custom allocator.
57 };
58
59 class TPushPop {
60 // Helper class that insures that push and pop are done when entering
61 // and leaving a C++ context (even in the presence of exceptions)
62 public:
65 void *objectstart) : fProxy(proxy) { fProxy->PushProxy(objectstart); }
66 inline ~TPushPop() { fProxy->PopProxy(); }
67 private:
68 TPushPop(const TPushPop&); // Not implemented
69 TPushPop& operator=(const TPushPop&); // Not implemented
70 };
71
74
75 virtual TVirtualCollectionProxy* Generate() const = 0; // Returns an object of the actual CollectionProxy class
77
78 virtual TClass *GetCollectionClass() const { return fClass; }
79 // Return a pointer to the TClass representing the container
80
81 virtual Int_t GetCollectionType() const = 0;
82 // Return the type of collection see TClassEdit::ESTLType
83
84 virtual ULong_t GetIncrement() const = 0;
85 // Return the offset between two consecutive value_types (memory layout).
86
87 virtual Int_t GetProperties() const { return fProperties; }
88 // Return miscallenous properties of the proxy see TVirtualCollectionProxy::EProperty
89
90 virtual void *New() const {
91 // Return a new container object
92 return fClass.GetClass()==0 ? 0 : fClass->New();
93 }
94 virtual void *New(void *arena) const {
95 // Execute the container constructor
96 return fClass.GetClass()==0 ? 0 : fClass->New(arena);
97 }
98 virtual TClass::ObjectPtr NewObject() const {
99 // Return a new container object
100 return fClass.GetClass()==0 ? TClass::ObjectPtr{} : fClass->NewObject();
101 }
102 virtual TClass::ObjectPtr NewObject(void *arena) const {
103 // Execute the container constructor
104 return fClass.GetClass()==0 ? TClass::ObjectPtr{} : fClass->NewObject(arena);
105 }
106
107 virtual void *NewArray(Int_t nElements) const {
108 // Return a new container object
109 return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements);
110 }
111 virtual void *NewArray(Int_t nElements, void *arena) const {
112 // Execute the container constructor
113 return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements, arena);
114 }
115 virtual TClass::ObjectPtr NewObjectArray(Int_t nElements) const {
116 // Return a new container object
117 return fClass.GetClass()==0 ? TClass::ObjectPtr{} : fClass->NewObjectArray(nElements);
118 }
119 virtual TClass::ObjectPtr NewObjectArray(Int_t nElements, void *arena) const {
120 // Execute the container constructor
121 return fClass.GetClass()==0 ? TClass::ObjectPtr{} : fClass->NewObjectArray(nElements, arena);
122 }
123
124 virtual void Destructor(void *p, Bool_t dtorOnly = kFALSE) const {
125 // Execute the container destructor
126 TClass* cl = fClass.GetClass();
127 if (cl) cl->Destructor(p, dtorOnly);
128 }
129
130 virtual void DeleteArray(void *p, Bool_t dtorOnly = kFALSE) const {
131 // Execute the container array destructor
132 TClass* cl = fClass.GetClass();
133 if (cl) cl->DeleteArray(p, dtorOnly);
134 }
135
136 virtual UInt_t Sizeof() const = 0;
137 // Return the sizeof the collection object.
138
139 virtual void PushProxy(void *objectstart) = 0;
140 // Set the address of the container being proxied and keep track of the previous one.
141
142 virtual void PopProxy() = 0;
143 // Reset the address of the container being proxied to the previous container
144
145 virtual Bool_t HasPointers() const = 0;
146 // Return true if the content is of type 'pointer to'
147
148 virtual TClass *GetValueClass() const = 0;
149 // Return a pointer to the TClass representing the content.
150
151 virtual EDataType GetType() const = 0;
152 // If the content is a simple numerical value, return its type (see TDataType)
153
154 virtual void *At(UInt_t idx) = 0;
155 // Return the address of the value at index 'idx'
156
157 virtual void Clear(const char *opt = "") = 0;
158 // Clear the container
159
160 virtual UInt_t Size() const = 0;
161 // Return the current size of the container
162
163 virtual void* Allocate(UInt_t n, Bool_t forceDelete) = 0;
164
165 virtual void Commit(void*) = 0;
166
167 virtual void Insert(const void *data, void *container, size_t size) = 0;
168 // Insert data into the container where data is a C-style array of the actual type contained in the collection
169 // of the given size. For associative container (map, etc.), the data type is the pair<key,value>.
170
171 char *operator[](UInt_t idx) const { return (char*)(const_cast<TVirtualCollectionProxy*>(this))->At(idx); }
172
173 // MemberWise actions
177
178 // Set of functions to iterate easily throught the collection
179 static const Int_t fgIteratorArenaSize = 16; // greater than sizeof(void*) + sizeof(UInt_t)
180
181 typedef void (*CreateIterators_t)(void *collection, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy);
183 // begin_arena and end_arena should contain the location of a memory arena of size fgIteratorSize.
184 // If the collection iterator are of that size or less, the iterators will be constructed in place in those location (new with placement)
185 // Otherwise the iterators will be allocated via a regular new and their address returned by modifying the value of begin_arena and end_arena.
186
187 typedef void* (*CopyIterator_t)(void *dest, const void *source);
189 // Copy the iterator source, into dest. dest should contain the location of a memory arena of size fgIteratorSize.
190 // If the collection iterator is of that size or less, the iterator will be constructed in place in this location (new with placement)
191 // Otherwise the iterator will be allocated via a regular new.
192 // The actual address of the iterator is returned in both case.
193
194 typedef void* (*Next_t)(void *iter, const void *end);
195 virtual Next_t GetFunctionNext(Bool_t read = kTRUE) = 0;
196 // iter and end should be pointers to respectively an iterator to be incremented and the result of collection.end()
197 // If the iterator has not reached the end of the collection, 'Next' increment the iterator 'iter' and return 0 if
198 // the iterator reached the end.
199 // If the end was not reached, 'Next' returns the address of the content pointed to by the iterator before the
200 // incrementation ; if the collection contains pointers, 'Next' will return the value of the pointer.
201
202 typedef void (*DeleteIterator_t)(void *iter);
203 typedef void (*DeleteTwoIterators_t)(void *begin, void *end);
204
207 // If the size of the iterator is greater than fgIteratorArenaSize, call delete on the addresses,
208 // Otherwise just call the iterator's destructor.
209
210};
211
212#endif
int Int_t
Definition: CPyCppyy.h:43
unsigned int UInt_t
Definition: CPyCppyy.h:44
unsigned long ULong_t
Definition: CPyCppyy.h:51
const Bool_t kFALSE
Definition: RtypesCore.h:90
bool Bool_t
Definition: RtypesCore.h:61
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define BIT(n)
Definition: Rtypes.h:83
EDataType
Definition: TDataType.h:28
typedef void((*Func_t)())
TClassRef is used to implement a permanent reference to a TClass object.
Definition: TClassRef.h:28
TClass * GetClass() const
Definition: TClassRef.h:70
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
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:5163
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition: TClass.cxx:4948
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition: TClass.cxx:5370
void DeleteArray(void *ary, Bool_t dtorOnly=kFALSE)
Explicitly call operator delete[] for an array.
Definition: TClass.cxx:5499
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:5179
ObjectPtr NewObject(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Definition: TClass.cxx:4962
TPushPop(TVirtualCollectionProxy *proxy, void *objectstart)
TPushPop & operator=(const TPushPop &)
virtual Int_t GetProperties() const
virtual void PushProxy(void *objectstart)=0
virtual void * NewArray(Int_t nElements) const
virtual UInt_t Sizeof() const =0
virtual ULong_t GetIncrement() const =0
void(* CreateIterators_t)(void *collection, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy)
virtual TClass::ObjectPtr NewObjectArray(Int_t nElements) const
void *(* Next_t)(void *iter, const void *end)
virtual void Destructor(void *p, Bool_t dtorOnly=kFALSE) const
virtual EDataType GetType() const =0
virtual TStreamerInfoActions::TActionSequence * GetConversionReadMemberWiseActions(TClass *oldClass, Int_t version)=0
TVirtualCollectionProxy(const TVirtualCollectionProxy &)
virtual void Clear(const char *opt="")=0
char * operator[](UInt_t idx) const
virtual TStreamerInfoActions::TActionSequence * GetReadMemberWiseActions(Int_t version)=0
virtual void PopProxy()=0
virtual void * At(UInt_t idx)=0
virtual void DeleteArray(void *p, Bool_t dtorOnly=kFALSE) const
virtual void * NewArray(Int_t nElements, void *arena) const
virtual TClass::ObjectPtr NewObject(void *arena) const
virtual void * Allocate(UInt_t n, Bool_t forceDelete)=0
virtual void Commit(void *)=0
virtual TClass::ObjectPtr NewObject() const
virtual Int_t GetCollectionType() const =0
virtual Next_t GetFunctionNext(Bool_t read=kTRUE)=0
virtual DeleteTwoIterators_t GetFunctionDeleteTwoIterators(Bool_t read=kTRUE)=0
virtual UInt_t Size() const =0
void(* DeleteTwoIterators_t)(void *begin, void *end)
void(* DeleteIterator_t)(void *iter)
virtual void * New(void *arena) const
virtual TClass * GetValueClass() const =0
static const Int_t fgIteratorArenaSize
virtual void * New() const
virtual CreateIterators_t GetFunctionCreateIterators(Bool_t read=kTRUE)=0
TVirtualCollectionProxy & operator=(const TVirtualCollectionProxy &)
virtual TClass * GetCollectionClass() const
virtual TClass::ObjectPtr NewObjectArray(Int_t nElements, void *arena) const
virtual TStreamerInfoActions::TActionSequence * GetWriteMemberWiseActions()=0
virtual DeleteIterator_t GetFunctionDeleteIterator(Bool_t read=kTRUE)=0
virtual TVirtualCollectionProxy * Generate() const =0
virtual CopyIterator_t GetFunctionCopyIterator(Bool_t read=kTRUE)=0
virtual Bool_t HasPointers() const =0
void *(* CopyIterator_t)(void *dest, const void *source)
virtual void Insert(const void *data, void *container, size_t size)=0
const Int_t n
Definition: legend1.C:16
#define dest(otri, vertexptr)
Definition: triangle.c:1040