Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
25
26////////////////////////////////////////////////////////////////////////////////
27/// Generate an out-of-bounds error. Always returns false.
28
30{
31 ::Error(where, "index %d out of bounds (size: %d, this: 0x%zx)", i, fN, (size_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 = nullptr;
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 nullptr;
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}
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:60
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
TBuffer & operator<<(TBuffer &buf, const TArray *obj)
Write TArray or derived object to buffer.
Definition TArray.cxx:111
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
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:81
static TArray * ReadArray(TBuffer &b, const TClass *clReq)
Read TArray object from buffer.
Definition TArray.cxx:40
Bool_t OutOfBoundsError(const char *where, Int_t i) const
Generate an out-of-bounds error. Always returns false.
Definition TArray.cxx:29
Buffer base class used for serializing objects.
Definition TBuffer.h:43
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
void Streamer(void *obj, TBuffer &b, const TClass *onfile_class=nullptr) const
Definition TClass.h:623
TClass * IsA() const override
Definition TClass.h:634