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
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 // Reset the info gathered from StreamerInfos and value's TClass.
78 virtual Bool_t Reset() { return kTRUE; }
79
80 virtual TClass *GetCollectionClass() const { return fClass; }
81 // Return a pointer to the TClass representing the container
82
83 virtual Int_t GetCollectionType() const = 0;
84 // Return the type of collection see TClassEdit::ESTLType
85
86 virtual ULong_t GetIncrement() const = 0;
87 // Return the offset between two consecutive value_types (memory layout).
88
89 virtual Int_t GetProperties() const { return fProperties; }
90 // Return miscallenous properties of the proxy see TVirtualCollectionProxy::EProperty
91
92 virtual void *New() const {
93 // Return a new container object
94 return fClass.GetClass()==0 ? 0 : fClass->New();
95 }
96 virtual void *New(void *arena) const {
97 // Execute the container constructor
98 return fClass.GetClass()==0 ? 0 : fClass->New(arena);
99 }
100 virtual TClass::ObjectPtr NewObject() const {
101 // Return a new container object
102 return fClass.GetClass()==0 ? TClass::ObjectPtr{} : fClass->NewObject();
103 }
104 virtual TClass::ObjectPtr NewObject(void *arena) const {
105 // Execute the container constructor
106 return fClass.GetClass()==0 ? TClass::ObjectPtr{} : fClass->NewObject(arena);
107 }
108
109 virtual void *NewArray(Int_t nElements) const {
110 // Return a new container object
111 return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements);
112 }
113 virtual void *NewArray(Int_t nElements, void *arena) const {
114 // Execute the container constructor
115 return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements, arena);
116 }
117 virtual TClass::ObjectPtr NewObjectArray(Int_t nElements) const {
118 // Return a new container object
119 return fClass.GetClass()==0 ? TClass::ObjectPtr{} : fClass->NewObjectArray(nElements);
120 }
121 virtual TClass::ObjectPtr NewObjectArray(Int_t nElements, void *arena) const {
122 // Execute the container constructor
123 return fClass.GetClass()==0 ? TClass::ObjectPtr{} : fClass->NewObjectArray(nElements, arena);
124 }
125
126 virtual void Destructor(void *p, Bool_t dtorOnly = kFALSE) const {
127 // Execute the container destructor
128 TClass* cl = fClass.GetClass();
129 if (cl) cl->Destructor(p, dtorOnly);
130 }
131
132 virtual void DeleteArray(void *p, Bool_t dtorOnly = kFALSE) const {
133 // Execute the container array destructor
134 TClass* cl = fClass.GetClass();
135 if (cl) cl->DeleteArray(p, dtorOnly);
136 }
137
138 virtual UInt_t Sizeof() const = 0;
139 // Return the sizeof the collection object.
140
141 virtual void PushProxy(void *objectstart) = 0;
142 // Set the address of the container being proxied and keep track of the previous one.
143
144 virtual void PopProxy() = 0;
145 // Reset the address of the container being proxied to the previous container
146
147 virtual Bool_t HasPointers() const = 0;
148 // Return true if the content is of type 'pointer to'
149
150 virtual TClass *GetValueClass() const = 0;
151 // Return a pointer to the TClass representing the content.
152
153 virtual EDataType GetType() const = 0;
154 // If the content is a simple numerical value, return its type (see TDataType)
155
156 virtual void *At(UInt_t idx) = 0;
157 // Return the address of the value at index 'idx'
158
159 virtual void Clear(const char *opt = "") = 0;
160 // Clear the container
161
162 virtual UInt_t Size() const = 0;
163 // Return the current size of the container
164
165 virtual void* Allocate(UInt_t n, Bool_t forceDelete) = 0;
166
167 virtual void Commit(void*) = 0;
168
169 virtual void Insert(const void *data, void *container, size_t size) = 0;
170 // Insert data into the container where data is a C-style array of the actual type contained in the collection
171 // of the given size. For associative container (map, etc.), the data type is the pair<key,value>.
172
173 char *operator[](UInt_t idx) const { return (char*)(const_cast<TVirtualCollectionProxy*>(this))->At(idx); }
174
175 // MemberWise actions
179
180 // Set of functions to iterate easily throught the collection
181 static const Int_t fgIteratorArenaSize = 16; // greater than sizeof(void*) + sizeof(UInt_t)
182
183 typedef void (*CreateIterators_t)(void *collection, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy);
185 // begin_arena and end_arena should contain the location of a memory arena of size fgIteratorSize.
186 // If the collection iterator are of that size or less, the iterators will be constructed in place in those location (new with placement)
187 // Otherwise the iterators will be allocated via a regular new and their address returned by modifying the value of begin_arena and end_arena.
188
189 typedef void* (*CopyIterator_t)(void *dest, const void *source);
191 // Copy the iterator source, into dest. dest should contain the location of a memory arena of size fgIteratorSize.
192 // If the collection iterator is of that size or less, the iterator will be constructed in place in this location (new with placement)
193 // Otherwise the iterator will be allocated via a regular new.
194 // The actual address of the iterator is returned in both case.
195
196 typedef void* (*Next_t)(void *iter, const void *end);
197 virtual Next_t GetFunctionNext(Bool_t read = kTRUE) = 0;
198 // iter and end should be pointers to respectively an iterator to be incremented and the result of collection.end()
199 // If the iterator has not reached the end of the collection, 'Next' increment the iterator 'iter' and return 0 if
200 // the iterator reached the end.
201 // If the end was not reached, 'Next' returns the address of the content pointed to by the iterator before the
202 // incrementation ; if the collection contains pointers, 'Next' will return the value of the pointer.
203
204 typedef void (*DeleteIterator_t)(void *iter);
205 typedef void (*DeleteTwoIterators_t)(void *begin, void *end);
206
209 // If the size of the iterator is greater than fgIteratorArenaSize, call delete on the addresses,
210 // Otherwise just call the iterator's destructor.
211
212};
213
214#endif
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
unsigned long ULong_t
Definition RtypesCore.h:55
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:5179
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:4964
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition TClass.cxx:5386
void DeleteArray(void *ary, Bool_t dtorOnly=kFALSE)
Explicitly call operator delete[] for an array.
Definition TClass.cxx:5515
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:5195
ObjectPtr NewObject(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Definition TClass.cxx:4978
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 UInt_t Sizeof() const =0
virtual ULong_t GetIncrement() const =0
virtual TStreamerInfoActions::TActionSequence * GetReadMemberWiseActions(Int_t version)=0
void(* CreateIterators_t)(void *collection, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy)
virtual TClass::ObjectPtr NewObjectArray(Int_t nElements) const
virtual void Destructor(void *p, Bool_t dtorOnly=kFALSE) const
virtual EDataType GetType() const =0
void *(* CopyIterator_t)(void *dest, const void *source)
char * operator[](UInt_t idx) const
virtual void * NewArray(Int_t nElements, void *arena) const
virtual void Clear(const char *opt="")=0
virtual TStreamerInfoActions::TActionSequence * GetWriteMemberWiseActions()=0
void *(* Next_t)(void *iter, const void *end)
virtual void PopProxy()=0
virtual void DeleteArray(void *p, Bool_t dtorOnly=kFALSE) const
virtual TClass * GetValueClass() const =0
virtual TClass::ObjectPtr NewObject(void *arena) const
virtual void Commit(void *)=0
virtual TClass::ObjectPtr NewObject() const
virtual void * At(UInt_t idx)=0
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
virtual void * NewArray(Int_t nElements) const
void(* DeleteTwoIterators_t)(void *begin, void *end)
void(* DeleteIterator_t)(void *iter)
virtual void * New(void *arena) const
static const Int_t fgIteratorArenaSize
virtual TVirtualCollectionProxy * Generate() const =0
virtual CreateIterators_t GetFunctionCreateIterators(Bool_t read=kTRUE)=0
virtual TClass::ObjectPtr NewObjectArray(Int_t nElements, void *arena) const
virtual void * Allocate(UInt_t n, Bool_t forceDelete)=0
virtual TStreamerInfoActions::TActionSequence * GetConversionReadMemberWiseActions(TClass *oldClass, Int_t version)=0
TVirtualCollectionProxy & operator=(const TVirtualCollectionProxy &)=delete
virtual DeleteIterator_t GetFunctionDeleteIterator(Bool_t read=kTRUE)=0
TVirtualCollectionProxy(const TVirtualCollectionProxy &)=delete
virtual CopyIterator_t GetFunctionCopyIterator(Bool_t read=kTRUE)=0
virtual Bool_t HasPointers() const =0
virtual TClass * GetCollectionClass() const
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