Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:29:26

0001 // @(#)root/cont:$Id$
0002 // Author: Fons Rademakers   21/10/97
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_TArray
0013 #define ROOT_TArray
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TArray                                                               //
0019 //                                                                      //
0020 // Abstract array base class. Used by TArrayC, TArrayS, TArrayI,        //
0021 // TArrayL, TArrayF and TArrayD.                                        //
0022 // Data member is public for historical reasons.                        //
0023 //                                                                      //
0024 //////////////////////////////////////////////////////////////////////////
0025 
0026 #include "Rtypes.h"
0027 #include <cstring>   // used in all TArray derived classes for memset()
0028 
0029 class TBuffer;
0030 
0031 class TArray {
0032 
0033 protected:
0034    Bool_t        BoundsOk(const char *where, Int_t at) const;
0035    Bool_t        OutOfBoundsError(const char *where, Int_t i) const;
0036 
0037 public:
0038    Int_t     fN;            //Number of array elements
0039 
0040    TArray(): fN(0) { }
0041    TArray(Int_t n): fN(n) { }
0042    TArray(const TArray &a): fN(a.fN) { }
0043    TArray         &operator=(const TArray &rhs)
0044      {if(this!=&rhs) fN = rhs.fN; return *this; }
0045    virtual        ~TArray() { fN = 0; }
0046 
0047    Int_t          GetSize() const { return fN; }
0048    virtual void   Set(Int_t n) = 0;
0049 
0050    inline std::size_t size() const { return GetSize(); }
0051 
0052    virtual Double_t GetAt(Int_t i) const = 0;
0053    virtual void   SetAt(Double_t v, Int_t i) = 0;
0054 
0055    static TArray *ReadArray(TBuffer &b, const TClass *clReq);
0056    static void    WriteArray(TBuffer &b, const TArray *a);
0057 
0058    friend TBuffer &operator<<(TBuffer &b, const TArray *obj);
0059 
0060    ClassDef(TArray,1)  //Abstract array base class
0061 };
0062 
0063 #if defined R__TEMPLATE_OVERLOAD_BUG
0064 template <>
0065 #endif
0066 inline TBuffer &operator>>(TBuffer &buf, TArray *&obj)
0067 {
0068    // Read TArray object from buffer.
0069 
0070    obj = (TArray *) TArray::ReadArray(buf, TArray::Class());
0071    return buf;
0072 }
0073 
0074 #if defined R__TEMPLATE_OVERLOAD_BUG
0075 template <>
0076 #endif
0077 TBuffer &operator<<(TBuffer &b, const TArray *obj);
0078 
0079 inline Bool_t TArray::BoundsOk(const char *where, Int_t at) const
0080 {
0081    return (at < 0 || at >= fN)
0082                   ? OutOfBoundsError(where, at)
0083                   : kTRUE;
0084 }
0085 
0086 #endif