Logo ROOT   6.10/09
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  };
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 
72  TVirtualCollectionProxy() : fClass(), fProperties(0) {};
73  TVirtualCollectionProxy(TClass *cl) : fClass(cl), fProperties(0) {};
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 
99  virtual void *NewArray(Int_t nElements) const {
100  // Return a new container object
101  return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements);
102  }
103  virtual void *NewArray(Int_t nElements, void *arena) const {
104  // Execute the container constructor
105  return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements, arena);
106  }
107 
108  virtual void Destructor(void *p, Bool_t dtorOnly = kFALSE) const {
109  // Execute the container destructor
110  TClass* cl = fClass.GetClass();
111  if (cl) cl->Destructor(p, dtorOnly);
112  }
113 
114  virtual void DeleteArray(void *p, Bool_t dtorOnly = kFALSE) const {
115  // Execute the container array destructor
116  TClass* cl = fClass.GetClass();
117  if (cl) cl->DeleteArray(p, dtorOnly);
118  }
119 
120  virtual UInt_t Sizeof() const = 0;
121  // Return the sizeof the collection object.
122 
123  virtual void PushProxy(void *objectstart) = 0;
124  // Set the address of the container being proxied and keep track of the previous one.
125 
126  virtual void PopProxy() = 0;
127  // Reset the address of the container being proxied to the previous container
128 
129  virtual Bool_t HasPointers() const = 0;
130  // Return true if the content is of type 'pointer to'
131 
132  virtual TClass *GetValueClass() const = 0;
133  // Return a pointer to the TClass representing the content.
134 
135  virtual EDataType GetType() const = 0;
136  // If the content is a simple numerical value, return its type (see TDataType)
137 
138  virtual void *At(UInt_t idx) = 0;
139  // Return the address of the value at index 'idx'
140 
141  virtual void Clear(const char *opt = "") = 0;
142  // Clear the container
143 
144  virtual UInt_t Size() const = 0;
145  // Return the current size of the container
146 
147  virtual void* Allocate(UInt_t n, Bool_t forceDelete) = 0;
148 
149  virtual void Commit(void*) = 0;
150 
151  virtual void Insert(const void *data, void *container, size_t size) = 0;
152  // Insert data into the container where data is a C-style array of the actual type contained in the collection
153  // of the given size. For associative container (map, etc.), the data type is the pair<key,value>.
154 
155  char *operator[](UInt_t idx) const { return (char*)(const_cast<TVirtualCollectionProxy*>(this))->At(idx); }
156 
157  // MemberWise actions
158  virtual TStreamerInfoActions::TActionSequence *GetConversionReadMemberWiseActions(TClass *oldClass, Int_t version) = 0;
159  virtual TStreamerInfoActions::TActionSequence *GetReadMemberWiseActions(Int_t version) = 0;
160  virtual TStreamerInfoActions::TActionSequence *GetWriteMemberWiseActions() = 0;
161 
162  // Set of functions to iterate easily throught the collection
163  static const Int_t fgIteratorArenaSize = 16; // greater than sizeof(void*) + sizeof(UInt_t)
164 
165  typedef void (*CreateIterators_t)(void *collection, void **begin_arena, void **end_arena, TVirtualCollectionProxy *proxy);
166  virtual CreateIterators_t GetFunctionCreateIterators(Bool_t read = kTRUE) = 0;
167  // begin_arena and end_arena should contain the location of a memory arena of size fgIteratorSize.
168  // If the collection iterator are of that size or less, the iterators will be constructed in place in those location (new with placement)
169  // Otherwise the iterators will be allocated via a regular new and their address returned by modifying the value of begin_arena and end_arena.
170 
171  typedef void* (*CopyIterator_t)(void *dest, const void *source);
172  virtual CopyIterator_t GetFunctionCopyIterator(Bool_t read = kTRUE) = 0;
173  // Copy the iterator source, into dest. dest should contain the location of a memory arena of size fgIteratorSize.
174  // If the collection iterator is of that size or less, the iterator will be constructed in place in this location (new with placement)
175  // Otherwise the iterator will be allocated via a regular new.
176  // The actual address of the iterator is returned in both case.
177 
178  typedef void* (*Next_t)(void *iter, const void *end);
179  virtual Next_t GetFunctionNext(Bool_t read = kTRUE) = 0;
180  // iter and end should be pointers to respectively an iterator to be incremented and the result of collection.end()
181  // If the iterator has not reached the end of the collection, 'Next' increment the iterator 'iter' and return 0 if
182  // the iterator reached the end.
183  // If the end was not reached, 'Next' returns the address of the content pointed to by the iterator before the
184  // incrementation ; if the collection contains pointers, 'Next' will return the value of the pointer.
185 
186  typedef void (*DeleteIterator_t)(void *iter);
187  typedef void (*DeleteTwoIterators_t)(void *begin, void *end);
188 
189  virtual DeleteIterator_t GetFunctionDeleteIterator(Bool_t read = kTRUE) = 0;
190  virtual DeleteTwoIterators_t GetFunctionDeleteTwoIterators(Bool_t read = kTRUE) = 0;
191  // If the size of the iterator is greater than fgIteratorArenaSize, call delete on the addresses,
192  // Otherwise just call the iterator's destructor.
193 
194 };
195 
196 #endif
double read(const std::string &file_name)
reading
virtual void * NewArray(Int_t nElements) const
virtual Int_t GetProperties() const
const char * Size
Definition: TXMLSetup.cxx:56
char * operator[](UInt_t idx) const
virtual void PushProxy(void *objectstart)=0
#define BIT(n)
Definition: Rtypes.h:75
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:5180
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:4888
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition: TClass.cxx:5063
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:71
const Bool_t kFALSE
Definition: RtypesCore.h:92
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:91
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:4706