Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#define ROOT_COLLECTIONPROXY_VERSION 3
31
32class TClass;
33namespace TStreamerInfoActions {
34 class TActionSequence;
35}
36
37// clang-format off
38/**
39\class TVirtualCollectionProxy
40\brief Defines a common interface to inspect/change the contents of an object that represents a collection
41
42Specifically, an object of a class that derives from TVirtualCollectionProxy relays accesses to any object that
43matches the proxied collection type.
44The interface provides two families of functions: (i) for direct manipulation, e.g. `Insert()` or `At()`; and
45(ii) iterator-based, e.g. `GetFunctionCreateIterators()` or `GetFunctionNext()`.
46TVirtualCollectionProxy objects are stateful; in particular, many functions require to set the object to operate
47on via `PushProxy()` / `PopProxy()`. The `TPushPop` RAII class is provided for convenience.
48A collection proxy for a given class can be permanently set using `TClass::CopyCollectionProxy()`.
49The `Generate()` function should be overridden in derived classes to return a clean object of the most-derived class.
50*/
51// clang-format on
53private:
56
57protected:
60 friend class TClass;
61
62public:
63 enum EProperty {
64 // No longer used
65 // kIsInitialized = BIT(1),
68 /// The collection contains directly or indirectly (via other collection) some pointers that need explicit
69 /// deletion
71 kCustomAlloc = BIT(5) ///< The collection has a custom allocator.
72 };
73
74 /// RAII helper class that ensures that `PushProxy()` / `PopProxy()` are called when entering / leaving a C++ context
75 class TPushPop {
76 public:
79 void *objectstart) : fProxy(proxy) { fProxy->PushProxy(objectstart); }
80 inline ~TPushPop() { fProxy->PopProxy(); }
81 private:
82 TPushPop(const TPushPop&) = delete;
83 TPushPop& operator=(const TPushPop&) = delete;
84 };
85
89
90 /// Returns a clean object of the actual class that derives from TVirtualCollectionProxy. The caller is responsible
91 /// for deleting the returned object.
92 virtual TVirtualCollectionProxy *Generate() const = 0;
93
94 /// Reset the information gathered from StreamerInfos and value's TClass.
95 virtual Bool_t Reset() { return kTRUE; }
96
97 /// Return a pointer to the `TClass` representing the proxied _container_ class
98 virtual TClass *GetCollectionClass() const { return fClass; }
99
100 /// Return the type of the proxied collection (see enumeration TClassEdit::ESTLType)
101 virtual Int_t GetCollectionType() const = 0;
102
103 /// Return the offset between two consecutive in-memory values (which depends on the `sizeof()` and alignment of the
104 /// value type).
105 virtual ULong_t GetIncrement() const = 0;
106
107 /// Return miscallenous properties of the proxy (see TVirtualCollectionProxy::EProperty)
108 virtual Int_t GetProperties() const { return fProperties; }
109
110 /// Construct a new container object and return its address
111 virtual void *New() const { return !fClass.GetClass() ? nullptr : fClass->New(); }
112 /// Construct a new container object at the address given by `arena`
113 virtual void *New(void *arena) const { return !fClass.GetClass() ? nullptr : fClass->New(arena); }
114 /// Construct a new container object and return its address
116 {
118 }
119 /// Construct a new container object at the address given by `arena`
120 virtual TClass::ObjectPtr NewObject(void *arena) const
121 {
122 return !fClass.GetClass() ? TClass::ObjectPtr{} : fClass->NewObject(arena);
123 }
124
125 /// Construct an array of `nElements` container objects and return the base address of the array
126 virtual void *NewArray(Int_t nElements) const { return !fClass.GetClass() ? nullptr : fClass->NewArray(nElements); }
127 /// Construct an array of `nElements` container objects at the address given by `arena`
128 virtual void *NewArray(Int_t nElements, void *arena) const
129 {
130 return !fClass.GetClass() ? nullptr : fClass->NewArray(nElements, arena);
131 }
132 /// Construct an array of `nElements` container objects and return the base address of the array
133 virtual TClass::ObjectPtr NewObjectArray(Int_t nElements) const
134 {
135 return !fClass.GetClass() ? TClass::ObjectPtr{} : fClass->NewObjectArray(nElements);
136 }
137 /// Construct an array of `nElements` container objects at the address given by `arena`
138 virtual TClass::ObjectPtr NewObjectArray(Int_t nElements, void *arena) const
139 {
140 return !fClass.GetClass() ? TClass::ObjectPtr{} : fClass->NewObjectArray(nElements, arena);
141 }
142
143 /// Execute the container destructor
144 virtual void Destructor(void *p, Bool_t dtorOnly = kFALSE) const
145 {
146 TClass* cl = fClass.GetClass();
147 if (cl) cl->Destructor(p, dtorOnly);
148 }
149
150 /// Execute the container array destructor
151 virtual void DeleteArray(void *p, Bool_t dtorOnly = kFALSE) const
152 {
153 TClass* cl = fClass.GetClass();
154 if (cl) cl->DeleteArray(p, dtorOnly);
155 }
156
157 /// Return the `sizeof()` of the collection object
158 virtual UInt_t Sizeof() const = 0;
159
160 /// Set the address of the container being proxied and keep track of the previous one
161 virtual void PushProxy(void *objectstart) = 0;
162
163 /// Reset the address of the container being proxied to the previous container
164 virtual void PopProxy() = 0;
165
166 /// Return `true` if the content is of type 'pointer to'
167 virtual Bool_t HasPointers() const = 0;
168
169 /// If the value type is a user-defined class, return a pointer to the `TClass` representing the
170 /// value type of the container.
171 virtual TClass *GetValueClass() const = 0;
172
173 /// If the value type is a fundamental data type, return its type (see enumeration EDataType).
174 virtual EDataType GetType() const = 0;
175
176 /// Return the address of the value at index `idx`
177 virtual void *At(UInt_t idx) = 0;
178
179 /// Clear the container
180 virtual void Clear(const char *opt = "") = 0;
181
182 /// Return the current number of elements in the container
183 virtual UInt_t Size() const = 0;
184
185 /// Allocates space for storing at least `n` elements. This function returns a pointer to the actual object on
186 /// which insertions should take place. For associative collections, this function returns a pointer to a temporary
187 /// buffer known as the staging area. If the insertion happened in a staging area (i.e. the returned pointer !=
188 /// proxied object), `Commit()` should be called on the value returned by this function.
189 virtual void* Allocate(UInt_t n, Bool_t forceDelete) = 0;
190
191 /// Commits pending elements in a staging area (see Allocate() for more information).
192 virtual void Commit(void*) = 0;
193
194 /// Insert elements into the proxied container. `data` is a C-style array of the value type of the given `size`.
195 /// For associative containers, e.g. `std::map`, the data type should be `std::pair<Key_t, Value_t>`.
196 virtual void Insert(const void *data, void *container, size_t size) = 0;
197
198 /// Return the address of the value at index `idx`
199 char *operator[](UInt_t idx) const { return (char *)(const_cast<TVirtualCollectionProxy *>(this))->At(idx); }
200
201 // Functions related to member-wise actions
205
206 /// The size of a small buffer that can be allocated on the stack to store iterator-specific information
207 static const Int_t fgIteratorArenaSize = 16; // greater than sizeof(void*) + sizeof(UInt_t)
208
209 /// `*begin_arena` and `*end_arena` should contain the location of a memory arena of size `fgIteratorArenaSize`.
210 /// If iterator-specific information is of that size or less, the iterators will be constructed in place in the given
211 /// locations. Otherwise, iterators will be allocated via `new` and their address returned by modifying the value
212 /// of `*begin_arena` and `*end_arena`.
213 /// As a special case, given that iterators for array-backed containers are just pointers, the required information
214 /// will be directly stored in `*(begin|end)_arena`.
215 typedef void (*CreateIterators_t)(void *collection, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy);
216
217 /// Return a pointer to a function that can create an iterator pair, where each iterator points to the begin and end
218 /// of the collection, respectively (see CreateIterators_t). If `read == kTRUE`, data is to be read from disk, i.e.
219 /// written to the in-memory collection.
221
222 /// Copy the iterator `source` into `dest`. `dest` should contain the location of a memory arena of size
223 /// `fgIteratorArenaSize`.
224 /// If iterator-specific information is of that size or less, the iterators will be constructed in place in the given
225 /// locations. Otherwise, iterators will be allocated via `new` and their address returned by modifying the value
226 /// of `*begin_arena` and `*end_arena`. The actual address of the iterator is returned in any case.
227 typedef void* (*CopyIterator_t)(void *dest, const void *source);
228
229 /// Return a pointer to a function that can copy an iterator (see CopyIterator_t). If `read == kTRUE`, data is to be
230 /// read from disk, i.e. written to the in-memory collection.
232
233 /// `iter` and `end` should be pointers to an iterator to be incremented and an iterator that points to the end of
234 /// the collection, respectively. If `iter` has not reached the end of the collection, this function increments the
235 /// iterator and returns a pointer to the element before the increment. Otherwise, `nullptr` is returned.
236 typedef void* (*Next_t)(void *iter, const void *end);
237
238 /// Return a pointer to a function that can advance an iterator (see Next_t). If `read == kTRUE`, data is to be
239 /// read from disk, i.e. written to the in-memory collection.
240 virtual Next_t GetFunctionNext(Bool_t read = kTRUE) = 0;
241
242 /// If the size of the iterator is greater than `fgIteratorArenaSize`, call delete on the addresses; otherwise, just
243 /// call the iterator's destructor.
244 typedef void (*DeleteIterator_t)(void *iter);
245 typedef void (*DeleteTwoIterators_t)(void *begin, void *end);
246
247 /// Return a pointer to a function that can delete an iterator (pair) (see DeleteIterator_t). If `read == kTRUE`,
248 /// data is to be read from disk, i.e. written to the in-memory collection.
251};
252
253#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned long ULong_t
Definition RtypesCore.h:55
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define BIT(n)
Definition Rtypes.h:85
EDataType
Definition TDataType.h:28
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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:81
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:5193
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:4978
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition TClass.cxx:5400
void DeleteArray(void *ary, Bool_t dtorOnly=kFALSE)
Explicitly call operator delete[] for an array.
Definition TClass.cxx:5529
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:5209
ObjectPtr NewObject(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Definition TClass.cxx:4992
RAII helper class that ensures that PushProxy() / PopProxy() are called when entering / leaving a C++...
TPushPop & operator=(const TPushPop &)=delete
TPushPop(const TPushPop &)=delete
TPushPop(TVirtualCollectionProxy *proxy, void *objectstart)
Defines a common interface to inspect/change the contents of an object that represents a collection.
virtual Int_t GetProperties() const
Return miscallenous properties of the proxy (see TVirtualCollectionProxy::EProperty)
virtual void PushProxy(void *objectstart)=0
Set the address of the container being proxied and keep track of the previous one.
virtual UInt_t Sizeof() const =0
Return the sizeof() of the collection object.
virtual ULong_t GetIncrement() const =0
Return the offset between two consecutive in-memory values (which depends on the sizeof() and alignme...
virtual TStreamerInfoActions::TActionSequence * GetReadMemberWiseActions(Int_t version)=0
void(* CreateIterators_t)(void *collection, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy)
*begin_arena and *end_arena should contain the location of a memory arena of size fgIteratorArenaSize...
virtual TClass::ObjectPtr NewObjectArray(Int_t nElements) const
Construct an array of nElements container objects and return the base address of the array.
virtual void Destructor(void *p, Bool_t dtorOnly=kFALSE) const
Execute the container destructor.
virtual EDataType GetType() const =0
If the value type is a fundamental data type, return its type (see enumeration EDataType).
@ kCustomAlloc
The collection has a custom allocator.
@ kNeedDelete
The collection contains directly or indirectly (via other collection) some pointers that need explici...
void *(* CopyIterator_t)(void *dest, const void *source)
Copy the iterator source into dest.
char * operator[](UInt_t idx) const
Return the address of the value at index idx
virtual void * NewArray(Int_t nElements, void *arena) const
Construct an array of nElements container objects at the address given by arena
virtual void Clear(const char *opt="")=0
Clear the container.
virtual TStreamerInfoActions::TActionSequence * GetWriteMemberWiseActions()=0
virtual void * New() const
Construct a new container object and return its address.
void *(* Next_t)(void *iter, const void *end)
iter and end should be pointers to an iterator to be incremented and an iterator that points to the e...
virtual void PopProxy()=0
Reset the address of the container being proxied to the previous container.
virtual void DeleteArray(void *p, Bool_t dtorOnly=kFALSE) const
Execute the container array destructor.
virtual TClass * GetValueClass() const =0
If the value type is a user-defined class, return a pointer to the TClass representing the value type...
virtual TClass::ObjectPtr NewObject(void *arena) const
Construct a new container object at the address given by arena
virtual void Commit(void *)=0
Commits pending elements in a staging area (see Allocate() for more information).
virtual TClass::ObjectPtr NewObject() const
Construct a new container object and return its address.
virtual void * At(UInt_t idx)=0
Return the address of the value at index idx
virtual Int_t GetCollectionType() const =0
Return the type of the proxied collection (see enumeration TClassEdit::ESTLType)
virtual Next_t GetFunctionNext(Bool_t read=kTRUE)=0
Return a pointer to a function that can advance an iterator (see Next_t).
virtual DeleteTwoIterators_t GetFunctionDeleteTwoIterators(Bool_t read=kTRUE)=0
virtual UInt_t Size() const =0
Return the current number of elements in the container.
virtual void * NewArray(Int_t nElements) const
Construct an array of nElements container objects and return the base address of the array.
void(* DeleteTwoIterators_t)(void *begin, void *end)
void(* DeleteIterator_t)(void *iter)
If the size of the iterator is greater than fgIteratorArenaSize, call delete on the addresses; otherw...
virtual void * New(void *arena) const
Construct a new container object at the address given by arena
static const Int_t fgIteratorArenaSize
The size of a small buffer that can be allocated on the stack to store iterator-specific information.
virtual TVirtualCollectionProxy * Generate() const =0
Returns a clean object of the actual class that derives from TVirtualCollectionProxy.
virtual Bool_t Reset()
Reset the information gathered from StreamerInfos and value's TClass.
virtual CreateIterators_t GetFunctionCreateIterators(Bool_t read=kTRUE)=0
Return a pointer to a function that can create an iterator pair, where each iterator points to the be...
virtual TClass::ObjectPtr NewObjectArray(Int_t nElements, void *arena) const
Construct an array of nElements container objects at the address given by arena
virtual void * Allocate(UInt_t n, Bool_t forceDelete)=0
Allocates space for storing at least n elements.
virtual TStreamerInfoActions::TActionSequence * GetConversionReadMemberWiseActions(TClass *oldClass, Int_t version)=0
TVirtualCollectionProxy & operator=(const TVirtualCollectionProxy &)=delete
virtual DeleteIterator_t GetFunctionDeleteIterator(Bool_t read=kTRUE)=0
Return a pointer to a function that can delete an iterator (pair) (see DeleteIterator_t).
TVirtualCollectionProxy(const TVirtualCollectionProxy &)=delete
virtual CopyIterator_t GetFunctionCopyIterator(Bool_t read=kTRUE)=0
Return a pointer to a function that can copy an iterator (see CopyIterator_t).
virtual Bool_t HasPointers() const =0
Return true if the content is of type 'pointer to'.
virtual TClass * GetCollectionClass() const
Return a pointer to the TClass representing the proxied container class.
virtual void Insert(const void *data, void *container, size_t size)=0
Insert elements into the proxied container.
const Int_t n
Definition legend1.C:16
#define dest(otri, vertexptr)
Definition triangle.c:1041