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
33class TClass;
34namespace TStreamerInfoActions {
35 class TActionSequence;
36}
37
39private:
42
43protected:
46 friend class TClass;
47
48public:
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&) = delete;
68 TPushPop& operator=(const TPushPop&) = delete;
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
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
int Int_t
Definition: CPyCppyy.h:43
unsigned int UInt_t
Definition: CPyCppyy.h:44
unsigned long ULong_t
Definition: CPyCppyy.h:51
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define BIT(n)
Definition: Rtypes.h:85
EDataType
Definition: TDataType.h:28
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:5186
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition: TClass.cxx:4971
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition: TClass.cxx:5393
void DeleteArray(void *ary, Bool_t dtorOnly=kFALSE)
Explicitly call operator delete[] for an array.
Definition: TClass.cxx:5522
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:5202
ObjectPtr NewObject(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Definition: TClass.cxx:4985
TPushPop & operator=(const TPushPop &)=delete
TPushPop(const TPushPop &)=delete
TPushPop(TVirtualCollectionProxy *proxy, void *objectstart)
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
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
TVirtualCollectionProxy & operator=(const TVirtualCollectionProxy &)=delete
virtual void * New() const
virtual CreateIterators_t GetFunctionCreateIterators(Bool_t read=kTRUE)=0
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
TVirtualCollectionProxy(const TVirtualCollectionProxy &)=delete
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:1041