Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TBuffer.h
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Rene Brun, Philippe Canal, Fons Rademakers 04/05/96
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_TBuffer
13#define ROOT_TBuffer
14
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// TBuffer //
19// //
20// Buffer base class used for serializing objects. //
21// //
22//////////////////////////////////////////////////////////////////////////
23
24#include "TDataType.h"
25#include "TObject.h"
26#include "TClass.h"
27#include "Bytes.h"
28
29#include <vector>
30#include <string>
31
34class TString;
35class TProcessID;
36class TClonesArray;
37class TRefTable;
38class TVirtualArray;
40 class TActionSequence;
41}
42
43class TBuffer : public TObject {
44
45protected:
46 typedef std::vector<TVirtualArray*> CacheList_t;
47
48 Bool_t fMode; //Read or write mode
49 Int_t fVersion; //Buffer format version
50 Int_t fBufSize; //Size of buffer
51 char *fBuffer; //Buffer used to store objects
52 char *fBufCur; //Current position in buffer
53 char *fBufMax; //End of buffer
54 TObject *fParent; //Pointer to parent object owning this buffer
55 ReAllocCharFun_t fReAllocFunc; //! Realloc function to be used when extending the buffer.
56 CacheList_t fCacheStack; //Stack of pointers to the cache where to temporarily store the value of 'missing' data members
57
58 // Default ctor
59 TBuffer() : TObject(), fMode(0), fVersion(0), fBufSize(0), fBuffer(nullptr),
60 fBufCur(nullptr), fBufMax(nullptr), fParent(nullptr), fReAllocFunc(nullptr), fCacheStack(0, (TVirtualArray*)nullptr) {}
61
62 // TBuffer objects cannot be copied or assigned
63 TBuffer(const TBuffer &) = delete;
64 void operator=(const TBuffer &) = delete;
65
66 Int_t Read(const char *name) override { return TObject::Read(name); }
67 Int_t Write(const char *name, Int_t opt, Int_t bufs) override
68 { return TObject::Write(name, opt, bufs); }
69 Int_t Write(const char *name, Int_t opt, Int_t bufs) const override
70 { return TObject::Write(name, opt, bufs); }
71
72public:
73 enum EMode { kRead = 0, kWrite = 1 };
75 kIsOwner = BIT(16), //if set TBuffer owns fBuffer
76 kCannotHandleMemberWiseStreaming = BIT(17) //if set TClonesArray should not use member wise streaming
77 };
78 enum { kInitialSize = 1024, kMinimalSize = 128 };
79
81 TBuffer(EMode mode, Int_t bufsiz);
82 TBuffer(EMode mode, Int_t bufsiz, void *buf, Bool_t adopt = kTRUE, ReAllocCharFun_t reallocfunc = nullptr);
83 virtual ~TBuffer();
84
85 Int_t GetBufferVersion() const { return fVersion; }
86 Bool_t IsReading() const { return (fMode & kWrite) == 0; }
87 Bool_t IsWriting() const { return (fMode & kWrite) != 0; }
88 void SetReadMode();
89 void SetWriteMode();
90 void SetBuffer(void *buf, UInt_t bufsiz = 0, Bool_t adopt = kTRUE, ReAllocCharFun_t reallocfunc = nullptr);
92 void SetReAllocFunc(ReAllocCharFun_t reallocfunc = nullptr);
94 void SetParent(TObject *parent);
95 TObject *GetParent() const;
96 char *Buffer() const { return fBuffer; }
97 char *GetCurrent() const { return fBufCur; }
98 Int_t BufferSize() const { return fBufSize; }
99 void DetachBuffer() { fBuffer = nullptr; }
100 Int_t Length() const { return (Int_t)(fBufCur - fBuffer); }
101 void Expand(Int_t newsize, Bool_t copy = kTRUE); // expand buffer to newsize
102 void AutoExpand(Int_t size_needed); // expand buffer to newsize
103 Bool_t ByteSwapBuffer(Long64_t n, EDataType type); // Byte-swap N primitive-elements in the buffer
104
105 virtual Bool_t CheckObject(const TObject *obj) = 0;
106 virtual Bool_t CheckObject(const void *obj, const TClass *ptrClass) = 0;
107
108 virtual Int_t ReadBuf(void *buf, Int_t max) = 0;
109 virtual void WriteBuf(const void *buf, Int_t max) = 0;
110
111 virtual char *ReadString(char *s, Int_t max) = 0;
112 virtual void WriteString(const char *s) = 0;
113
114 virtual Int_t GetVersionOwner() const = 0;
115 virtual Int_t GetMapCount() const = 0;
116 virtual void GetMappedObject(UInt_t tag, void* &ptr, TClass* &ClassPtr) const = 0;
117 virtual void MapObject(const TObject *obj, UInt_t offset = 1) = 0;
118 virtual void MapObject(const void *obj, const TClass *cl, UInt_t offset = 1) = 0;
119 virtual void Reset() = 0;
120 virtual void InitMap() = 0;
121 virtual void ResetMap() = 0;
122 virtual void SetReadParam(Int_t mapsize) = 0;
123 virtual void SetWriteParam(Int_t mapsize) = 0;
124
125 virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss) = 0;
126 virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const char *classname) = 0;
127 virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion = kFALSE)= 0;
128
129 virtual void SkipVersion(const TClass *cl = nullptr) = 0;
130 virtual Version_t ReadVersion(UInt_t *start = nullptr, UInt_t *bcnt = nullptr, const TClass *cl = nullptr) = 0;
131 virtual Version_t ReadVersionNoCheckSum(UInt_t *start = nullptr, UInt_t *bcnt = nullptr) = 0;
132 virtual Version_t ReadVersionForMemberWise(const TClass *cl = nullptr) = 0;
133 virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt = kFALSE) = 0;
134 virtual UInt_t WriteVersionMemberWise(const TClass *cl, Bool_t useBcnt = kFALSE) = 0;
135
136 virtual void *ReadObjectAny(const TClass* cast) = 0;
137 virtual void SkipObjectAny() = 0;
138
139 virtual void TagStreamerInfo(TVirtualStreamerInfo* info) = 0;
140 virtual void IncrementLevel(TVirtualStreamerInfo* info) = 0;
141 virtual void SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type) = 0;
143
144 virtual void ClassBegin(const TClass*, Version_t = -1) = 0;
145 virtual void ClassEnd(const TClass*) = 0;
146 virtual void ClassMember(const char*, const char * = nullptr, Int_t = -1, Int_t = -1) = 0;
148
149 virtual TVirtualArray *PeekDataCache() const;
150 virtual TVirtualArray *PopDataCache();
151 virtual void PushDataCache(TVirtualArray *);
152
153 virtual TClass *ReadClass(const TClass *cl = nullptr, UInt_t *objTag = nullptr) = 0;
154 virtual void WriteClass(const TClass *cl) = 0;
155
156 virtual TObject *ReadObject(const TClass *cl) = 0;
157 virtual void WriteObject(const TObject *obj, Bool_t cacheReuse) = 0;
158
159 template <class T> Int_t WriteObject(const T *objptr, Bool_t cacheReuse = kTRUE);
160
161 virtual Int_t WriteObjectAny(const void *obj, const TClass *ptrClass, Bool_t cacheReuse = kTRUE) = 0;
162
163 virtual UShort_t GetPidOffset() const = 0;
164 virtual void SetPidOffset(UShort_t offset) = 0;
165 virtual Int_t GetBufferDisplacement() const = 0;
166 virtual void SetBufferDisplacement() = 0;
167 virtual void SetBufferDisplacement(Int_t skipped) = 0;
168
169 // basic types and arrays of basic types
170 virtual void ReadFloat16 (Float_t *f, TStreamerElement *ele = nullptr) = 0;
171 virtual void WriteFloat16(Float_t *f, TStreamerElement *ele = nullptr) = 0;
172 virtual void ReadDouble32 (Double_t *d, TStreamerElement *ele = nullptr) = 0;
173 virtual void WriteDouble32(Double_t *d, TStreamerElement *ele = nullptr) = 0;
174 virtual void ReadWithFactor(Float_t *ptr, Double_t factor, Double_t minvalue) = 0;
175 virtual void ReadWithNbits(Float_t *ptr, Int_t nbits) = 0;
176 virtual void ReadWithFactor(Double_t *ptr, Double_t factor, Double_t minvalue) = 0;
177 virtual void ReadWithNbits(Double_t *ptr, Int_t nbits) = 0;
178
179 virtual Int_t ReadArray(Bool_t *&b) = 0;
180 virtual Int_t ReadArray(Char_t *&c) = 0;
181 virtual Int_t ReadArray(UChar_t *&c) = 0;
182 virtual Int_t ReadArray(Short_t *&h) = 0;
183 virtual Int_t ReadArray(UShort_t *&h) = 0;
184 virtual Int_t ReadArray(Int_t *&i) = 0;
185 virtual Int_t ReadArray(UInt_t *&i) = 0;
186 virtual Int_t ReadArray(Long_t *&l) = 0;
187 virtual Int_t ReadArray(ULong_t *&l) = 0;
188 virtual Int_t ReadArray(Long64_t *&l) = 0;
189 virtual Int_t ReadArray(ULong64_t *&l) = 0;
190 virtual Int_t ReadArray(Float_t *&f) = 0;
191 virtual Int_t ReadArray(Double_t *&d) = 0;
192 virtual Int_t ReadArrayFloat16(Float_t *&f, TStreamerElement *ele = nullptr) = 0;
193 virtual Int_t ReadArrayDouble32(Double_t *&d, TStreamerElement *ele = nullptr) = 0;
194
200 virtual Int_t ReadStaticArray(Int_t *i) = 0;
201 virtual Int_t ReadStaticArray(UInt_t *i) = 0;
210
211 virtual void ReadFastArray(Bool_t *b, Int_t n) = 0;
212 virtual void ReadFastArray(Char_t *c, Int_t n) = 0;
213 virtual void ReadFastArrayString(Char_t *c, Int_t n) = 0;
214 virtual void ReadFastArray(UChar_t *c, Int_t n) = 0;
215 virtual void ReadFastArray(Short_t *h, Int_t n) = 0;
216 virtual void ReadFastArray(UShort_t *h, Int_t n) = 0;
217 virtual void ReadFastArray(Int_t *i, Int_t n) = 0;
218 virtual void ReadFastArray(UInt_t *i, Int_t n) = 0;
219 virtual void ReadFastArray(Long_t *l, Int_t n) = 0;
220 virtual void ReadFastArray(ULong_t *l, Int_t n) = 0;
221 virtual void ReadFastArray(Long64_t *l, Int_t n) = 0;
222 virtual void ReadFastArray(ULong64_t *l, Int_t n) = 0;
223 virtual void ReadFastArray(Float_t *f, Int_t n) = 0;
224 virtual void ReadFastArray(Double_t *d, Int_t n) = 0;
225 virtual void ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele = nullptr) = 0;
226 virtual void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele = nullptr) = 0;
227 virtual void ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue) = 0;
228 virtual void ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits) = 0;
229 virtual void ReadFastArrayWithFactor(Double_t *ptr, Int_t n, Double_t factor, Double_t minvalue) = 0;
230 virtual void ReadFastArrayWithNbits(Double_t *ptr, Int_t n, Int_t nbits) = 0;
231 virtual void ReadFastArray(void *start , const TClass *cl, Int_t n=1, TMemberStreamer *s = nullptr, const TClass *onFileClass = nullptr) = 0;
232 virtual void ReadFastArray(void **startp, const TClass *cl, Int_t n=1, Bool_t isPreAlloc=kFALSE, TMemberStreamer *s = nullptr, const TClass *onFileClass = nullptr) = 0;
233
234 virtual void WriteArray(const Bool_t *b, Int_t n) = 0;
235 virtual void WriteArray(const Char_t *c, Int_t n) = 0;
236 virtual void WriteArray(const UChar_t *c, Int_t n) = 0;
237 virtual void WriteArray(const Short_t *h, Int_t n) = 0;
238 virtual void WriteArray(const UShort_t *h, Int_t n) = 0;
239 virtual void WriteArray(const Int_t *i, Int_t n) = 0;
240 virtual void WriteArray(const UInt_t *i, Int_t n) = 0;
241 virtual void WriteArray(const Long_t *l, Int_t n) = 0;
242 virtual void WriteArray(const ULong_t *l, Int_t n) = 0;
243 virtual void WriteArray(const Long64_t *l, Int_t n) = 0;
244 virtual void WriteArray(const ULong64_t *l, Int_t n) = 0;
245 virtual void WriteArray(const Float_t *f, Int_t n) = 0;
246 virtual void WriteArray(const Double_t *d, Int_t n) = 0;
247 virtual void WriteArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele = nullptr) = 0;
248 virtual void WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele = nullptr) = 0;
249
250 virtual void WriteFastArray(const Bool_t *b, Long64_t n) = 0;
251 virtual void WriteFastArray(const Char_t *c, Long64_t n) = 0;
252 virtual void WriteFastArrayString(const Char_t *c, Long64_t n) = 0;
253 virtual void WriteFastArray(const UChar_t *c, Long64_t n) = 0;
254 virtual void WriteFastArray(const Short_t *h, Long64_t n) = 0;
255 virtual void WriteFastArray(const UShort_t *h, Long64_t n) = 0;
256 virtual void WriteFastArray(const Int_t *i, Long64_t n) = 0;
257 virtual void WriteFastArray(const UInt_t *i, Long64_t n) = 0;
258 virtual void WriteFastArray(const Long_t *l, Long64_t n) = 0;
259 virtual void WriteFastArray(const ULong_t *l, Long64_t n) = 0;
260 virtual void WriteFastArray(const Long64_t *l, Long64_t n) = 0;
261 virtual void WriteFastArray(const ULong64_t *l, Long64_t n) = 0;
262 virtual void WriteFastArray(const Float_t *f, Long64_t n) = 0;
263 virtual void WriteFastArray(const Double_t *d, Long64_t n) = 0;
264 virtual void WriteFastArrayFloat16(const Float_t *f, Long64_t n, TStreamerElement *ele = nullptr) = 0;
265 virtual void WriteFastArrayDouble32(const Double_t *d, Long64_t n, TStreamerElement *ele = nullptr) = 0;
266 virtual void WriteFastArray(void *start, const TClass *cl, Long64_t n=1, TMemberStreamer *s = nullptr) = 0;
267 virtual Int_t WriteFastArray(void **startp, const TClass *cl, Long64_t n=1, Bool_t isPreAlloc = kFALSE, TMemberStreamer *s = nullptr) = 0;
268
269 virtual void StreamObject(void *obj, const std::type_info &typeinfo, const TClass* onFileClass = nullptr) = 0;
270 virtual void StreamObject(void *obj, const char *className, const TClass* onFileClass = nullptr) = 0;
271 virtual void StreamObject(void *obj, const TClass *cl, const TClass* onFileClass = nullptr) = 0;
272 virtual void StreamObject(TObject *obj) = 0;
273
274 virtual void ReadBool(Bool_t &b) = 0;
275 virtual void ReadChar(Char_t &c) = 0;
276 virtual void ReadUChar(UChar_t &c) = 0;
277 virtual void ReadShort(Short_t &s) = 0;
278 virtual void ReadUShort(UShort_t &s) = 0;
279 virtual void ReadInt(Int_t &i) = 0;
280 virtual void ReadUInt(UInt_t &i) = 0;
281 virtual void ReadLong(Long_t &l) = 0;
282 virtual void ReadULong(ULong_t &l) = 0;
283 virtual void ReadLong64(Long64_t &l) = 0;
284 virtual void ReadULong64(ULong64_t &l) = 0;
285 virtual void ReadFloat(Float_t &f) = 0;
286 virtual void ReadDouble(Double_t &d) = 0;
287 virtual void ReadCharP(Char_t *c) = 0;
288 virtual void ReadTString(TString &s) = 0;
289 virtual void ReadStdString(std::string *s) = 0;
290 virtual void ReadCharStar(char* &s) = 0;
291
292 virtual inline void ReadStdString(std::string &s) { ReadStdString(&s); }
293
294 virtual void WriteBool(Bool_t b) = 0;
295 virtual void WriteChar(Char_t c) = 0;
296 virtual void WriteUChar(UChar_t c) = 0;
297 virtual void WriteShort(Short_t s) = 0;
298 virtual void WriteUShort(UShort_t s) = 0;
299 virtual void WriteInt(Int_t i) = 0;
300 virtual void WriteUInt(UInt_t i) = 0;
301 virtual void WriteLong(Long_t l) = 0;
302 virtual void WriteULong(ULong_t l) = 0;
303 virtual void WriteLong64(Long64_t l) = 0;
304 virtual void WriteULong64(ULong64_t l) = 0;
305 virtual void WriteFloat(Float_t f) = 0;
306 virtual void WriteDouble(Double_t d) = 0;
307 virtual void WriteCharP(const Char_t *c) = 0;
308 virtual void WriteTString(const TString &s) = 0;
309 virtual void WriteStdString(const std::string *s) = 0;
310 virtual void WriteCharStar(char *s) = 0;
311
312 virtual inline void WriteStdString(std::string &s) { WriteStdString(&s); }
313
314 // Special basic ROOT objects and collections
315 virtual TProcessID *GetLastProcessID(TRefTable *reftable) const = 0;
316 virtual UInt_t GetTRefExecId() = 0;
317 virtual TProcessID *ReadProcessID(UShort_t pidf) = 0;
318 virtual UShort_t WriteProcessID(TProcessID *pid) = 0;
319
320 // Utilities for TStreamerInfo
321 virtual void ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force) = 0;
323 virtual Int_t ReadClones (TClonesArray *a, Int_t nobjects, Version_t objvers) = 0;
324 virtual Int_t WriteClones(TClonesArray *a, Int_t nobjects) = 0;
325
326 // Utilities for TClass
327 virtual Int_t ReadClassEmulated(const TClass *cl, void *object, const TClass *onfile_class = nullptr) = 0;
328 virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class = nullptr) = 0;
329 virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, Int_t version, UInt_t start, UInt_t count, const TClass *onfile_class = nullptr) = 0;
330 virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer) = 0;
331
332 // Utilites to streamer using sequences.
333 virtual Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *object) = 0;
334 virtual Int_t ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection) = 0;
335 virtual Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection) = 0;
336
337 static TClass *GetClass(const std::type_info &typeinfo);
338 static TClass *GetClass(const char *className);
339
340 ClassDefOverride(TBuffer,0) //Buffer base class used for serializing objects
341};
342
343//---------------------- TBuffer default external operators --------------------
344
345inline TBuffer &operator>>(TBuffer &buf, Bool_t &b) { buf.ReadBool(b); return buf; }
346inline TBuffer &operator>>(TBuffer &buf, Char_t &c) { buf.ReadChar(c); return buf; }
347inline TBuffer &operator>>(TBuffer &buf, UChar_t &c) { buf.ReadUChar(c); return buf; }
348inline TBuffer &operator>>(TBuffer &buf, Short_t &s) { buf.ReadShort(s); return buf; }
349inline TBuffer &operator>>(TBuffer &buf, UShort_t &s) { buf.ReadUShort(s); return buf; }
350inline TBuffer &operator>>(TBuffer &buf, Int_t &i) { buf.ReadInt(i); return buf; }
351inline TBuffer &operator>>(TBuffer &buf, UInt_t &i) { buf.ReadUInt(i); return buf; }
352inline TBuffer &operator>>(TBuffer &buf, Long_t &l) { buf.ReadLong(l); return buf; }
353inline TBuffer &operator>>(TBuffer &buf, ULong_t &l) { buf.ReadULong(l); return buf; }
354inline TBuffer &operator>>(TBuffer &buf, Long64_t &l) { buf.ReadLong64(l); return buf; }
355inline TBuffer &operator>>(TBuffer &buf, ULong64_t &l){ buf.ReadULong64(l);return buf; }
356inline TBuffer &operator>>(TBuffer &buf, Float_t &f) { buf.ReadFloat(f); return buf; }
357inline TBuffer &operator>>(TBuffer &buf, Double_t &d) { buf.ReadDouble(d); return buf; }
358inline TBuffer &operator>>(TBuffer &buf, Char_t *c) { buf.ReadCharP(c); return buf; }
359inline TBuffer &operator>>(TBuffer &buf, TString &s) { buf.ReadTString(s);return buf; }
360
361inline TBuffer &operator<<(TBuffer &buf, Bool_t b) { buf.WriteBool(b); return buf; }
362inline TBuffer &operator<<(TBuffer &buf, Char_t c) { buf.WriteChar(c); return buf; }
363inline TBuffer &operator<<(TBuffer &buf, UChar_t c) { buf.WriteUChar(c); return buf; }
364inline TBuffer &operator<<(TBuffer &buf, Short_t s) { buf.WriteShort(s); return buf; }
365inline TBuffer &operator<<(TBuffer &buf, UShort_t s) { buf.WriteUShort(s); return buf; }
366inline TBuffer &operator<<(TBuffer &buf, Int_t i) { buf.WriteInt(i); return buf; }
367inline TBuffer &operator<<(TBuffer &buf, UInt_t i) { buf.WriteUInt(i); return buf; }
368inline TBuffer &operator<<(TBuffer &buf, Long_t l) { buf.WriteLong(l); return buf; }
369inline TBuffer &operator<<(TBuffer &buf, ULong_t l) { buf.WriteULong(l); return buf; }
370inline TBuffer &operator<<(TBuffer &buf, Long64_t l) { buf.WriteLong64(l); return buf; }
371inline TBuffer &operator<<(TBuffer &buf, ULong64_t l){ buf.WriteULong64(l);return buf; }
372inline TBuffer &operator<<(TBuffer &buf, Float_t f) { buf.WriteFloat(f); return buf; }
373inline TBuffer &operator<<(TBuffer &buf, Double_t d) { buf.WriteDouble(d); return buf; }
374inline TBuffer &operator<<(TBuffer &buf, const Char_t *c) { buf.WriteCharP(c); return buf; }
375inline TBuffer &operator<<(TBuffer &buf, const TString &s) { buf.WriteTString(s);return buf; }
376
377#ifndef __CINT__
378
379#if defined(R__SOLARIS) && defined(R__GNU)
380#include <typeinfo>
381#endif
382
383template <class Tmpl> TBuffer &operator>>(TBuffer &buf, Tmpl *&obj)
384{
385 // Read TObject derived classes from a TBuffer. Need to provide
386 // custom version for non-TObject derived classes.
387
388 // This operator has to be a templated and/or automatically
389 // generated if we want to be able to check the type of the
390 // incoming object. I.e. a operator>>(TBuffer &buf, TObject *&)
391 // would not be sufficient to pass the information 'which class do we want'
392 // since the pointer could be zero (so typeid(*obj) is not usable).
393
394 auto cl = TClass::GetClass<Tmpl>();
395 obj = (Tmpl *) ( (void*) buf.ReadObjectAny(cl) );
396 return buf;
397}
398
399template <class Tmpl> TBuffer &operator<<(TBuffer &buf, const Tmpl *obj)
400{
401 auto cl = (obj) ? TClass::GetClass<Tmpl>() : nullptr;
402 buf.WriteObjectAny(obj, cl);
403 return buf;
404}
405#else
406template <class Tmpl> TBuffer &operator>>(TBuffer &buf, Tmpl *&obj);
407template <class Tmpl> TBuffer &operator<<(TBuffer &buf, Tmpl *&obj);
408#endif
409
410template <class T>
411inline Int_t TBuffer::WriteObject(const T *objptr, Bool_t cacheReuse)
412{
413 auto cl = (objptr) ? TClass::GetClass<T>() : nullptr;
414 return WriteObjectAny(objptr, cl, cacheReuse);
415}
416
417#endif // ROOT_TBuffer
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Definition RtypesCore.h:63
unsigned short UShort_t
Definition RtypesCore.h:40
int Int_t
Definition RtypesCore.h:45
short Version_t
Definition RtypesCore.h:65
unsigned char UChar_t
Definition RtypesCore.h:38
char Char_t
Definition RtypesCore.h:37
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
unsigned int UInt_t
Definition RtypesCore.h:46
float Float_t
Definition RtypesCore.h:57
short Short_t
Definition RtypesCore.h:39
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:80
unsigned long long ULong64_t
Definition RtypesCore.h:81
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define BIT(n)
Definition Rtypes.h:85
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
Definition TBuffer.h:399
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
TBuffer & operator>>(TBuffer &buf, Bool_t &b)
Definition TBuffer.h:345
EDataType
Definition TDataType.h:28
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
char *(* ReAllocCharFun_t)(char *, size_t, size_t)
Definition TStorage.h:30
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual void WriteCharStar(char *s)=0
virtual void WriteFastArray(const ULong_t *l, Long64_t n)=0
virtual Int_t ReadStaticArrayDouble32(Double_t *d, TStreamerElement *ele=nullptr)=0
virtual void WriteStdString(const std::string *s)=0
virtual void WriteClass(const TClass *cl)=0
virtual void ReadWithNbits(Float_t *ptr, Int_t nbits)=0
virtual void ReadWithFactor(Float_t *ptr, Double_t factor, Double_t minvalue)=0
TBuffer()
Definition TBuffer.h:59
virtual Int_t ReadStaticArray(UShort_t *h)=0
virtual void WriteFastArray(const UChar_t *c, Long64_t n)=0
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection)=0
virtual void WriteArray(const Short_t *h, Int_t n)=0
virtual void ForceWriteInfoClones(TClonesArray *a)=0
virtual void ReadWithFactor(Double_t *ptr, Double_t factor, Double_t minvalue)=0
virtual void WriteArray(const Float_t *f, Int_t n)=0
std::vector< TVirtualArray * > CacheList_t
Definition TBuffer.h:46
virtual Version_t ReadVersionForMemberWise(const TClass *cl=nullptr)=0
void SetWriteMode()
Set buffer in write mode.
Definition TBuffer.cxx:315
virtual void ReadFastArrayWithFactor(Double_t *ptr, Int_t n, Double_t factor, Double_t minvalue)=0
virtual void Reset()=0
virtual void WriteStdString(std::string &s)
Definition TBuffer.h:312
virtual void WriteDouble32(Double_t *d, TStreamerElement *ele=nullptr)=0
virtual void ReadDouble32(Double_t *d, TStreamerElement *ele=nullptr)=0
virtual void WriteString(const char *s)=0
Bool_t ByteSwapBuffer(Long64_t n, EDataType type)
Byte-swap N primitive-elements in the buffer.
Definition TBuffer.cxx:392
virtual void GetMappedObject(UInt_t tag, void *&ptr, TClass *&ClassPtr) const =0
virtual void WriteFastArrayString(const Char_t *c, Long64_t n)=0
virtual void ReadTString(TString &s)=0
virtual void ReadBool(Bool_t &b)=0
virtual UInt_t GetTRefExecId()=0
virtual void WriteULong(ULong_t l)=0
virtual void ReadFastArray(UShort_t *h, Int_t n)=0
virtual TVirtualStreamerInfo * GetInfo()=0
virtual void ClassBegin(const TClass *, Version_t=-1)=0
virtual void WriteArray(const UShort_t *h, Int_t n)=0
CacheList_t fCacheStack
Realloc function to be used when extending the buffer.
Definition TBuffer.h:56
virtual void ReadShort(Short_t &s)=0
virtual TProcessID * ReadProcessID(UShort_t pidf)=0
Return the current Process-ID.
Definition TBuffer.cxx:344
virtual Int_t ReadStaticArray(Int_t *i)=0
virtual UInt_t WriteVersionMemberWise(const TClass *cl, Bool_t useBcnt=kFALSE)=0
virtual Int_t ReadStaticArray(UInt_t *i)=0
virtual UShort_t WriteProcessID(TProcessID *pid)=0
Always return 0 (current processID).
Definition TBuffer.cxx:353
virtual Int_t ReadArray(Int_t *&i)=0
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
virtual void ReadInt(Int_t &i)=0
virtual TObject * ReadObject(const TClass *cl)=0
virtual void StreamObject(TObject *obj)=0
virtual void ReadDouble(Double_t &d)=0
virtual void ReadFastArray(ULong64_t *l, Int_t n)=0
Int_t fBufSize
Definition TBuffer.h:50
virtual Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection)=0
virtual void SkipObjectAny()=0
virtual void ReadFastArray(Long_t *l, Int_t n)=0
virtual void ReadFastArray(void **startp, const TClass *cl, Int_t n=1, Bool_t isPreAlloc=kFALSE, TMemberStreamer *s=nullptr, const TClass *onFileClass=nullptr)=0
virtual void WriteArray(const Double_t *d, Int_t n)=0
virtual void WriteDouble(Double_t d)=0
void SetParent(TObject *parent)
Set parent owning this buffer.
Definition TBuffer.cxx:270
virtual Version_t ReadVersionNoCheckSum(UInt_t *start=nullptr, UInt_t *bcnt=nullptr)=0
virtual Int_t ReadArray(Float_t *&f)=0
virtual void WriteUChar(UChar_t c)=0
virtual void ReadLong64(Long64_t &l)=0
TObject * GetParent() const
Return pointer to parent of this buffer.
Definition TBuffer.cxx:262
virtual Int_t ReadArray(Short_t *&h)=0
virtual TClass * ReadClass(const TClass *cl=nullptr, UInt_t *objTag=nullptr)=0
virtual void WriteLong(Long_t l)=0
virtual Int_t ReadStaticArray(Char_t *c)=0
char * GetCurrent() const
Definition TBuffer.h:97
virtual Int_t ReadClones(TClonesArray *a, Int_t nobjects, Version_t objvers)=0
void Expand(Int_t newsize, Bool_t copy=kTRUE)
Expand (or shrink) the I/O buffer to newsize bytes.
Definition TBuffer.cxx:223
virtual Int_t ReadArray(UChar_t *&c)=0
virtual void SetBufferDisplacement(Int_t skipped)=0
virtual void WriteUInt(UInt_t i)=0
virtual Int_t GetBufferDisplacement() const =0
virtual void ReadFastArray(Double_t *d, Int_t n)=0
virtual void ReadFastArrayString(Char_t *c, Int_t n)=0
virtual void WriteFloat16(Float_t *f, TStreamerElement *ele=nullptr)=0
virtual void * ReadObjectAny(const TClass *cast)=0
virtual void ReadFloat(Float_t &f)=0
virtual void WriteArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele=nullptr)=0
virtual UShort_t GetPidOffset() const =0
virtual void ReadFastArray(Long64_t *l, Int_t n)=0
virtual void ReadChar(Char_t &c)=0
virtual void SetReadParam(Int_t mapsize)=0
virtual Int_t ReadArrayFloat16(Float_t *&f, TStreamerElement *ele=nullptr)=0
Int_t Write(const char *name, Int_t opt, Int_t bufs) override
Write this object to the current directory.
Definition TBuffer.h:67
virtual void WriteArray(const ULong64_t *l, Int_t n)=0
virtual Int_t ReadStaticArray(Long_t *l)=0
virtual void WriteFastArray(const Double_t *d, Long64_t n)=0
virtual Int_t ReadStaticArray(Float_t *f)=0
virtual void ReadFastArray(Int_t *i, Int_t n)=0
virtual Int_t ReadArray(Double_t *&d)=0
Int_t BufferSize() const
Definition TBuffer.h:98
virtual void ReadFastArray(UChar_t *c, Int_t n)=0
EStatusBits
Definition TBuffer.h:74
@ kCannotHandleMemberWiseStreaming
Definition TBuffer.h:76
@ kIsOwner
Definition TBuffer.h:75
virtual void WriteFastArray(const Short_t *h, Long64_t n)=0
virtual Int_t WriteClones(TClonesArray *a, Int_t nobjects)=0
virtual Int_t WriteObjectAny(const void *obj, const TClass *ptrClass, Bool_t cacheReuse=kTRUE)=0
void SetBuffer(void *buf, UInt_t bufsiz=0, Bool_t adopt=kTRUE, ReAllocCharFun_t reallocfunc=nullptr)
Sets a new buffer in an existing TBuffer object.
Definition TBuffer.cxx:187
virtual void SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type)=0
virtual void ReadFastArray(Float_t *f, Int_t n)=0
virtual void WriteShort(Short_t s)=0
virtual void WriteFastArray(const ULong64_t *l, Long64_t n)=0
virtual void PushDataCache(TVirtualArray *)
Push a new data cache area onto the list of area to be used for temporarily store 'missing' data memb...
Definition TBuffer.cxx:362
virtual void ReadCharP(Char_t *c)=0
virtual void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele=nullptr)=0
void SetReAllocFunc(ReAllocCharFun_t reallocfunc=nullptr)
Set which memory reallocation method to use.
Definition TBuffer.cxx:286
virtual void WriteArray(const Bool_t *b, Int_t n)=0
virtual TVirtualArray * PopDataCache()
Pop and Return the 'current' data cache area from the list of area to be used for temporarily store '...
Definition TBuffer.cxx:381
virtual Int_t ReadArray(Bool_t *&b)=0
@ kWrite
Definition TBuffer.h:73
@ kRead
Definition TBuffer.h:73
char * fBufMax
Definition TBuffer.h:53
virtual void ReadStdString(std::string &s)
Definition TBuffer.h:292
char * fBufCur
Definition TBuffer.h:52
virtual Int_t ReadStaticArray(Short_t *h)=0
virtual void ClassEnd(const TClass *)=0
virtual void WriteLong64(Long64_t l)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
void AutoExpand(Int_t size_needed)
Automatically calculate a new size and expand the buffer to fit at least size_needed.
Definition TBuffer.cxx:158
Bool_t IsWriting() const
Definition TBuffer.h:87
virtual void WriteChar(Char_t c)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const char *classname)=0
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual TVirtualArray * PeekDataCache() const
Return the 'current' data cache area from the list of area to be used for temporarily store 'missing'...
Definition TBuffer.cxx:371
virtual Int_t ReadStaticArray(ULong64_t *l)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
virtual void WriteBool(Bool_t b)=0
virtual void ReadFastArray(Short_t *h, Int_t n)=0
virtual Int_t ReadArray(Long_t *&l)=0
virtual void WriteArray(const Long_t *l, Int_t n)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, Int_t version, UInt_t start, UInt_t count, const TClass *onfile_class=nullptr)=0
@ kMinimalSize
Definition TBuffer.h:78
@ kInitialSize
Definition TBuffer.h:78
virtual void WriteUShort(UShort_t s)=0
virtual void WriteArray(const Char_t *c, Int_t n)=0
virtual void WriteULong64(ULong64_t l)=0
Int_t Read(const char *name) override
Read contents of object with specified name from the current directory.
Definition TBuffer.h:66
virtual void WriteArray(const Int_t *i, Int_t n)=0
virtual void WriteFastArray(const UInt_t *i, Long64_t n)=0
virtual Int_t ReadStaticArrayFloat16(Float_t *f, TStreamerElement *ele=nullptr)=0
virtual void WriteFastArray(const Long_t *l, Long64_t n)=0
virtual Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *object)=0
virtual void WriteFastArray(const Int_t *i, Long64_t n)=0
virtual void IncrementLevel(TVirtualStreamerInfo *info)=0
virtual void MapObject(const void *obj, const TClass *cl, UInt_t offset=1)=0
virtual void SetWriteParam(Int_t mapsize)=0
virtual void ClassMember(const char *, const char *=nullptr, Int_t=-1, Int_t=-1)=0
virtual void ReadULong64(ULong64_t &l)=0
virtual void ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits)=0
virtual void StreamObject(void *obj, const char *className, const TClass *onFileClass=nullptr)=0
virtual void ReadFastArray(UInt_t *i, Int_t n)=0
virtual Int_t GetVersionOwner() const =0
virtual Int_t ReadStaticArray(UChar_t *c)=0
virtual Int_t WriteFastArray(void **startp, const TClass *cl, Long64_t n=1, Bool_t isPreAlloc=kFALSE, TMemberStreamer *s=nullptr)=0
virtual ~TBuffer()
Delete an I/O buffer object.
Definition TBuffer.cxx:140
virtual void ReadULong(ULong_t &l)=0
virtual void ReadLong(Long_t &l)=0
virtual void DecrementLevel(TVirtualStreamerInfo *)=0
static TClass * GetClass(const std::type_info &typeinfo)
Forward to TROOT::GetClass().
Definition TBuffer.cxx:328
virtual Int_t ReadStaticArray(Double_t *d)=0
virtual void WriteFastArray(const Float_t *f, Long64_t n)=0
virtual Int_t ReadArray(UShort_t *&h)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual Int_t ReadArrayDouble32(Double_t *&d, TStreamerElement *ele=nullptr)=0
virtual Int_t ReadArray(UInt_t *&i)=0
virtual void WriteFastArray(const UShort_t *h, Long64_t n)=0
virtual void WriteArray(const Long64_t *l, Int_t n)=0
Bool_t fMode
Definition TBuffer.h:48
virtual void ResetMap()=0
void SetBufferOffset(Int_t offset=0)
Definition TBuffer.h:93
virtual void ReadFloat16(Float_t *f, TStreamerElement *ele=nullptr)=0
void operator=(const TBuffer &)=delete
virtual void SetPidOffset(UShort_t offset)=0
TBuffer(const TBuffer &)=delete
virtual void InitMap()=0
ReAllocCharFun_t GetReAllocFunc() const
Return the reallocation method currently used.
Definition TBuffer.cxx:277
ReAllocCharFun_t fReAllocFunc
Definition TBuffer.h:55
char * fBuffer
Definition TBuffer.h:51
TObject * fParent
Definition TBuffer.h:54
virtual Int_t ReadStaticArray(Bool_t *b)=0
virtual void WriteObject(const TObject *obj, Bool_t cacheReuse)=0
virtual void WriteFastArrayFloat16(const Float_t *f, Long64_t n, TStreamerElement *ele=nullptr)=0
virtual void WriteFastArray(const Bool_t *b, Long64_t n)=0
virtual void ReadFastArrayWithNbits(Double_t *ptr, Int_t n, Int_t nbits)=0
virtual Int_t ReadArray(Long64_t *&l)=0
virtual Int_t ReadStaticArray(Long64_t *l)=0
virtual void StreamObject(void *obj, const TClass *cl, const TClass *onFileClass=nullptr)=0
virtual void WriteFastArray(const Char_t *c, Long64_t n)=0
virtual Int_t GetMapCount() const =0
void SetReadMode()
Set buffer in read mode.
Definition TBuffer.cxx:302
virtual TProcessID * GetLastProcessID(TRefTable *reftable) const =0
virtual void ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue)=0
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
Int_t GetBufferVersion() const
Definition TBuffer.h:85
virtual void ReadUChar(UChar_t &c)=0
virtual Int_t ReadArray(ULong64_t *&l)=0
virtual void WriteInt(Int_t i)=0
void DetachBuffer()
Definition TBuffer.h:99
virtual void ReadUInt(UInt_t &i)=0
virtual void ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force)=0
virtual void ReadFastArray(Char_t *c, Int_t n)=0
virtual Bool_t CheckObject(const void *obj, const TClass *ptrClass)=0
virtual void WriteBuf(const void *buf, Int_t max)=0
virtual void ReadStdString(std::string *s)=0
virtual void WriteCharP(const Char_t *c)=0
virtual Int_t ReadStaticArray(ULong_t *l)=0
virtual void SetBufferDisplacement()=0
virtual void WriteFastArrayDouble32(const Double_t *d, Long64_t n, TStreamerElement *ele=nullptr)=0
virtual Bool_t CheckObject(const TObject *obj)=0
virtual void ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele=nullptr)=0
virtual void WriteFastArray(void *start, const TClass *cl, Long64_t n=1, TMemberStreamer *s=nullptr)=0
virtual Int_t ReadArray(ULong_t *&l)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void ReadWithNbits(Double_t *ptr, Int_t nbits)=0
virtual void ReadFastArray(void *start, const TClass *cl, Int_t n=1, TMemberStreamer *s=nullptr, const TClass *onFileClass=nullptr)=0
virtual void ReadCharStar(char *&s)=0
virtual void WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=nullptr)=0
virtual char * ReadString(char *s, Int_t max)=0
virtual void ReadUShort(UShort_t &s)=0
virtual void WriteArray(const UChar_t *c, Int_t n)=0
Int_t fVersion
Definition TBuffer.h:49
virtual void WriteFloat(Float_t f)=0
virtual void TagStreamerInfo(TVirtualStreamerInfo *info)=0
virtual void ReadFastArray(ULong_t *l, Int_t n)=0
virtual void WriteArray(const UInt_t *i, Int_t n)=0
Int_t Write(const char *name, Int_t opt, Int_t bufs) const override
Write this object to the current directory.
Definition TBuffer.h:69
virtual void WriteFastArray(const Long64_t *l, Long64_t n)=0
Int_t Length() const
Definition TBuffer.h:100
virtual void SkipVersion(const TClass *cl=nullptr)=0
virtual void WriteTString(const TString &s)=0
virtual Int_t ReadBuf(void *buf, Int_t max)=0
virtual void MapObject(const TObject *obj, UInt_t offset=1)=0
virtual void WriteArray(const ULong_t *l, Int_t n)=0
virtual Int_t ReadClassEmulated(const TClass *cl, void *object, const TClass *onfile_class=nullptr)=0
char * Buffer() const
Definition TBuffer.h:96
virtual Int_t ReadArray(Char_t *&c)=0
virtual void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass=nullptr)=0
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
An array of clone (identical) objects.
Mother of all ROOT objects.
Definition TObject.h:41
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition TObject.cxx:880
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
Definition TObject.cxx:648
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition TProcessID.h:74
A TRefTable maintains the association between a referenced object and the parent object supporting th...
Definition TRefTable.h:35
Basic string class.
Definition TString.h:139
Wrapper around an object and giving indirect access to its content even if the object is not of a cla...
Abstract Interface class describing Streamer information for one class.
const Int_t n
Definition legend1.C:16
TLine l
Definition textangle.C:4