Logo ROOT  
Reference Guide
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 
33 class TStreamerElement;
34 class TString;
35 class TProcessID;
36 class TClonesArray;
37 class TRefTable;
38 class TVirtualArray;
40  class TActionSequence;
41 }
42 
43 class TBuffer : public TObject {
44 
45 protected:
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(0),
61 
62  // TBuffer objects cannot be copied or assigned
63  TBuffer(const TBuffer &); // not implemented
64  void operator=(const TBuffer &); // not implemented
65 
66  Int_t Read(const char *name) { return TObject::Read(name); }
67  Int_t Write(const char *name, Int_t opt, Int_t bufs)
68  { return TObject::Write(name, opt, bufs); }
69  Int_t Write(const char *name, Int_t opt, Int_t bufs) const
70  { return TObject::Write(name, opt, bufs); }
71 
72 public:
73  enum EMode { kRead = 0, kWrite = 1 };
74  enum EStatusBits {
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 
80  TBuffer(EMode mode);
81  TBuffer(EMode mode, Int_t bufsiz);
82  TBuffer(EMode mode, Int_t bufsiz, void *buf, Bool_t adopt = kTRUE, ReAllocCharFun_t reallocfunc = 0);
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 = 0);
92  void SetReAllocFunc(ReAllocCharFun_t reallocfunc = 0);
93  void SetBufferOffset(Int_t offset = 0) { fBufCur = fBuffer+offset; }
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 = 0; }
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 = 0) = 0;
130  virtual Version_t ReadVersion(UInt_t *start = 0, UInt_t *bcnt = 0, const TClass *cl = 0) = 0;
131  virtual Version_t ReadVersionNoCheckSum(UInt_t *start = 0, UInt_t *bcnt = 0) = 0;
132  virtual Version_t ReadVersionForMemberWise(const TClass *cl = 0) = 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;
142  virtual void DecrementLevel(TVirtualStreamerInfo*) = 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* = 0, Int_t = -1, Int_t = -1) = 0;
147  virtual TVirtualStreamerInfo *GetInfo() = 0;
148 
149  virtual TVirtualArray *PeekDataCache() const;
150  virtual TVirtualArray *PopDataCache();
151  virtual void PushDataCache(TVirtualArray *);
152 
153  virtual TClass *ReadClass(const TClass *cl = 0, UInt_t *objTag = 0) = 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=0) = 0;
171  virtual void WriteFloat16(Float_t *f, TStreamerElement *ele=0) = 0;
172  virtual void ReadDouble32 (Double_t *d, TStreamerElement *ele=0) = 0;
173  virtual void WriteDouble32(Double_t *d, TStreamerElement *ele=0) = 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=0) = 0;
193  virtual Int_t ReadArrayDouble32(Double_t *&d, TStreamerElement *ele=0) = 0;
194 
195  virtual Int_t ReadStaticArray(Bool_t *b) = 0;
196  virtual Int_t ReadStaticArray(Char_t *c) = 0;
197  virtual Int_t ReadStaticArray(UChar_t *c) = 0;
198  virtual Int_t ReadStaticArray(Short_t *h) = 0;
199  virtual Int_t ReadStaticArray(UShort_t *h) = 0;
200  virtual Int_t ReadStaticArray(Int_t *i) = 0;
201  virtual Int_t ReadStaticArray(UInt_t *i) = 0;
202  virtual Int_t ReadStaticArray(Long_t *l) = 0;
203  virtual Int_t ReadStaticArray(ULong_t *l) = 0;
204  virtual Int_t ReadStaticArray(Long64_t *l) = 0;
205  virtual Int_t ReadStaticArray(ULong64_t *l) = 0;
206  virtual Int_t ReadStaticArray(Float_t *f) = 0;
207  virtual Int_t ReadStaticArray(Double_t *d) = 0;
208  virtual Int_t ReadStaticArrayFloat16(Float_t *f, TStreamerElement *ele=0) = 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=0) = 0;
226  virtual void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele=0) = 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=0, const TClass *onFileClass=0) = 0;
232  virtual void ReadFastArray(void **startp, const TClass *cl, Int_t n=1, Bool_t isPreAlloc=kFALSE, TMemberStreamer *s=0, const TClass *onFileClass=0) = 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=0) = 0;
248  virtual void WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=0) = 0;
249 
250  virtual void WriteFastArray(const Bool_t *b, Int_t n) = 0;
251  virtual void WriteFastArray(const Char_t *c, Int_t n) = 0;
252  virtual void WriteFastArrayString(const Char_t *c, Int_t n) = 0;
253  virtual void WriteFastArray(const UChar_t *c, Int_t n) = 0;
254  virtual void WriteFastArray(const Short_t *h, Int_t n) = 0;
255  virtual void WriteFastArray(const UShort_t *h, Int_t n) = 0;
256  virtual void WriteFastArray(const Int_t *i, Int_t n) = 0;
257  virtual void WriteFastArray(const UInt_t *i, Int_t n) = 0;
258  virtual void WriteFastArray(const Long_t *l, Int_t n) = 0;
259  virtual void WriteFastArray(const ULong_t *l, Int_t n) = 0;
260  virtual void WriteFastArray(const Long64_t *l, Int_t n) = 0;
261  virtual void WriteFastArray(const ULong64_t *l, Int_t n) = 0;
262  virtual void WriteFastArray(const Float_t *f, Int_t n) = 0;
263  virtual void WriteFastArray(const Double_t *d, Int_t n) = 0;
264  virtual void WriteFastArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele=0) = 0;
265  virtual void WriteFastArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=0) = 0;
266  virtual void WriteFastArray(void *start, const TClass *cl, Int_t n=1, TMemberStreamer *s=0) = 0;
267  virtual Int_t WriteFastArray(void **startp, const TClass *cl, Int_t n=1, Bool_t isPreAlloc=kFALSE, TMemberStreamer *s=0) = 0;
268 
269  virtual void StreamObject(void *obj, const std::type_info &typeinfo, const TClass* onFileClass = 0 ) = 0;
270  virtual void StreamObject(void *obj, const char *className, const TClass* onFileClass = 0 ) = 0;
271  virtual void StreamObject(void *obj, const TClass *cl, const TClass* onFileClass = 0 ) = 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;
322  virtual void ForceWriteInfoClones(TClonesArray *a) = 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 = 0) = 0;
328  virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class = 0) = 0;
329  virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, Int_t version, UInt_t start, UInt_t count, const TClass *onfile_class = 0) = 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  ClassDef(TBuffer,0) //Buffer base class used for serializing objects
341 };
342 
343 //---------------------- TBuffer default external operators --------------------
344 
345 inline TBuffer &operator>>(TBuffer &buf, Bool_t &b) { buf.ReadBool(b); return buf; }
346 inline TBuffer &operator>>(TBuffer &buf, Char_t &c) { buf.ReadChar(c); return buf; }
347 inline TBuffer &operator>>(TBuffer &buf, UChar_t &c) { buf.ReadUChar(c); return buf; }
348 inline TBuffer &operator>>(TBuffer &buf, Short_t &s) { buf.ReadShort(s); return buf; }
349 inline TBuffer &operator>>(TBuffer &buf, UShort_t &s) { buf.ReadUShort(s); return buf; }
350 inline TBuffer &operator>>(TBuffer &buf, Int_t &i) { buf.ReadInt(i); return buf; }
351 inline TBuffer &operator>>(TBuffer &buf, UInt_t &i) { buf.ReadUInt(i); return buf; }
352 inline TBuffer &operator>>(TBuffer &buf, Long_t &l) { buf.ReadLong(l); return buf; }
353 inline TBuffer &operator>>(TBuffer &buf, ULong_t &l) { buf.ReadULong(l); return buf; }
354 inline TBuffer &operator>>(TBuffer &buf, Long64_t &l) { buf.ReadLong64(l); return buf; }
355 inline TBuffer &operator>>(TBuffer &buf, ULong64_t &l){ buf.ReadULong64(l);return buf; }
356 inline TBuffer &operator>>(TBuffer &buf, Float_t &f) { buf.ReadFloat(f); return buf; }
357 inline TBuffer &operator>>(TBuffer &buf, Double_t &d) { buf.ReadDouble(d); return buf; }
358 inline TBuffer &operator>>(TBuffer &buf, Char_t *c) { buf.ReadCharP(c); return buf; }
359 inline TBuffer &operator>>(TBuffer &buf, TString &s) { buf.ReadTString(s);return buf; }
360 
361 inline TBuffer &operator<<(TBuffer &buf, Bool_t b) { buf.WriteBool(b); return buf; }
362 inline TBuffer &operator<<(TBuffer &buf, Char_t c) { buf.WriteChar(c); return buf; }
363 inline TBuffer &operator<<(TBuffer &buf, UChar_t c) { buf.WriteUChar(c); return buf; }
364 inline TBuffer &operator<<(TBuffer &buf, Short_t s) { buf.WriteShort(s); return buf; }
365 inline TBuffer &operator<<(TBuffer &buf, UShort_t s) { buf.WriteUShort(s); return buf; }
366 inline TBuffer &operator<<(TBuffer &buf, Int_t i) { buf.WriteInt(i); return buf; }
367 inline TBuffer &operator<<(TBuffer &buf, UInt_t i) { buf.WriteUInt(i); return buf; }
368 inline TBuffer &operator<<(TBuffer &buf, Long_t l) { buf.WriteLong(l); return buf; }
369 inline TBuffer &operator<<(TBuffer &buf, ULong_t l) { buf.WriteULong(l); return buf; }
370 inline TBuffer &operator<<(TBuffer &buf, Long64_t l) { buf.WriteLong64(l); return buf; }
371 inline TBuffer &operator<<(TBuffer &buf, ULong64_t l){ buf.WriteULong64(l);return buf; }
372 inline TBuffer &operator<<(TBuffer &buf, Float_t f) { buf.WriteFloat(f); return buf; }
373 inline TBuffer &operator<<(TBuffer &buf, Double_t d) { buf.WriteDouble(d); return buf; }
374 inline TBuffer &operator<<(TBuffer &buf, const Char_t *c) { buf.WriteCharP(c); return buf; }
375 inline 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 
383 template <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 
399 template <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
406 template <class Tmpl> TBuffer &operator>>(TBuffer &buf, Tmpl *&obj);
407 template <class Tmpl> TBuffer &operator<<(TBuffer &buf, Tmpl *&obj);
408 #endif
409 
410 template <class T>
411 inline 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
TBuffer::ReadVersionNoCheckSum
virtual Version_t ReadVersionNoCheckSum(UInt_t *start=0, UInt_t *bcnt=0)=0
TBuffer::ReadStaticArrayFloat16
virtual Int_t ReadStaticArrayFloat16(Float_t *f, TStreamerElement *ele=0)=0
c
#define c(i)
Definition: RSha256.hxx:119
TBuffer::GetMapCount
virtual Int_t GetMapCount() const =0
l
auto * l
Definition: textangle.C:4
TBuffer::fParent
TObject * fParent
Definition: TBuffer.h:54
TBuffer::ReadString
virtual char * ReadString(char *s, Int_t max)=0
TBuffer::ClassMember
virtual void ClassMember(const char *, const char *=0, Int_t=-1, Int_t=-1)=0
TBuffer::ReadClones
virtual Int_t ReadClones(TClonesArray *a, Int_t nobjects, Version_t objvers)=0
n
const Int_t n
Definition: legend1.C:16
TBuffer::PopDataCache
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
TBuffer::WriteUShort
virtual void WriteUShort(UShort_t s)=0
TBuffer::ReadUShort
virtual void ReadUShort(UShort_t &s)=0
TBuffer::ReadFastArrayDouble32
virtual void ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement *ele=0)=0
TBuffer::WriteInt
virtual void WriteInt(Int_t i)=0
TBuffer::ReadULong64
virtual void ReadULong64(ULong64_t &l)=0
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
Version_t
short Version_t
Definition: RtypesCore.h:65
TBuffer::ReadLong
virtual void ReadLong(Long_t &l)=0
TBuffer::ReadStdString
virtual void ReadStdString(std::string *s)=0
TBuffer::PushDataCache
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
TBuffer::ReadFastArrayFloat16
virtual void ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement *ele=0)=0
TBuffer::WriteShort
virtual void WriteShort(Short_t s)=0
TBuffer::ReadDouble
virtual void ReadDouble(Double_t &d)=0
f
#define f(i)
Definition: RSha256.hxx:122
TBuffer::ReadUInt
virtual void ReadUInt(UInt_t &i)=0
TBuffer::BufferSize
Int_t BufferSize() const
Definition: TBuffer.h:98
TBuffer::kRead
@ kRead
Definition: TBuffer.h:73
TBuffer::SetBuffer
void SetBuffer(void *buf, UInt_t bufsiz=0, Bool_t adopt=kTRUE, ReAllocCharFun_t reallocfunc=0)
Sets a new buffer in an existing TBuffer object.
Definition: TBuffer.cxx:187
TBuffer::GetPidOffset
virtual UShort_t GetPidOffset() const =0
TBuffer::WriteVersion
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
TBuffer::WriteFloat
virtual void WriteFloat(Float_t f)=0
TBuffer::WriteArrayFloat16
virtual void WriteArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele=0)=0
TBuffer::fBufCur
char * fBufCur
Definition: TBuffer.h:52
TBuffer::SetByteCount
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
UShort_t
unsigned short UShort_t
Definition: RtypesCore.h:40
TBuffer::TBuffer
TBuffer()
Definition: TBuffer.h:59
TBuffer::ForceWriteInfoClones
virtual void ForceWriteInfoClones(TClonesArray *a)=0
TBuffer::ReadUChar
virtual void ReadUChar(UChar_t &c)=0
TBuffer::TagStreamerInfo
virtual void TagStreamerInfo(TVirtualStreamerInfo *info)=0
TBuffer::ReadStaticArray
virtual Int_t ReadStaticArray(Bool_t *b)=0
TBuffer::Expand
void Expand(Int_t newsize, Bool_t copy=kTRUE)
Expand (or shrink) the I/O buffer to newsize bytes.
Definition: TBuffer.cxx:223
TBuffer::ReadFastArray
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
TBuffer::WriteUChar
virtual void WriteUChar(UChar_t c)=0
TBuffer::ReadFastArrayString
virtual void ReadFastArrayString(Char_t *c, Int_t n)=0
TBuffer::ReadClassBuffer
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
TBuffer::WriteULong
virtual void WriteULong(ULong_t l)=0
TBuffer::ReadVersionForMemberWise
virtual Version_t ReadVersionForMemberWise(const TClass *cl=0)=0
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TBuffer::MapObject
virtual void MapObject(const TObject *obj, UInt_t offset=1)=0
TBuffer::ReadBool
virtual void ReadBool(Bool_t &b)=0
TBuffer::ReadWithNbits
virtual void ReadWithNbits(Float_t *ptr, Int_t nbits)=0
TBuffer::CheckObject
virtual Bool_t CheckObject(const TObject *obj)=0
TBuffer::WriteUInt
virtual void WriteUInt(UInt_t i)=0
TBuffer::fBuffer
char * fBuffer
Definition: TBuffer.h:51
TBuffer::fVersion
Int_t fVersion
Definition: TBuffer.h:49
TBuffer::WriteFastArrayString
virtual void WriteFastArrayString(const Char_t *c, Int_t n)=0
Float_t
float Float_t
Definition: RtypesCore.h:57
TBuffer::WriteObject
virtual void WriteObject(const TObject *obj, Bool_t cacheReuse)=0
TBuffer::kCannotHandleMemberWiseStreaming
@ kCannotHandleMemberWiseStreaming
Definition: TBuffer.h:76
TProcessID
Definition: TProcessID.h:74
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
TBuffer::GetVersionOwner
virtual Int_t GetVersionOwner() const =0
TBuffer::ApplySequence
virtual Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *object)=0
Int_t
int Int_t
Definition: RtypesCore.h:45
TBuffer::ReadFloat
virtual void ReadFloat(Float_t &f)=0
TBuffer::WriteStdString
virtual void WriteStdString(const std::string *s)=0
TBuffer::ReadFastArrayWithFactor
virtual void ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue)=0
TBuffer::EStatusBits
EStatusBits
Definition: TBuffer.h:74
TBuffer::Buffer
char * Buffer() const
Definition: TBuffer.h:96
TBuffer::ReadTString
virtual void ReadTString(TString &s)=0
TClass.h
TBuffer::fBufMax
char * fBufMax
Definition: TBuffer.h:53
ReAllocCharFun_t
char *(* ReAllocCharFun_t)(char *, size_t, size_t)
Definition: TStorage.h:30
TVirtualArray
Definition: TVirtualArray.h:26
TBuffer::ReadArray
virtual Int_t ReadArray(Bool_t *&b)=0
TBuffer
Definition: TBuffer.h:43
TBuffer::CheckByteCount
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
TString
Definition: TString.h:136
TBuffer::GetBufferVersion
Int_t GetBufferVersion() const
Definition: TBuffer.h:85
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TBuffer::SetBufferOffset
void SetBufferOffset(Int_t offset=0)
Definition: TBuffer.h:93
b
#define b(i)
Definition: RSha256.hxx:118
TBuffer::StreamObject
virtual void StreamObject(void *obj, const std::type_info &typeinfo, const TClass *onFileClass=0)=0
TBuffer::Write
Int_t Write(const char *name, Int_t opt, Int_t bufs)
Write this object to the current directory.
Definition: TBuffer.h:67
TBuffer::ReadBuf
virtual Int_t ReadBuf(void *buf, Int_t max)=0
TBuffer::DecrementLevel
virtual void DecrementLevel(TVirtualStreamerInfo *)=0
TVirtualStreamerInfo
Definition: TVirtualStreamerInfo.h:37
bool
TBuffer::ApplySequenceVecPtr
virtual Int_t ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection)=0
TBuffer::ReadFastArrayWithNbits
virtual void ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits)=0
TBuffer::ReadClassEmulated
virtual Int_t ReadClassEmulated(const TClass *cl, void *object, const TClass *onfile_class=0)=0
TBuffer::ReadULong
virtual void ReadULong(ULong_t &l)=0
TBuffer::ResetMap
virtual void ResetMap()=0
TBuffer::GetCurrent
char * GetCurrent() const
Definition: TBuffer.h:97
TBuffer::Length
Int_t Length() const
Definition: TBuffer.h:100
TDataType.h
TBuffer::GetBufferDisplacement
virtual Int_t GetBufferDisplacement() const =0
TBuffer::GetTRefExecId
virtual UInt_t GetTRefExecId()=0
TBuffer::WriteDouble32
virtual void WriteDouble32(Double_t *d, TStreamerElement *ele=0)=0
TBuffer::SetReadMode
void SetReadMode()
Set buffer in read mode.
Definition: TBuffer.cxx:302
TBuffer::fReAllocFunc
ReAllocCharFun_t fReAllocFunc
Definition: TBuffer.h:55
TBuffer::ReadStdString
virtual void ReadStdString(std::string &s)
Definition: TBuffer.h:292
TBuffer::WriteString
virtual void WriteString(const char *s)=0
TBuffer::EMode
EMode
Definition: TBuffer.h:73
TBuffer::SetStreamerElementNumber
virtual void SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type)=0
h
#define h(i)
Definition: RSha256.hxx:124
TBuffer::WriteFastArray
virtual void WriteFastArray(const Bool_t *b, Int_t n)=0
TBuffer::InitMap
virtual void InitMap()=0
TBuffer::WriteVersionMemberWise
virtual UInt_t WriteVersionMemberWise(const TClass *cl, Bool_t useBcnt=kFALSE)=0
TStreamerInfoActions
Definition: TBuffer.h:39
operator<<
TBuffer & operator<<(TBuffer &buf, Bool_t b)
Definition: TBuffer.h:361
TBuffer::IsWriting
Bool_t IsWriting() const
Definition: TBuffer.h:87
a
auto * a
Definition: textangle.C:12
TBuffer::WriteFastArrayFloat16
virtual void WriteFastArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele=0)=0
TBuffer::ClassBegin
virtual void ClassBegin(const TClass *, Version_t=-1)=0
TBuffer::WriteClassBuffer
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
TBuffer::ForceWriteInfo
virtual void ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force)=0
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TBuffer::SetPidOffset
virtual void SetPidOffset(UShort_t offset)=0
TBuffer::WriteBuf
virtual void WriteBuf(const void *buf, Int_t max)=0
TBuffer::ReadStaticArrayDouble32
virtual Int_t ReadStaticArrayDouble32(Double_t *d, TStreamerElement *ele=0)=0
Long_t
long Long_t
Definition: RtypesCore.h:54
TBuffer::kMinimalSize
@ kMinimalSize
Definition: TBuffer.h:78
TBuffer::GetLastProcessID
virtual TProcessID * GetLastProcessID(TRefTable *reftable) const =0
TBuffer::SetReAllocFunc
void SetReAllocFunc(ReAllocCharFun_t reallocfunc=0)
Set which memory reallocation method to use.
Definition: TBuffer.cxx:286
TBuffer::kIsOwner
@ kIsOwner
Definition: TBuffer.h:75
TBuffer::GetMappedObject
virtual void GetMappedObject(UInt_t tag, void *&ptr, TClass *&ClassPtr) const =0
TBuffer::GetInfo
virtual TVirtualStreamerInfo * GetInfo()=0
operator>>
TBuffer & operator>>(TBuffer &buf, Bool_t &b)
Definition: TBuffer.h:345
BIT
#define BIT(n)
Definition: Rtypes.h:85
TBuffer::SetBufferDisplacement
virtual void SetBufferDisplacement()=0
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TBuffer::DetachBuffer
void DetachBuffer()
Definition: TBuffer.h:99
TBuffer::ByteSwapBuffer
Bool_t ByteSwapBuffer(Long64_t n, EDataType type)
Byte-swap N primitive-elements in the buffer.
Definition: TBuffer.cxx:392
TBuffer::WriteStdString
virtual void WriteStdString(std::string &s)
Definition: TBuffer.h:312
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TBuffer::ReadInt
virtual void ReadInt(Int_t &i)=0
Short_t
short Short_t
Definition: RtypesCore.h:39
TBuffer::GetParent
TObject * GetParent() const
Return pointer to parent of this buffer.
Definition: TBuffer.cxx:262
TBuffer::ReadObjectAny
virtual void * ReadObjectAny(const TClass *cast)=0
TBuffer::ReadArrayFloat16
virtual Int_t ReadArrayFloat16(Float_t *&f, TStreamerElement *ele=0)=0
TBuffer::SetReadParam
virtual void SetReadParam(Int_t mapsize)=0
TObject::Read
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
Definition: TObject.cxx:564
TBuffer::WriteULong64
virtual void WriteULong64(ULong64_t l)=0
TBuffer::ReadVersion
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
TBuffer::ReadLong64
virtual void ReadLong64(Long64_t &l)=0
TRefTable
Definition: TRefTable.h:35
TBuffer::SetWriteParam
virtual void SetWriteParam(Int_t mapsize)=0
TBuffer::ReadShort
virtual void ReadShort(Short_t &s)=0
TBuffer::WriteDouble
virtual void WriteDouble(Double_t d)=0
TBuffer::WriteFloat16
virtual void WriteFloat16(Float_t *f, TStreamerElement *ele=0)=0
TBuffer::ClassEnd
virtual void ClassEnd(const TClass *)=0
TBuffer::ReadArrayDouble32
virtual Int_t ReadArrayDouble32(Double_t *&d, TStreamerElement *ele=0)=0
TBuffer::IsReading
Bool_t IsReading() const
Definition: TBuffer.h:86
ULong64_t
unsigned long long ULong64_t
Definition: RtypesCore.h:74
TBuffer::CacheList_t
std::vector< TVirtualArray * > CacheList_t
Definition: TBuffer.h:46
TBuffer::WriteClass
virtual void WriteClass(const TClass *cl)=0
TBuffer::PeekDataCache
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
Double_t
double Double_t
Definition: RtypesCore.h:59
TBuffer::fBufSize
Int_t fBufSize
Definition: TBuffer.h:50
TBuffer::WriteCharStar
virtual void WriteCharStar(char *s)=0
TBuffer::SkipObjectAny
virtual void SkipObjectAny()=0
TObject.h
TBuffer::WriteProcessID
virtual UShort_t WriteProcessID(TProcessID *pid)=0
Always return 0 (current processID).
Definition: TBuffer.cxx:353
TBuffer::WriteClones
virtual Int_t WriteClones(TClonesArray *a, Int_t nobjects)=0
TClass
Definition: TClass.h:80
TBuffer::IncrementLevel
virtual void IncrementLevel(TVirtualStreamerInfo *info)=0
TBuffer::WriteChar
virtual void WriteChar(Char_t c)=0
EDataType
EDataType
Definition: TDataType.h:28
UChar_t
unsigned char UChar_t
Definition: RtypesCore.h:38
TBuffer::Write
Int_t Write(const char *name, Int_t opt, Int_t bufs) const
Write this object to the current directory.
Definition: TBuffer.h:69
TObject::Write
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:795
TBuffer::Read
Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
Definition: TBuffer.h:66
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
Bytes.h
TBuffer::operator=
void operator=(const TBuffer &)
name
char name[80]
Definition: TGX11.cxx:110
TBuffer::ReadObject
virtual TObject * ReadObject(const TClass *cl)=0
TBuffer::fMode
Bool_t fMode
Definition: TBuffer.h:48
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:52
d
#define d(i)
Definition: RSha256.hxx:120
TBuffer::GetReAllocFunc
ReAllocCharFun_t GetReAllocFunc() const
Return the reallocation method currently used.
Definition: TBuffer.cxx:277
TBuffer::ReadProcessID
virtual TProcessID * ReadProcessID(UShort_t pidf)=0
Return the current Process-ID.
Definition: TBuffer.cxx:344
TBuffer::WriteFastArrayDouble32
virtual void WriteFastArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=0)=0
TBuffer::WriteArray
virtual void WriteArray(const Bool_t *b, Int_t n)=0
TBuffer::SkipVersion
virtual void SkipVersion(const TClass *cl=0)=0
TBuffer::AutoExpand
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
TBuffer::SetWriteMode
void SetWriteMode()
Set buffer in write mode.
Definition: TBuffer.cxx:315
TBuffer::WriteCharP
virtual void WriteCharP(const Char_t *c)=0
TBuffer::ReadCharStar
virtual void ReadCharStar(char *&s)=0
TBuffer::Reset
virtual void Reset()=0
TBuffer::ReadCharP
virtual void ReadCharP(Char_t *c)=0
TMemberStreamer
Definition: TMemberStreamer.h:26
type
int type
Definition: TGX11.cxx:121
TStreamerInfoActions::TActionSequence
Definition: TStreamerInfoActions.h:172
TBuffer::SetParent
void SetParent(TObject *parent)
Set parent owning this buffer.
Definition: TBuffer.cxx:270
TBuffer::GetClass
static TClass * GetClass(const std::type_info &typeinfo)
Forward to TROOT::GetClass().
Definition: TBuffer.cxx:328
TBuffer::WriteLong
virtual void WriteLong(Long_t l)=0
TBuffer::WriteTString
virtual void WriteTString(const TString &s)=0
TBuffer::WriteBool
virtual void WriteBool(Bool_t b)=0
TBuffer::ReadWithFactor
virtual void ReadWithFactor(Float_t *ptr, Double_t factor, Double_t minvalue)=0
Char_t
char Char_t
Definition: RtypesCore.h:33
TBuffer::ReadDouble32
virtual void ReadDouble32(Double_t *d, TStreamerElement *ele=0)=0
TClonesArray
Definition: TClonesArray.h:29
TBuffer::WriteLong64
virtual void WriteLong64(Long64_t l)=0
TStreamerElement
Definition: TStreamerElement.h:33
TBuffer::WriteObjectAny
virtual Int_t WriteObjectAny(const void *obj, const TClass *ptrClass, Bool_t cacheReuse=kTRUE)=0
TBuffer::ReadChar
virtual void ReadChar(Char_t &c)=0
TBuffer::kInitialSize
@ kInitialSize
Definition: TBuffer.h:78
TBuffer::kWrite
@ kWrite
Definition: TBuffer.h:73
TBuffer::~TBuffer
virtual ~TBuffer()
Delete an I/O buffer object.
Definition: TBuffer.cxx:140
TBuffer::fCacheStack
CacheList_t fCacheStack
Realloc function to be used when extending the buffer.
Definition: TBuffer.h:56
TBuffer::WriteArrayDouble32
virtual void WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=0)=0
int
TBuffer::ReadFloat16
virtual void ReadFloat16(Float_t *f, TStreamerElement *ele=0)=0
TBuffer::ReadClass
virtual TClass * ReadClass(const TClass *cl=0, UInt_t *objTag=0)=0