ROOT  6.06/09
Reference Guide
TArray.cxx
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 /** \class TArray
13 Abstract array base class. Used by TArrayC, TArrayS, TArrayI,
14 TArrayL, TArrayF and TArrayD.
15 Data member is public for historical reasons.
16 */
17 
18 #include "TArray.h"
19 #include "TError.h"
20 #include "TClass.h"
21 #include "TBuffer.h"
22 
23 
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Generate an out-of-bounds error. Always returns false.
28 
29 Bool_t TArray::OutOfBoundsError(const char *where, Int_t i) const
30 {
31  ::Error(where, "index %d out of bounds (size: %d, this: 0x%lx)", i, fN, (Long_t)this);
32  return kFALSE;
33 }
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Read TArray object from buffer. Simplified version of
37 /// TBuffer::ReadObject (does not keep track of multiple
38 /// references to same array).
39 
41 {
42  R__ASSERT(b.IsReading());
43 
44  // Make sure ReadArray is initialized
45  b.InitMap();
46 
47  // Before reading object save start position
48  UInt_t startpos = UInt_t(b.Length());
49 
50  UInt_t tag;
51  TClass *clRef = b.ReadClass(clReq, &tag);
52 
53  TArray *a;
54  if (!clRef) {
55 
56  a = 0;
57 
58  } else {
59 
60  a = (TArray *) clRef->New();
61  if (!a) {
62  ::Error("TArray::ReadArray", "could not create object of class %s",
63  clRef->GetName());
64  // Exception
65  return 0;
66  }
67 
68  a->Streamer(b);
69 
70  b.CheckByteCount(startpos, tag, clRef);
71  }
72 
73  return a;
74 }
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Write TArray object to buffer. Simplified version of
78 /// TBuffer::WriteObject (does not keep track of multiple
79 /// references to the same array).
80 
82 {
83  R__ASSERT(b.IsWriting());
84 
85  // Make sure WriteMap is initialized
86  b.InitMap();
87 
88  if (!a) {
89 
90  b << (UInt_t) 0;
91 
92  } else {
93 
94  // Reserve space for leading byte count
95  UInt_t cntpos = UInt_t(b.Length());
96  b.SetBufferOffset(Int_t(cntpos+sizeof(UInt_t)));
97 
98  TClass *cl = a->IsA();
99  b.WriteClass(cl);
100 
101  ((TArray *)a)->Streamer(b);
102 
103  // Write byte count
104  b.SetByteCount(cntpos);
105  }
106 }
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Write TArray or derived object to buffer.
110 
112 {
113  TArray::WriteArray(buf, obj);
114  return buf;
115 }
Abstract array base class.
Definition: TArray.h:33
void SetBufferOffset(Int_t offset=0)
Definition: TBuffer.h:88
Bool_t IsReading() const
Definition: TBuffer.h:81
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
#define R__ASSERT(e)
Definition: TError.h:98
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
virtual void WriteClass(const TClass *cl)=0
ClassImp(TArray) Bool_t TArray return kFALSE
Generate an out-of-bounds error. Always returns false.
Definition: TArray.cxx:24
TBuffer & operator<<(TBuffer &buf, const TArray *obj)
Write TArray or derived object to buffer.
Definition: TArray.cxx:111
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition: TClass.cxx:4683
virtual void InitMap()=0
static void WriteArray(TBuffer &b, const TArray *a)
Write TArray object to buffer.
Definition: TArray.cxx:81
void Error(const char *location, const char *msgfmt,...)
Bool_t IsWriting() const
Definition: TBuffer.h:82
static TArray * ReadArray(TBuffer &b, const TClass *clReq)
Read TArray object from buffer.
Definition: TArray.cxx:40
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
long Long_t
Definition: RtypesCore.h:50
#define ClassImp(name)
Definition: Rtypes.h:279
Int_t Length() const
Definition: TBuffer.h:94
virtual TClass * ReadClass(const TClass *cl=0, UInt_t *objTag=0)=0
TObject * obj