Logo ROOT   6.10/09
Reference Guide
TVirtualArray.h
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Philippe Canal July, 2008
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
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_TVirtualArray
13 #define ROOT_TVirtualArray
14 
15 
16 
17 /**
18 \class TVirtualArray
19 \ingroup IO
20 Wrapper around an object and giving indirect access to its content
21 even if the object is not of a class in the Cint/Reflex dictionary.
22 */
23 
24 #include "TClassRef.h"
25 
27 public:
31  char *fArray; ///<[fSize]
32 
33  TVirtualArray( TClass *cl, UInt_t size ) : fClass(cl), fCapacity(size), fSize(size), fArray( (char*)( cl ? cl->NewArray(size) : 0) ) {};
34  ~TVirtualArray() { if (fClass) fClass->DeleteArray( fArray ); }
35 
36  TClass *GetClass() { return fClass; }
37  char *operator[](UInt_t ind) const { return GetObjectAt(ind); }
38  char *GetObjectAt(UInt_t ind) const { return fArray+fClass->Size()*ind; }
39 
40  void SetSize(UInt_t size) {
41  // Set the used size of this array to 'size'. If size is greater than the existing
42  // capacity, reallocate the array BUT no data is preserved.
43  fSize = size;
44  if (fSize > fCapacity && fClass) {
45  fClass->DeleteArray( fArray );
46  fArray = (char*)fClass->NewArray(fSize);
47  fCapacity = fSize;
48  }
49  }
50 
51 
52 };
53 
54 #endif // ROOT_TVirtualArray
void DeleteArray(void *ary, Bool_t dtorOnly=kFALSE)
Explicitly call operator delete[] for an array.
Definition: TClass.cxx:5180
char * GetObjectAt(UInt_t ind) const
Definition: TVirtualArray.h:38
TVirtualArray(TClass *cl, UInt_t size)
Definition: TVirtualArray.h:33
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
Wrapper around an object and giving indirect access to its content even if the object is not of a cla...
Definition: TVirtualArray.h:26
char * operator[](UInt_t ind) const
Definition: TVirtualArray.h:37
unsigned int UInt_t
Definition: RtypesCore.h:42
UInt_t fCapacity
Definition: TVirtualArray.h:29
Int_t Size() const
Return size of object of this class.
Definition: TClass.cxx:5348
char * fArray
[fSize]
Definition: TVirtualArray.h:31
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:71
TClassRef fClass
Definition: TVirtualArray.h:28
TClassRef is used to implement a permanent reference to a TClass object.
Definition: TClassRef.h:29
void SetSize(UInt_t size)
Definition: TVirtualArray.h:40
TClass * GetClass()
Definition: TVirtualArray.h:36