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