Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:32

0001 // @(#)root/io:$Id$
0002 // Author: Philippe Canal July, 2008
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010   *************************************************************************/
0011 
0012 #ifndef ROOT_TVirtualArray
0013 #define ROOT_TVirtualArray
0014 
0015 
0016 
0017 /**
0018 \class TVirtualArray
0019 \ingroup IO
0020 Wrapper around an object and giving indirect access to its content
0021 even if the object is not of a class in the Cint/Reflex dictionary.
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; ///< fSize elements
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       // Set the used size of this array to 'size'.   If size is greater than the existing
0045       // capacity, reallocate the array BUT no data is preserved.
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 // ROOT_TVirtualArray