Logo ROOT   6.16/01
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\ingroup Containers
14Abstract array base class. Used by TArrayC, TArrayS, TArrayI,
15TArrayL, TArrayF and TArrayD.
16Data 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
30Bool_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}
#define b(i)
Definition: RSha256.hxx:100
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
#define ClassImp(name)
Definition: Rtypes.h:363
TBuffer & operator<<(TBuffer &buf, const TArray *obj)
Write TArray or derived object to buffer.
Definition: TArray.cxx:112
#define R__ASSERT(e)
Definition: TError.h:96
void Error(const char *location, const char *msgfmt,...)
Abstract array base class.
Definition: TArray.h:31
Int_t fN
Definition: TArray.h:38
static void WriteArray(TBuffer &b, const TArray *a)
Write TArray object to buffer.
Definition: TArray.cxx:82
static TArray * ReadArray(TBuffer &b, const TClass *clReq)
Read TArray object from buffer.
Definition: TArray.cxx:41
Bool_t OutOfBoundsError(const char *where, Int_t i) const
Generate an out-of-bounds error. Always returns false.
Definition: TArray.cxx:30
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition: TClass.cxx:4824
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
auto * a
Definition: textangle.C:12