Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:33

0001 // @(#)root/base:$Id$
0002 // Author: Rene Brun, Philippe Canal, Fons Rademakers   04/05/96
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TBuffer
0013 #define ROOT_TBuffer
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TBuffer                                                              //
0019 //                                                                      //
0020 // Buffer base class used for serializing objects.                      //
0021 //                                                                      //
0022 //////////////////////////////////////////////////////////////////////////
0023 
0024 #include "TDataType.h"
0025 #include "TObject.h"
0026 #include "TClass.h"
0027 #include "Bytes.h"
0028 
0029 #include <vector>
0030 #include <string>
0031 
0032 class TVirtualStreamerInfo;
0033 class TStreamerElement;
0034 class TString;
0035 class TProcessID;
0036 class TClonesArray;
0037 class TRefTable;
0038 class TVirtualArray;
0039 namespace TStreamerInfoActions {
0040    class TActionSequence;
0041 }
0042 
0043 class TBuffer : public TObject {
0044 
0045 protected:
0046    typedef std::vector<TVirtualArray*> CacheList_t;
0047 
0048    Bool_t           fMode;          //Read or write mode
0049    Int_t            fVersion;       //Buffer format version
0050    Int_t            fBufSize;       //Size of buffer
0051    char            *fBuffer;        //Buffer used to store objects
0052    char            *fBufCur;        //Current position in buffer
0053    char            *fBufMax;        //End of buffer
0054    TObject         *fParent;        //Pointer to parent object owning this buffer
0055    ReAllocCharFun_t fReAllocFunc;   //! Realloc function to be used when extending the buffer.
0056    CacheList_t      fCacheStack;    //Stack of pointers to the cache where to temporarily store the value of 'missing' data members
0057 
0058    // Default ctor
0059    TBuffer() : TObject(), fMode(0), fVersion(0), fBufSize(0), fBuffer(nullptr),
0060      fBufCur(nullptr), fBufMax(nullptr), fParent(nullptr), fReAllocFunc(nullptr), fCacheStack(0, (TVirtualArray*)nullptr) {}
0061 
0062    // TBuffer objects cannot be copied or assigned
0063    TBuffer(const TBuffer &) = delete;
0064    void operator=(const TBuffer &) = delete;
0065 
0066    Int_t Read(const char *name) override { return TObject::Read(name); }
0067    Int_t Write(const char *name, Int_t opt, Int_t bufs) override
0068                               { return TObject::Write(name, opt, bufs); }
0069    Int_t Write(const char *name, Int_t opt, Int_t bufs) const override
0070                               { return TObject::Write(name, opt, bufs); }
0071 
0072 public:
0073    enum EMode { kRead = 0, kWrite = 1 };
0074    enum EStatusBits {
0075      kIsOwner = BIT(16), //if set TBuffer owns fBuffer
0076      kCannotHandleMemberWiseStreaming = BIT(17) //if set TClonesArray should not use member wise streaming
0077    };
0078    enum { kInitialSize = 1024, kMinimalSize = 128 };
0079 
0080    TBuffer(EMode mode);
0081    TBuffer(EMode mode, Int_t bufsiz);
0082    TBuffer(EMode mode, Int_t bufsiz, void *buf, Bool_t adopt = kTRUE, ReAllocCharFun_t reallocfunc = nullptr);
0083    virtual ~TBuffer();
0084 
0085    Int_t    GetBufferVersion() const { return fVersion; }
0086    Bool_t   IsReading() const { return (fMode & kWrite) == 0; }
0087    Bool_t   IsWriting() const { return (fMode & kWrite) != 0; }
0088    void     SetReadMode();
0089    void     SetWriteMode();
0090    void     SetBuffer(void *buf, UInt_t bufsiz = 0, Bool_t adopt = kTRUE, ReAllocCharFun_t reallocfunc = nullptr);
0091    ReAllocCharFun_t GetReAllocFunc() const;
0092    void     SetReAllocFunc(ReAllocCharFun_t reallocfunc = nullptr);
0093    void     SetBufferOffset(Int_t offset = 0) { fBufCur = fBuffer+offset; }
0094    void     SetParent(TObject *parent);
0095    TObject *GetParent()  const;
0096    char    *Buffer()     const { return fBuffer; }
0097    char    *GetCurrent() const { return fBufCur; }
0098    Int_t    BufferSize() const { return fBufSize; }
0099    void     DetachBuffer() { fBuffer = nullptr; }
0100    Int_t    Length()     const { return (Int_t)(fBufCur - fBuffer); }
0101    void     Expand(Int_t newsize, Bool_t copy = kTRUE);  // expand buffer to newsize
0102    void     AutoExpand(Int_t size_needed);  // expand buffer to newsize
0103    Bool_t   ByteSwapBuffer(Long64_t n, EDataType type);  // Byte-swap N primitive-elements in the buffer
0104 
0105    virtual Bool_t     CheckObject(const TObject *obj) = 0;
0106    virtual Bool_t     CheckObject(const void *obj, const TClass *ptrClass) = 0;
0107 
0108    virtual Int_t      ReadBuf(void *buf, Int_t max) = 0;
0109    virtual void       WriteBuf(const void *buf, Int_t max) = 0;
0110 
0111    virtual char      *ReadString(char *s, Int_t max) = 0;
0112    virtual void       WriteString(const char *s) = 0;
0113 
0114    virtual Int_t      GetVersionOwner() const  = 0;
0115    virtual Int_t      GetMapCount() const  = 0;
0116    virtual void       GetMappedObject(UInt_t tag, void* &ptr, TClass* &ClassPtr) const = 0;
0117    virtual void       MapObject(const TObject *obj, UInt_t offset = 1) = 0;
0118    virtual void       MapObject(const void *obj, const TClass *cl, UInt_t offset = 1) = 0;
0119    virtual void       Reset() = 0;
0120    virtual void       InitMap() = 0;
0121    virtual void       ResetMap() = 0;
0122    virtual void       SetReadParam(Int_t mapsize) = 0;
0123    virtual void       SetWriteParam(Int_t mapsize) = 0;
0124 
0125    virtual Int_t      CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss) = 0;
0126    virtual Int_t      CheckByteCount(UInt_t startpos, UInt_t bcnt, const char *classname) = 0;
0127    virtual void       SetByteCount(UInt_t cntpos, Bool_t packInVersion = kFALSE)= 0;
0128 
0129    virtual void       SkipVersion(const TClass *cl = nullptr) = 0;
0130    virtual Version_t  ReadVersion(UInt_t *start = nullptr, UInt_t *bcnt = nullptr, const TClass *cl = nullptr) = 0;
0131    virtual Version_t  ReadVersionNoCheckSum(UInt_t *start = nullptr, UInt_t *bcnt = nullptr) = 0;
0132    virtual Version_t  ReadVersionForMemberWise(const TClass *cl = nullptr) = 0;
0133    virtual UInt_t     WriteVersion(const TClass *cl, Bool_t useBcnt = kFALSE) = 0;
0134    virtual UInt_t     WriteVersionMemberWise(const TClass *cl, Bool_t useBcnt = kFALSE) = 0;
0135 
0136    virtual void      *ReadObjectAny(const TClass* cast) = 0;
0137    virtual void       SkipObjectAny() = 0;
0138 
0139    virtual void       TagStreamerInfo(TVirtualStreamerInfo* info) = 0;
0140    virtual void       IncrementLevel(TVirtualStreamerInfo* info) = 0;
0141    virtual void       SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type) = 0;
0142    virtual void       DecrementLevel(TVirtualStreamerInfo*) = 0;
0143 
0144    virtual void       ClassBegin(const TClass*, Version_t = -1) = 0;
0145    virtual void       ClassEnd(const TClass*) = 0;
0146    virtual void       ClassMember(const char*, const char * = nullptr, Int_t = -1, Int_t = -1) = 0;
0147    virtual TVirtualStreamerInfo *GetInfo() = 0;
0148 
0149    virtual TVirtualArray *PeekDataCache() const;
0150    virtual TVirtualArray *PopDataCache();
0151    virtual void           PushDataCache(TVirtualArray *);
0152 
0153    virtual TClass    *ReadClass(const TClass *cl = nullptr, UInt_t *objTag = nullptr) = 0;
0154    virtual void       WriteClass(const TClass *cl) = 0;
0155 
0156    virtual TObject   *ReadObject(const TClass *cl) = 0;
0157    virtual void       WriteObject(const TObject *obj, Bool_t cacheReuse) = 0;
0158 
0159    template <class T> Int_t WriteObject(const T *objptr, Bool_t cacheReuse = kTRUE);
0160 
0161    virtual Int_t      WriteObjectAny(const void *obj, const TClass *ptrClass, Bool_t cacheReuse = kTRUE) = 0;
0162 
0163    virtual UShort_t   GetPidOffset() const  = 0;
0164    virtual void       SetPidOffset(UShort_t offset) = 0;
0165    virtual Int_t      GetBufferDisplacement() const  = 0;
0166    virtual void       SetBufferDisplacement() = 0;
0167    virtual void       SetBufferDisplacement(Int_t skipped) = 0;
0168 
0169    // basic types and arrays of basic types
0170    virtual   void     ReadFloat16 (Float_t *f, TStreamerElement *ele = nullptr) = 0;
0171    virtual   void     WriteFloat16(Float_t *f, TStreamerElement *ele = nullptr) = 0;
0172    virtual   void     ReadDouble32 (Double_t *d, TStreamerElement *ele = nullptr) = 0;
0173    virtual   void     WriteDouble32(Double_t *d, TStreamerElement *ele = nullptr) = 0;
0174    virtual   void     ReadWithFactor(Float_t *ptr, Double_t factor, Double_t minvalue) = 0;
0175    virtual   void     ReadWithNbits(Float_t *ptr, Int_t nbits) = 0;
0176    virtual   void     ReadWithFactor(Double_t *ptr, Double_t factor, Double_t minvalue) = 0;
0177    virtual   void     ReadWithNbits(Double_t *ptr, Int_t nbits) = 0;
0178 
0179    virtual   Int_t    ReadArray(Bool_t    *&b) = 0;
0180    virtual   Int_t    ReadArray(Char_t    *&c) = 0;
0181    virtual   Int_t    ReadArray(UChar_t   *&c) = 0;
0182    virtual   Int_t    ReadArray(Short_t   *&h) = 0;
0183    virtual   Int_t    ReadArray(UShort_t  *&h) = 0;
0184    virtual   Int_t    ReadArray(Int_t     *&i) = 0;
0185    virtual   Int_t    ReadArray(UInt_t    *&i) = 0;
0186    virtual   Int_t    ReadArray(Long_t    *&l) = 0;
0187    virtual   Int_t    ReadArray(ULong_t   *&l) = 0;
0188    virtual   Int_t    ReadArray(Long64_t  *&l) = 0;
0189    virtual   Int_t    ReadArray(ULong64_t *&l) = 0;
0190    virtual   Int_t    ReadArray(Float_t   *&f) = 0;
0191    virtual   Int_t    ReadArray(Double_t  *&d) = 0;
0192    virtual   Int_t    ReadArrayFloat16(Float_t *&f, TStreamerElement *ele = nullptr) = 0;
0193    virtual   Int_t    ReadArrayDouble32(Double_t *&d, TStreamerElement *ele = nullptr) = 0;
0194 
0195    virtual   Int_t    ReadStaticArray(Bool_t    *b) = 0;
0196    virtual   Int_t    ReadStaticArray(Char_t    *c) = 0;
0197    virtual   Int_t    ReadStaticArray(UChar_t   *c) = 0;
0198    virtual   Int_t    ReadStaticArray(Short_t   *h) = 0;
0199    virtual   Int_t    ReadStaticArray(UShort_t  *h) = 0;
0200    virtual   Int_t    ReadStaticArray(Int_t     *i) = 0;
0201    virtual   Int_t    ReadStaticArray(UInt_t    *i) = 0;
0202    virtual   Int_t    ReadStaticArray(Long_t    *l) = 0;
0203    virtual   Int_t    ReadStaticArray(ULong_t   *l) = 0;
0204    virtual   Int_t    ReadStaticArray(Long64_t  *l) = 0;
0205    virtual   Int_t    ReadStaticArray(ULong64_t *l) = 0;
0206    virtual   Int_t    ReadStaticArray(Float_t   *f) = 0;
0207    virtual   Int_t    ReadStaticArray(Double_t  *d) = 0;
0208    virtual   Int_t    ReadStaticArrayFloat16(Float_t  *f, TStreamerElement *ele = nullptr) = 0;
0209    virtual   Int_t    ReadStaticArrayDouble32(Double_t  *d, TStreamerElement *ele = nullptr) = 0;
0210 
0211    virtual   void     ReadFastArray(Bool_t    *b, Int_t n) = 0;
0212    virtual   void     ReadFastArray(Char_t    *c, Int_t n) = 0;
0213    virtual   void     ReadFastArrayString(Char_t *c, Int_t n) = 0;
0214    virtual   void     ReadFastArray(UChar_t   *c, Int_t n) = 0;
0215    virtual   void     ReadFastArray(Short_t   *h, Int_t n) = 0;
0216    virtual   void     ReadFastArray(UShort_t  *h, Int_t n) = 0;
0217    virtual   void     ReadFastArray(Int_t     *i, Int_t n) = 0;
0218    virtual   void     ReadFastArray(UInt_t    *i, Int_t n) = 0;
0219    virtual   void     ReadFastArray(Long_t    *l, Int_t n) = 0;
0220    virtual   void     ReadFastArray(ULong_t   *l, Int_t n) = 0;
0221    virtual   void     ReadFastArray(Long64_t  *l, Int_t n) = 0;
0222    virtual   void     ReadFastArray(ULong64_t *l, Int_t n) = 0;
0223    virtual   void     ReadFastArray(Float_t   *f, Int_t n) = 0;
0224    virtual   void     ReadFastArray(Double_t  *d, Int_t n) = 0;
0225    virtual   void     ReadFastArrayFloat16(Float_t  *f, Int_t n, TStreamerElement *ele = nullptr) = 0;
0226    virtual   void     ReadFastArrayDouble32(Double_t  *d, Int_t n, TStreamerElement *ele = nullptr) = 0;
0227    virtual   void     ReadFastArrayWithFactor(Float_t *ptr, Int_t n, Double_t factor, Double_t minvalue) = 0;
0228    virtual   void     ReadFastArrayWithNbits(Float_t *ptr, Int_t n, Int_t nbits) = 0;
0229    virtual   void     ReadFastArrayWithFactor(Double_t *ptr, Int_t n, Double_t factor, Double_t minvalue) = 0;
0230    virtual   void     ReadFastArrayWithNbits(Double_t *ptr, Int_t n, Int_t nbits) = 0;
0231    virtual   void     ReadFastArray(void  *start , const TClass *cl, Int_t n=1, TMemberStreamer *s = nullptr, const TClass *onFileClass = nullptr) = 0;
0232    virtual   void     ReadFastArray(void **startp, const TClass *cl, Int_t n=1, Bool_t isPreAlloc=kFALSE, TMemberStreamer *s = nullptr, const TClass *onFileClass = nullptr) = 0;
0233 
0234    virtual   void     WriteArray(const Bool_t    *b, Int_t n) = 0;
0235    virtual   void     WriteArray(const Char_t    *c, Int_t n) = 0;
0236    virtual   void     WriteArray(const UChar_t   *c, Int_t n) = 0;
0237    virtual   void     WriteArray(const Short_t   *h, Int_t n) = 0;
0238    virtual   void     WriteArray(const UShort_t  *h, Int_t n) = 0;
0239    virtual   void     WriteArray(const Int_t     *i, Int_t n) = 0;
0240    virtual   void     WriteArray(const UInt_t    *i, Int_t n) = 0;
0241    virtual   void     WriteArray(const Long_t    *l, Int_t n) = 0;
0242    virtual   void     WriteArray(const ULong_t   *l, Int_t n) = 0;
0243    virtual   void     WriteArray(const Long64_t  *l, Int_t n) = 0;
0244    virtual   void     WriteArray(const ULong64_t *l, Int_t n) = 0;
0245    virtual   void     WriteArray(const Float_t   *f, Int_t n) = 0;
0246    virtual   void     WriteArray(const Double_t  *d, Int_t n) = 0;
0247    virtual   void     WriteArrayFloat16(const Float_t  *f, Int_t n, TStreamerElement *ele = nullptr) = 0;
0248    virtual   void     WriteArrayDouble32(const Double_t  *d, Int_t n, TStreamerElement *ele = nullptr) = 0;
0249 
0250    virtual   void     WriteFastArray(const Bool_t    *b, Long64_t n) = 0;
0251    virtual   void     WriteFastArray(const Char_t    *c, Long64_t n) = 0;
0252    virtual   void     WriteFastArrayString(const Char_t    *c, Long64_t n) = 0;
0253    virtual   void     WriteFastArray(const UChar_t   *c, Long64_t n) = 0;
0254    virtual   void     WriteFastArray(const Short_t   *h, Long64_t n) = 0;
0255    virtual   void     WriteFastArray(const UShort_t  *h, Long64_t n) = 0;
0256    virtual   void     WriteFastArray(const Int_t     *i, Long64_t n) = 0;
0257    virtual   void     WriteFastArray(const UInt_t    *i, Long64_t n) = 0;
0258    virtual   void     WriteFastArray(const Long_t    *l, Long64_t n) = 0;
0259    virtual   void     WriteFastArray(const ULong_t   *l, Long64_t n) = 0;
0260    virtual   void     WriteFastArray(const Long64_t  *l, Long64_t n) = 0;
0261    virtual   void     WriteFastArray(const ULong64_t *l, Long64_t n) = 0;
0262    virtual   void     WriteFastArray(const Float_t   *f, Long64_t n) = 0;
0263    virtual   void     WriteFastArray(const Double_t  *d, Long64_t n) = 0;
0264    virtual   void     WriteFastArrayFloat16(const Float_t  *f, Long64_t n, TStreamerElement *ele = nullptr) = 0;
0265    virtual   void     WriteFastArrayDouble32(const Double_t  *d, Long64_t n, TStreamerElement *ele = nullptr) = 0;
0266    virtual   void     WriteFastArray(void  *start,  const TClass *cl, Long64_t n=1, TMemberStreamer *s = nullptr) = 0;
0267    virtual   Int_t    WriteFastArray(void **startp, const TClass *cl, Long64_t n=1, Bool_t isPreAlloc = kFALSE, TMemberStreamer *s = nullptr) = 0;
0268 
0269    virtual   void     StreamObject(void *obj, const std::type_info &typeinfo, const TClass* onFileClass = nullptr) = 0;
0270    virtual   void     StreamObject(void *obj, const char *className, const TClass* onFileClass = nullptr) = 0;
0271    virtual   void     StreamObject(void *obj, const TClass *cl, const TClass* onFileClass = nullptr) = 0;
0272    virtual   void     StreamObject(TObject *obj) = 0;
0273 
0274    virtual   void     ReadBool(Bool_t       &b) = 0;
0275    virtual   void     ReadChar(Char_t       &c) = 0;
0276    virtual   void     ReadUChar(UChar_t     &c) = 0;
0277    virtual   void     ReadShort(Short_t     &s) = 0;
0278    virtual   void     ReadUShort(UShort_t   &s) = 0;
0279    virtual   void     ReadInt(Int_t         &i) = 0;
0280    virtual   void     ReadUInt(UInt_t       &i) = 0;
0281    virtual   void     ReadLong(Long_t       &l) = 0;
0282    virtual   void     ReadULong(ULong_t     &l) = 0;
0283    virtual   void     ReadLong64(Long64_t   &l) = 0;
0284    virtual   void     ReadULong64(ULong64_t &l) = 0;
0285    virtual   void     ReadFloat(Float_t     &f) = 0;
0286    virtual   void     ReadDouble(Double_t   &d) = 0;
0287    virtual   void     ReadCharP(Char_t      *c) = 0;
0288    virtual   void     ReadTString(TString   &s) = 0;
0289    virtual   void     ReadStdString(std::string *s) = 0;
0290    virtual   void     ReadCharStar(char* &s) = 0;
0291 
0292    virtual inline void ReadStdString(std::string &s) { ReadStdString(&s); }
0293 
0294    virtual   void     WriteBool(Bool_t       b) = 0;
0295    virtual   void     WriteChar(Char_t       c) = 0;
0296    virtual   void     WriteUChar(UChar_t     c) = 0;
0297    virtual   void     WriteShort(Short_t     s) = 0;
0298    virtual   void     WriteUShort(UShort_t   s) = 0;
0299    virtual   void     WriteInt(Int_t         i) = 0;
0300    virtual   void     WriteUInt(UInt_t       i) = 0;
0301    virtual   void     WriteLong(Long_t       l) = 0;
0302    virtual   void     WriteULong(ULong_t     l) = 0;
0303    virtual   void     WriteLong64(Long64_t   l) = 0;
0304    virtual   void     WriteULong64(ULong64_t l) = 0;
0305    virtual   void     WriteFloat(Float_t     f) = 0;
0306    virtual   void     WriteDouble(Double_t   d) = 0;
0307    virtual   void     WriteCharP(const Char_t *c) = 0;
0308    virtual   void     WriteTString(const TString &s) = 0;
0309    virtual   void     WriteStdString(const std::string *s) = 0;
0310    virtual   void     WriteCharStar(char *s) = 0;
0311 
0312    virtual inline void WriteStdString(std::string &s) { WriteStdString(&s); }
0313 
0314    // Special basic ROOT objects and collections
0315    virtual   TProcessID *GetLastProcessID(TRefTable *reftable) const = 0;
0316    virtual   UInt_t      GetTRefExecId() = 0;
0317    virtual   TProcessID *ReadProcessID(UShort_t pidf) = 0;
0318    virtual   UShort_t    WriteProcessID(TProcessID *pid) = 0;
0319 
0320    // Utilities for TStreamerInfo
0321    virtual   void     ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force) = 0;
0322    virtual   void     ForceWriteInfoClones(TClonesArray *a) = 0;
0323    virtual   Int_t    ReadClones (TClonesArray *a, Int_t nobjects, Version_t objvers) = 0;
0324    virtual   Int_t    WriteClones(TClonesArray *a, Int_t nobjects) = 0;
0325 
0326    // Utilities for TClass
0327    virtual   Int_t    ReadClassEmulated(const TClass *cl, void *object, const TClass *onfile_class = nullptr) = 0;
0328    virtual   Int_t    ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class = nullptr) = 0;
0329    virtual   Int_t    ReadClassBuffer(const TClass *cl, void *pointer, Int_t version, UInt_t start, UInt_t count, const TClass *onfile_class = nullptr) = 0;
0330    virtual   Int_t    WriteClassBuffer(const TClass *cl, void *pointer) = 0;
0331 
0332    // Utilites to streamer using sequences.
0333    virtual Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *object) = 0;
0334    virtual Int_t ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection) = 0;
0335    virtual Int_t ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection) = 0;
0336 
0337    static TClass *GetClass(const std::type_info &typeinfo);
0338    static TClass *GetClass(const char *className);
0339 
0340    ClassDefOverride(TBuffer,0)  //Buffer base class used for serializing objects
0341 };
0342 
0343 //---------------------- TBuffer default external operators --------------------
0344 
0345 inline TBuffer &operator>>(TBuffer &buf, Bool_t &b)   { buf.ReadBool(b);   return buf; }
0346 inline TBuffer &operator>>(TBuffer &buf, Char_t &c)   { buf.ReadChar(c);   return buf; }
0347 inline TBuffer &operator>>(TBuffer &buf, UChar_t &c)  { buf.ReadUChar(c);  return buf; }
0348 inline TBuffer &operator>>(TBuffer &buf, Short_t &s)  { buf.ReadShort(s);  return buf; }
0349 inline TBuffer &operator>>(TBuffer &buf, UShort_t &s) { buf.ReadUShort(s); return buf; }
0350 inline TBuffer &operator>>(TBuffer &buf, Int_t &i)    { buf.ReadInt(i);    return buf; }
0351 inline TBuffer &operator>>(TBuffer &buf, UInt_t &i)   { buf.ReadUInt(i);   return buf; }
0352 inline TBuffer &operator>>(TBuffer &buf, Long_t &l)   { buf.ReadLong(l);   return buf; }
0353 inline TBuffer &operator>>(TBuffer &buf, ULong_t &l)  { buf.ReadULong(l);  return buf; }
0354 inline TBuffer &operator>>(TBuffer &buf, Long64_t &l) { buf.ReadLong64(l); return buf; }
0355 inline TBuffer &operator>>(TBuffer &buf, ULong64_t &l){ buf.ReadULong64(l);return buf; }
0356 inline TBuffer &operator>>(TBuffer &buf, Float_t &f)  { buf.ReadFloat(f);  return buf; }
0357 inline TBuffer &operator>>(TBuffer &buf, Double_t &d) { buf.ReadDouble(d); return buf; }
0358 inline TBuffer &operator>>(TBuffer &buf, Char_t *c)   { buf.ReadCharP(c);  return buf; }
0359 inline TBuffer &operator>>(TBuffer &buf, TString &s)  { buf.ReadTString(s);return buf; }
0360 
0361 inline TBuffer &operator<<(TBuffer &buf, Bool_t b)   { buf.WriteBool(b);   return buf; }
0362 inline TBuffer &operator<<(TBuffer &buf, Char_t c)   { buf.WriteChar(c);   return buf; }
0363 inline TBuffer &operator<<(TBuffer &buf, UChar_t c)  { buf.WriteUChar(c);  return buf; }
0364 inline TBuffer &operator<<(TBuffer &buf, Short_t s)  { buf.WriteShort(s);  return buf; }
0365 inline TBuffer &operator<<(TBuffer &buf, UShort_t s) { buf.WriteUShort(s); return buf; }
0366 inline TBuffer &operator<<(TBuffer &buf, Int_t i)    { buf.WriteInt(i);    return buf; }
0367 inline TBuffer &operator<<(TBuffer &buf, UInt_t i)   { buf.WriteUInt(i);   return buf; }
0368 inline TBuffer &operator<<(TBuffer &buf, Long_t l)   { buf.WriteLong(l);   return buf; }
0369 inline TBuffer &operator<<(TBuffer &buf, ULong_t l)  { buf.WriteULong(l);  return buf; }
0370 inline TBuffer &operator<<(TBuffer &buf, Long64_t l) { buf.WriteLong64(l); return buf; }
0371 inline TBuffer &operator<<(TBuffer &buf, ULong64_t l){ buf.WriteULong64(l);return buf; }
0372 inline TBuffer &operator<<(TBuffer &buf, Float_t f)  { buf.WriteFloat(f);  return buf; }
0373 inline TBuffer &operator<<(TBuffer &buf, Double_t d) { buf.WriteDouble(d); return buf; }
0374 inline TBuffer &operator<<(TBuffer &buf, const Char_t *c)  { buf.WriteCharP(c);  return buf; }
0375 inline TBuffer &operator<<(TBuffer &buf, const TString &s) { buf.WriteTString(s);return buf; }
0376 
0377 #if defined(R__SOLARIS) && defined(R__GNU)
0378 #include <typeinfo>
0379 #endif
0380 
0381 template <class Tmpl> TBuffer &operator>>(TBuffer &buf, Tmpl *&obj)
0382 {
0383    // Read TObject derived classes from a TBuffer. Need to provide
0384    // custom version for non-TObject derived classes.
0385 
0386    // This operator has to be a templated and/or automatically
0387    // generated if we want to be able to check the type of the
0388    // incoming object. I.e. a operator>>(TBuffer &buf, TObject *&)
0389    // would not be sufficient to pass the information 'which class do we want'
0390    // since the pointer could be zero (so typeid(*obj) is not usable).
0391 
0392    auto cl = TClass::GetClass<Tmpl>();
0393    obj = (Tmpl *) ( (void*) buf.ReadObjectAny(cl) );
0394    return buf;
0395 }
0396 
0397 template <class Tmpl> TBuffer &operator<<(TBuffer &buf, const Tmpl *obj)
0398 {
0399    auto cl = (obj) ? TClass::GetClass<Tmpl>() : nullptr;
0400    buf.WriteObjectAny(obj, cl);
0401    return buf;
0402 }
0403 
0404 template <class T>
0405 inline Int_t TBuffer::WriteObject(const T *objptr, Bool_t cacheReuse)
0406 {
0407    auto cl = (objptr) ? TClass::GetClass<T>() : nullptr;
0408    return WriteObjectAny(objptr, cl, cacheReuse);
0409 }
0410 
0411 #endif // ROOT_TBuffer