Logo ROOT   6.08/07
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 #ifndef ROOT_TArray
25 #include "TArray.h"
26 #endif
27 
28 
29 class TArrayI : public TArray {
30 
31 public:
32  Int_t *fArray; //[fN] Array of fN 32 bit integers
33 
34  TArrayI();
35  TArrayI(Int_t n);
36  TArrayI(Int_t n, const Int_t *array);
37  TArrayI(const TArrayI &array);
38  TArrayI &operator=(const TArrayI &rhs);
39  virtual ~TArrayI();
40 
41  void Adopt(Int_t n, Int_t *array);
42  void AddAt(Int_t c, Int_t i);
43  Int_t At(Int_t i) const ;
44  void Copy(TArrayI &array) const {array.Set(fN,fArray);}
45  const Int_t *GetArray() const { return fArray; }
46  Int_t *GetArray() { return fArray; }
47  Double_t GetAt(Int_t i) const { return At(i); }
48  Stat_t GetSum() const {Stat_t sum=0; for (Int_t i=0;i<fN;i++) sum+=fArray[i]; return sum;}
49  void Reset() {memset(fArray, 0, fN*sizeof(Int_t));}
50  void Reset(Int_t val) {for (Int_t i=0;i<fN;i++) fArray[i] = val;}
51  void Set(Int_t n);
52  void Set(Int_t n, const Int_t *array);
53  void SetAt(Double_t v, Int_t i) { AddAt((Int_t)v, i); }
55  Int_t operator[](Int_t i) const;
56 
57  ClassDef(TArrayI,1) //Array of ints
58 };
59 
60 
61 #if defined R__TEMPLATE_OVERLOAD_BUG
62 template <>
63 #endif
64 inline TBuffer &operator>>(TBuffer &buf, TArrayI *&obj)
65 {
66  // Read TArrayI object from buffer.
67 
68  obj = (TArrayI *) TArray::ReadArray(buf, TArrayI::Class());
69  return buf;
70 }
71 
72 #if defined R__TEMPLATE_OVERLOAD_BUG
73 template <>
74 #endif
75 inline TBuffer &operator<<(TBuffer &buf, const TArrayI *obj)
76 {
77  // Write a TArrayI object into buffer
78  return buf << (const TArray*)obj;
79 }
80 
81 inline Int_t TArrayI::At(Int_t i) const
82 {
83  if (!BoundsOk("TArrayI::At", i)) return 0;
84  return fArray[i];
85 }
86 
88 {
89  if (!BoundsOk("TArrayI::operator[]", i))
90  i = 0;
91  return fArray[i];
92 }
93 
95 {
96  if (!BoundsOk("TArrayI::operator[]", i)) return 0;
97  return fArray[i];
98 }
99 
100 #endif
Abstract array base class.
Definition: TArray.h:33
static long int sum(long int i)
Definition: Factory.cxx:1786
void Copy(TArrayI &array) const
Definition: TArrayI.h:44
return c
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:64
int Int_t
Definition: RtypesCore.h:41
const char * Class
Definition: TXMLSetup.cxx:64
Array of integers (32 bits per element).
Definition: TArrayI.h:29
#define ClassDef(name, id)
Definition: Rtypes.h:254
Bool_t BoundsOk(const char *where, Int_t at) const
Definition: TArray.h:79
const Int_t * GetArray() const
Definition: TArrayI.h:45
Double_t GetAt(Int_t i) const
Definition: TArrayI.h:47
void Set(Int_t n)
Set size of this array to n ints.
Definition: TArrayI.cxx:105
Int_t * GetArray()
Definition: TArrayI.h:46
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:40
Int_t & operator[](Int_t i)
Definition: TArrayI.h:87
SVector< double, 2 > v
Definition: Dict.h:5
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:53
Stat_t GetSum() const
Definition: TArrayI.h:48
friend TBuffer & operator<<(TBuffer &b, const TArray *obj)
Write TArray or derived object to buffer.
Definition: TArray.cxx:112
double Double_t
Definition: RtypesCore.h:55
Int_t * fArray
Definition: TArrayI.h:32
double Stat_t
Definition: RtypesCore.h:73
TArrayI & operator=(const TArrayI &rhs)
TArrayI assignment operator.
Definition: TArrayI.cxx:61
void Reset()
Definition: TArrayI.h:49
Int_t At(Int_t i) const
Definition: TArrayI.h:81
const Int_t n
Definition: legend1.C:16
void Reset(Int_t val)
Definition: TArrayI.h:50