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