File indexing completed on 2025-01-18 10:12:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TVirtualArray
0013 #define ROOT_TVirtualArray
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include "TClass.h"
0025 #include "TClassRef.h"
0026
0027 class TVirtualArray {
0028 public:
0029 using ObjectPtr = TClass::ObjectPtr;
0030
0031 TClassRef fClass;
0032 UInt_t fCapacity;
0033 UInt_t fSize;
0034 ObjectPtr fArray;
0035
0036 TVirtualArray( TClass *cl, UInt_t size ) : fClass(cl), fCapacity(size), fSize(size), fArray( ( cl ? cl->NewObjectArray(size) : ObjectPtr{nullptr, nullptr}) ) {};
0037 ~TVirtualArray() { if (fClass) fClass->DeleteArray( fArray ); }
0038
0039 TClass *GetClass() { return fClass; }
0040 char *operator[](UInt_t ind) const { return GetObjectAt(ind); }
0041 char *GetObjectAt(UInt_t ind) const { return ((char*)fArray.GetPtr())+fClass->Size()*ind; }
0042
0043 void SetSize(UInt_t size) {
0044
0045
0046 fSize = size;
0047 if (fSize > fCapacity && fClass) {
0048 fClass->DeleteArray( fArray );
0049 fArray = fClass->NewObjectArray(fSize);
0050 fCapacity = fSize;
0051 }
0052 }
0053
0054
0055 };
0056
0057 #endif