Logo ROOT   6.19/01
Reference Guide
TArrayI.h
Go to the documentation of this file.
1 // @(#)root/cont:$Id$
2 // Author: Rene Brun 06/03/95
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_TArrayI
13 #define ROOT_TArrayI
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TArrayI //
19 // //
20 // Array of integers (32 bits per element). //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "TArray.h"
25 
26 
27 class TArrayI : public TArray {
28 
29 public:
30  Int_t *fArray; //[fN] Array of fN 32 bit integers
31 
32  TArrayI();
33  TArrayI(Int_t n);
34  TArrayI(Int_t n, const Int_t *array);
35  TArrayI(const TArrayI &array);
36  TArrayI &operator=(const TArrayI &rhs);
37  virtual ~TArrayI();
38 
39  void Adopt(Int_t n, Int_t *array);
40  void AddAt(Int_t c, Int_t i);
41  Int_t At(Int_t i) const ;
42  void Copy(TArrayI &array) const {array.Set(fN,fArray);}
43  const Int_t *GetArray() const { return fArray; }
44  Int_t *GetArray() { return fArray; }
45  Double_t GetAt(Int_t i) const { return At(i); }
46  Stat_t GetSum() const {Stat_t sum=0; for (Int_t i=0;i<fN;i++) sum+=fArray[i]; return sum;}
47  void Reset() {memset(fArray, 0, fN*sizeof(Int_t));}
48  void Reset(Int_t val) {for (Int_t i=0;i<fN;i++) fArray[i] = val;}
49  void Set(Int_t n);
50  void Set(Int_t n, const Int_t *array);
51  void SetAt(Double_t v, Int_t i) { AddAt((Int_t)v, i); }
53  Int_t operator[](Int_t i) const;
54 
55  ClassDef(TArrayI,1) //Array of ints
56 };
57 
58 
59 #if defined R__TEMPLATE_OVERLOAD_BUG
60 template <>
61 #endif
62 inline TBuffer &operator>>(TBuffer &buf, TArrayI *&obj)
63 {
64  // Read TArrayI object from buffer.
65 
66  obj = (TArrayI *) TArray::ReadArray(buf, TArrayI::Class());
67  return buf;
68 }
69 
70 #if defined R__TEMPLATE_OVERLOAD_BUG
71 template <>
72 #endif
73 inline TBuffer &operator<<(TBuffer &buf, const TArrayI *obj)
74 {
75  // Write a TArrayI object into buffer
76  return buf << (const TArray*)obj;
77 }
78 
79 inline Int_t TArrayI::At(Int_t i) const
80 {
81  if (!BoundsOk("TArrayI::At", i)) return 0;
82  return fArray[i];
83 }
84 
86 {
87  if (!BoundsOk("TArrayI::operator[]", i))
88  i = 0;
89  return fArray[i];
90 }
91 
93 {
94  if (!BoundsOk("TArrayI::operator[]", i)) return 0;
95  return fArray[i];
96 }
97 
98 #endif
Abstract array base class.
Definition: TArray.h:31
static long int sum(long int i)
Definition: Factory.cxx:2276
void Copy(TArrayI &array) const
Definition: TArrayI.h:42
void Adopt(Int_t n, Int_t *array)
Adopt array arr into TArrayI, i.e.
Definition: TArrayI.cxx:81
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
TArrayI()
Default TArrayI ctor.
Definition: TArrayI.cxx:26
TBuffer & operator>>(TBuffer &buf, TArrayI *&obj)
Definition: TArrayI.h:62
int Int_t
Definition: RtypesCore.h:41
Array of integers (32 bits per element).
Definition: TArrayI.h:27
#define ClassDef(name, id)
Definition: Rtypes.h:326
void Class()
Definition: Class.C:29
Bool_t BoundsOk(const char *where, Int_t at) const
Definition: TArray.h:77
const Int_t * GetArray() const
Definition: TArrayI.h:43
TBuffer & operator<<(TBuffer &buf, const TArrayI *obj)
Definition: TArrayI.h:73
Double_t GetAt(Int_t i) const
Definition: TArrayI.h:45
void Set(Int_t n)
Set size of this array to n ints.
Definition: TArrayI.cxx:105
Int_t * GetArray()
Definition: TArrayI.h:44
void AddAt(Int_t c, Int_t i)
Add Int_t c at position i. Check for out of bounds.
Definition: TArrayI.cxx:93
Int_t fN
Definition: TArray.h:38
Int_t & operator[](Int_t i)
Definition: TArrayI.h:85
static TArray * ReadArray(TBuffer &b, const TClass *clReq)
Read TArray object from buffer.
Definition: TArray.cxx:41
virtual ~TArrayI()
Delete TArrayI object.
Definition: TArrayI.cxx:71
void SetAt(Double_t v, Int_t i)
Definition: TArrayI.h:51
Stat_t GetSum() const
Definition: TArrayI.h:46
double Double_t
Definition: RtypesCore.h:55
Int_t * fArray
Definition: TArrayI.h:30
double Stat_t
Definition: RtypesCore.h:73
TArrayI & operator=(const TArrayI &rhs)
TArrayI assignment operator.
Definition: TArrayI.cxx:61
void Reset()
Definition: TArrayI.h:47
#define c(i)
Definition: RSha256.hxx:101
Int_t At(Int_t i) const
Definition: TArrayI.h:79
const Int_t n
Definition: legend1.C:16
void Reset(Int_t val)
Definition: TArrayI.h:48