Logo ROOT  
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
20Wrapper around an object and giving indirect access to its content
21even if the object is not of a class in the Cint/Reflex dictionary.
22*/
23
24#include "TClass.h"
25#include "TClassRef.h"
26
28public:
30
34 ObjectPtr fArray; ///< fSize elements
35
36 TVirtualArray( TClass *cl, UInt_t size ) : fClass(cl), fCapacity(size), fSize(size), fArray( ( cl ? cl->NewObjectArray(size) : ObjectPtr{nullptr, nullptr}) ) {};
38
39 TClass *GetClass() { return fClass; }
40 char *operator[](UInt_t ind) const { return GetObjectAt(ind); }
41 char *GetObjectAt(UInt_t ind) const { return ((char*)fArray.GetPtr())+fClass->Size()*ind; }
42
43 void SetSize(UInt_t size) {
44 // Set the used size of this array to 'size'. If size is greater than the existing
45 // capacity, reallocate the array BUT no data is preserved.
46 fSize = size;
47 if (fSize > fCapacity && fClass) {
51 }
52 }
53
54
55};
56
57#endif // ROOT_TVirtualArray
unsigned int UInt_t
Definition: RtypesCore.h:44
TClassRef is used to implement a permanent reference to a TClass object.
Definition: TClassRef.h:28
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
Int_t Size() const
Return size of object of this class.
Definition: TClass.cxx:5674
void DeleteArray(void *ary, Bool_t dtorOnly=kFALSE)
Explicitly call operator delete[] for an array.
Definition: TClass.cxx:5499
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:5179
Wrapper around an object and giving indirect access to its content even if the object is not of a cla...
Definition: TVirtualArray.h:27
ObjectPtr fArray
fSize elements
Definition: TVirtualArray.h:34
char * GetObjectAt(UInt_t ind) const
Definition: TVirtualArray.h:41
TClass * GetClass()
Definition: TVirtualArray.h:39
void SetSize(UInt_t size)
Definition: TVirtualArray.h:43
UInt_t fCapacity
Definition: TVirtualArray.h:32
char * operator[](UInt_t ind) const
Definition: TVirtualArray.h:40
TClassRef fClass
Definition: TVirtualArray.h:31
TVirtualArray(TClass *cl, UInt_t size)
Definition: TVirtualArray.h:36
const char * ObjectPtr
void * GetPtr() const
Definition: TClass.h:147