Logo ROOT  
Reference Guide
TArray.h
Go to the documentation of this file.
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 #include "Rtypes.h"
27 #include <cstring> // used in all TArray derived classes for memset()
28 
29 class TBuffer;
30 
31 class TArray {
32 
33 protected:
34  Bool_t BoundsOk(const char *where, Int_t at) const;
35  Bool_t OutOfBoundsError(const char *where, Int_t i) const;
36 
37 public:
38  Int_t fN; //Number of array elements
39 
40  TArray(): fN(0) { }
41  TArray(Int_t n): fN(n) { }
42  TArray(const TArray &a): fN(a.fN) { }
43  TArray &operator=(const TArray &rhs)
44  {if(this!=&rhs) fN = rhs.fN; return *this; }
45  virtual ~TArray() { fN = 0; }
46 
47  Int_t GetSize() const { return fN; }
48  virtual void Set(Int_t n) = 0;
49 
50  virtual Double_t GetAt(Int_t i) const = 0;
51  virtual void SetAt(Double_t v, Int_t i) = 0;
52 
53  static TArray *ReadArray(TBuffer &b, const TClass *clReq);
54  static void WriteArray(TBuffer &b, const TArray *a);
55 
56  friend TBuffer &operator<<(TBuffer &b, const TArray *obj);
57 
58  ClassDef(TArray,1) //Abstract array base class
59 };
60 
61 #if defined R__TEMPLATE_OVERLOAD_BUG
62 template <>
63 #endif
64 inline TBuffer &operator>>(TBuffer &buf, TArray *&obj)
65 {
66  // Read TArray object from buffer.
67 
68  obj = (TArray *) TArray::ReadArray(buf, TArray::Class());
69  return buf;
70 }
71 
72 #if defined R__TEMPLATE_OVERLOAD_BUG
73 template <>
74 #endif
75 TBuffer &operator<<(TBuffer &b, const TArray *obj);
76 
77 inline Bool_t TArray::BoundsOk(const char *where, Int_t at) const
78 {
79  return (at < 0 || at >= fN)
80  ? OutOfBoundsError(where, at)
81  : kTRUE;
82 }
83 
84 #endif
n
const Int_t n
Definition: legend1.C:16
TArray::TArray
TArray()
Definition: TArray.h:40
TArray::GetAt
virtual Double_t GetAt(Int_t i) const =0
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
operator<<
TBuffer & operator<<(TBuffer &b, const TArray *obj)
Write TArray or derived object to buffer.
Definition: TArray.cxx:112
TArray::SetAt
virtual void SetAt(Double_t v, Int_t i)=0
TArray::TArray
TArray(const TArray &a)
Definition: TArray.h:42
TBuffer
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
TArray::fN
Int_t fN
Definition: TArray.h:38
TArray::~TArray
virtual ~TArray()
Definition: TArray.h:45
v
@ v
Definition: rootcling_impl.cxx:3635
b
#define b(i)
Definition: RSha256.hxx:100
bool
TArray::OutOfBoundsError
Bool_t OutOfBoundsError(const char *where, Int_t i) const
Generate an out-of-bounds error. Always returns false.
Definition: TArray.cxx:30
a
auto * a
Definition: textangle.C:12
TArray::operator<<
friend TBuffer & operator<<(TBuffer &b, const TArray *obj)
Write TArray or derived object to buffer.
Definition: TArray.cxx:112
operator>>
TBuffer & operator>>(TBuffer &buf, TArray *&obj)
Definition: TArray.h:64
TArray::TArray
TArray(Int_t n)
Definition: TArray.h:41
TArray::ReadArray
static TArray * ReadArray(TBuffer &b, const TClass *clReq)
Read TArray object from buffer.
Definition: TArray.cxx:41
Double_t
double Double_t
Definition: RtypesCore.h:59
TArray
Abstract array base class.
Definition: TArray.h:31
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TArray::BoundsOk
Bool_t BoundsOk(const char *where, Int_t at) const
Definition: TArray.h:77
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TArray::WriteArray
static void WriteArray(TBuffer &b, const TArray *a)
Write TArray object to buffer.
Definition: TArray.cxx:82
TArray::operator=
TArray & operator=(const TArray &rhs)
Definition: TArray.h:43
Class
void Class()
Definition: Class.C:29
Rtypes.h
TArray::Set
virtual void Set(Int_t n)=0
TArray::GetSize
Int_t GetSize() const
Definition: TArray.h:47
int