ROOT  6.06/09
Reference Guide
TArrayS.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_TArrayS
13 #define ROOT_TArrayS
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TArrayS //
19 // //
20 // Array of shorts (16 bits per element). //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #ifndef ROOT_TArray
25 #include "TArray.h"
26 #endif
27 
28 
29 class TArrayS : public TArray {
30 
31 public:
32  Short_t *fArray; //[fN] Array of fN shorts
33 
34  TArrayS();
35  TArrayS(Int_t n);
36  TArrayS(Int_t n, const Short_t *array);
37  TArrayS(const TArrayS &array);
38  TArrayS &operator=(const TArrayS &rhs);
39  virtual ~TArrayS();
40 
41  void Adopt(Int_t n, Short_t *array);
42  void AddAt(Short_t c, Int_t i);
43  Short_t At(Int_t i) const ;
44  void Copy(TArrayS &array) const {array.Set(fN,fArray);}
45  const Short_t *GetArray() const { return fArray; }
46  Short_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(Short_t));}
50  void Reset(Short_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 Short_t *array);
53  void SetAt(Double_t v, Int_t i) { AddAt((Short_t)v, i); }
55  Short_t operator[](Int_t i) const;
56 
57  ClassDef(TArrayS,1) //Array of shorts
58 };
59 
60 #if defined R__TEMPLATE_OVERLOAD_BUG
61 template <>
62 #endif
64 {
65  // Read TArrayS object from buffer.
66 
67  obj = (TArrayS *) TArray::ReadArray(buf, TArrayS::Class());
68  return buf;
69 }
70 
71 #if defined R__TEMPLATE_OVERLOAD_BUG
72 template <>
73 #endif
74 inline TBuffer &operator<<(TBuffer &buf, const TArrayS *obj)
75 {
76  // Write a TArrayS object into buffer
77  return buf << (const TArray*)obj;
78 }
79 
80 inline Short_t TArrayS::At(Int_t i) const
81 {
82  if (!BoundsOk("TArrayS::At", i)) return 0;
83  return fArray[i];
84 }
85 
87 {
88  if (!BoundsOk("TArrayS::operator[]", i))
89  i = 0;
90  return fArray[i];
91 }
92 
94 {
95  if (!BoundsOk("TArrayS::operator[]", i)) return 0;
96  return fArray[i];
97 }
98 
99 #endif
Abstract array base class.
Definition: TArray.h:33
Short_t * fArray
Definition: TArrayS.h:32
void AddAt(Short_t c, Int_t i)
Add short c at position i. Check for out of bounds.
Definition: TArrayS.cxx:92
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
Double_t GetAt(Int_t i) const
Definition: TArrayS.h:47
void Copy(TArrayS &array) const
Definition: TArrayS.h:44
int Int_t
Definition: RtypesCore.h:41
void SetAt(Double_t v, Int_t i)
Definition: TArrayS.h:53
Short_t & operator[](Int_t i)
Definition: TArrayS.h:86
#define ClassDef(name, id)
Definition: Rtypes.h:254
void Class()
Definition: Class.C:29
virtual ~TArrayS()
Delete TArrayS object.
Definition: TArrayS.cxx:70
TBuffer & operator<<(TBuffer &buf, const TArrayS *obj)
Definition: TArrayS.h:74
Short_t At(Int_t i) const
Definition: TArrayS.h:80
void Set(Int_t n)
Set size of this array to n shorts.
Definition: TArrayS.cxx:104
TArrayS & operator=(const TArrayS &rhs)
TArrayS assignment operator.
Definition: TArrayS.cxx:60
void Reset()
Definition: TArrayS.h:49
Int_t fN
Definition: TArray.h:40
Bool_t BoundsOk(const char *where, Int_t at) const
Definition: TArray.h:79
Array of shorts (16 bits per element).
Definition: TArrayS.h:29
SVector< double, 2 > v
Definition: Dict.h:5
static TArray * ReadArray(TBuffer &b, const TClass *clReq)
Read TArray object from buffer.
Definition: TArray.cxx:40
short Short_t
Definition: RtypesCore.h:35
double Double_t
Definition: RtypesCore.h:55
TBuffer & operator>>(TBuffer &buf, TArrayS *&obj)
Definition: TArrayS.h:63
double Stat_t
Definition: RtypesCore.h:73
Stat_t GetSum() const
Definition: TArrayS.h:48
void Reset(Short_t val)
Definition: TArrayS.h:50
Short_t * GetArray()
Definition: TArrayS.h:46
const Short_t * GetArray() const
Definition: TArrayS.h:45
TObject * obj
const Int_t n
Definition: legend1.C:16
void Adopt(Int_t n, Short_t *array)
Adopt array arr into TArrayS, i.e.
Definition: TArrayS.cxx:80