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