1 // @(#)root/cont:$Id$ 2 // Author: Fons Rademakers 21/10/97 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_TArray 13 #define ROOT_TArray 14 15 16 ////////////////////////////////////////////////////////////////////////// 17 // // 18 // TArray // 19 // // 20 // Abstract array base class. Used by TArrayC, TArrayS, TArrayI, // 21 // TArrayL, TArrayF and TArrayD. // 22 // Data member is public for historical reasons. // 23 // // 24 ////////////////////////////////////////////////////////////////////////// 25 26 #ifndef ROOT_Rtypes 27 #include "Rtypes.h" 28 #endif 29 #include <string.h> 30 31 class TBuffer; 32 33 class TArray { 34 35 protected: 36 Bool_t BoundsOk(const char *where, Int_t at) const; 37 Bool_t OutOfBoundsError(const char *where, Int_t i) const; 38 39 public: 40 Int_t fN; //Number of array elements 41 42 TArray(): fN(0) { } 43 TArray(Int_t n): fN(n) { } 44 TArray(const TArray &a): fN(a.fN) { } 45 TArray &operator=(const TArray &rhs) 46 {if(this!=&rhs) fN = rhs.fN; return *this; } 47 virtual ~TArray() { fN = 0; } 48 49 Int_t GetSize() const { return fN; } 50 virtual void Set(Int_t n) = 0; 51 52 virtual Double_t GetAt(Int_t i) const = 0; 53 virtual void SetAt(Double_t v, Int_t i) = 0; 54 55 static TArray *ReadArray(TBuffer &b, const TClass *clReq); 56 static void WriteArray(TBuffer &b, const TArray *a); 57 58 friend TBuffer &operator<<(TBuffer &b, const TArray *obj); 59 60 ClassDef(TArray,1) //Abstract array base class 61 }; 62 63 #if defined R__TEMPLATE_OVERLOAD_BUG 64 template <> 65 #endif 66 inline TBuffer &operator>>(TBuffer &buf, TArray *&obj) 67 { 68 // Read TArray object from buffer. 69 70 obj = (TArray *) TArray::ReadArray(buf, TArray::Class()); 71 return buf; 72 } 73 74 #if defined R__TEMPLATE_OVERLOAD_BUG 75 template <> 76 #endif 77 TBuffer &operator<<(TBuffer &b, const TArray *obj); 78 79 inline Bool_t TArray::BoundsOk(const char *where, Int_t at) const 80 { 81 return (at < 0 || at >= fN) 82 ? OutOfBoundsError(where, at) 83 : kTRUE; 84 } 85 86 #endif 87