TArray.h

Go to the documentation of this file.
00001 // @(#)root/cont:$Id: TArray.h 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Fons Rademakers   21/10/97
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TArray
00013 #define ROOT_TArray
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TArray                                                               //
00019 //                                                                      //
00020 // Abstract array base class. Used by TArrayC, TArrayS, TArrayI,        //
00021 // TArrayL, TArrayF and TArrayD.                                        //
00022 // Data member is public for historical reasons.                        //
00023 //                                                                      //
00024 //////////////////////////////////////////////////////////////////////////
00025 
00026 #ifndef ROOT_Rtypes
00027 #include "Rtypes.h"
00028 #endif
00029 #include <string.h>
00030 
00031 class TBuffer;
00032 
00033 class TArray {
00034 
00035 protected:
00036    Bool_t        BoundsOk(const char *where, Int_t at) const;
00037    Bool_t        OutOfBoundsError(const char *where, Int_t i) const;
00038 
00039 public:
00040    Int_t     fN;            //Number of array elements
00041 
00042    TArray(): fN(0) { }
00043    TArray(Int_t n): fN(n) { }
00044    TArray(const TArray &a): fN(a.fN) { }
00045    TArray         &operator=(const TArray &rhs) 
00046      {if(this!=&rhs) fN = rhs.fN; return *this; }
00047    virtual        ~TArray() { fN = 0; }
00048 
00049    Int_t          GetSize() const { return fN; }
00050    virtual void   Set(Int_t n) = 0;
00051 
00052    virtual Double_t GetAt(Int_t i) const = 0;
00053    virtual void   SetAt(Double_t v, Int_t i) = 0;
00054 
00055    static TArray *ReadArray(TBuffer &b, const TClass *clReq);
00056    static void    WriteArray(TBuffer &b, const TArray *a);
00057 
00058    friend TBuffer &operator<<(TBuffer &b, const TArray *obj);
00059 
00060    ClassDef(TArray,1)  //Abstract array base class
00061 };
00062 
00063 #if defined R__TEMPLATE_OVERLOAD_BUG
00064 template <>
00065 #endif
00066 inline TBuffer &operator>>(TBuffer &buf, TArray *&obj)
00067 {
00068    // Read TArray object from buffer.
00069 
00070    obj = (TArray *) TArray::ReadArray(buf, TArray::Class());
00071    return buf;
00072 }
00073 
00074 #if defined R__TEMPLATE_OVERLOAD_BUG
00075 template <>
00076 #endif
00077 TBuffer &operator<<(TBuffer &b, const TArray *obj);
00078 
00079 inline Bool_t TArray::BoundsOk(const char *where, Int_t at) const
00080 {
00081    return (at < 0 || at >= fN)
00082                   ? OutOfBoundsError(where, at)
00083                   : kTRUE;
00084 }
00085 
00086 #endif

Generated on Tue Jul 5 14:11:25 2011 for ROOT_528-00b_version by  doxygen 1.5.1