Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TBufferXML.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/xml:$Id: d90d66e8fd2aa9daa4b05bcba9166aee1e2b2e7f $
0002 // Author: Sergey Linev  10.05.2004
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2004, 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_TBufferXML
0013 #define ROOT_TBufferXML
0014 
0015 #include "Compression.h"
0016 #include "TBufferText.h"
0017 #include "TXMLSetup.h"
0018 #include "TString.h"
0019 #include "TXMLEngine.h"
0020 
0021 #include <string>
0022 #include <deque>
0023 #include <memory>
0024 
0025 class TExMap;
0026 class TVirtualStreamerInfo;
0027 class TStreamerInfo;
0028 class TStreamerElement;
0029 class TMemberStreamer;
0030 class TXMLFile;
0031 class TXMLStackObj;
0032 
0033 class TBufferXML final : public TBufferText, public TXMLSetup {
0034 
0035    friend class TKeyXML;
0036 
0037 public:
0038    TBufferXML(TBuffer::EMode mode);
0039    TBufferXML(TBuffer::EMode mode, TXMLFile *file);
0040    ~TBufferXML() override;
0041 
0042    static TString ConvertToXML(const TObject *obj, Bool_t GenericLayout = kFALSE, Bool_t UseNamespaces = kFALSE);
0043    static TString
0044    ConvertToXML(const void *obj, const TClass *cl, Bool_t GenericLayout = kFALSE, Bool_t UseNamespaces = kFALSE);
0045 
0046    template <class T>
0047    static TString ToXML(const T *obj, Bool_t GenericLayout = kFALSE, Bool_t UseNamespaces = kFALSE)
0048    {
0049       return ConvertToXML(obj, TClass::GetClass<T>(), GenericLayout, UseNamespaces);
0050    }
0051 
0052    static TObject *ConvertFromXML(const char *str, Bool_t GenericLayout = kFALSE, Bool_t UseNamespaces = kFALSE);
0053    static void *ConvertFromXMLAny(const char *str, TClass **cl = nullptr, Bool_t GenericLayout = kFALSE,
0054                                   Bool_t UseNamespaces = kFALSE);
0055 
0056    template <class T>
0057    static Bool_t FromXML(T *&obj, const char *xml, Bool_t GenericLayout = kFALSE, Bool_t UseNamespaces = kFALSE)
0058    {
0059       if (obj)
0060          return kFALSE;
0061       obj = (T *)ConvertFromXMLChecked(xml, TClass::GetClass<T>(), GenericLayout, UseNamespaces);
0062       return obj != nullptr;
0063    }
0064 
0065    Int_t GetIOVersion() const { return fIOVersion; }
0066    void SetIOVersion(Int_t v) { fIOVersion = v; }
0067 
0068    // suppress class writing/reading
0069 
0070    TClass *ReadClass(const TClass *cl = nullptr, UInt_t *objTag = nullptr) final;
0071    void WriteClass(const TClass *cl) final;
0072 
0073    // redefined virtual functions of TBuffer
0074 
0075    Version_t ReadVersion(UInt_t *start = nullptr, UInt_t *bcnt = nullptr, const TClass *cl = nullptr) final;
0076    UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt = kFALSE) final;
0077 
0078    void *ReadObjectAny(const TClass *clCast) final;
0079    void SkipObjectAny() final;
0080 
0081    void IncrementLevel(TVirtualStreamerInfo *) final;
0082    void SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type) final;
0083    void DecrementLevel(TVirtualStreamerInfo *) final;
0084 
0085    void ClassBegin(const TClass *, Version_t = -1) final;
0086    void ClassEnd(const TClass *) final;
0087    void ClassMember(const char *name, const char *typeName = nullptr, Int_t arrsize1 = -1, Int_t arrsize2 = -1) final;
0088 
0089    Int_t ReadArray(Bool_t *&b) final;
0090    Int_t ReadArray(Char_t *&c) final;
0091    Int_t ReadArray(UChar_t *&c) final;
0092    Int_t ReadArray(Short_t *&h) final;
0093    Int_t ReadArray(UShort_t *&h) final;
0094    Int_t ReadArray(Int_t *&i) final;
0095    Int_t ReadArray(UInt_t *&i) final;
0096    Int_t ReadArray(Long_t *&l) final;
0097    Int_t ReadArray(ULong_t *&l) final;
0098    Int_t ReadArray(Long64_t *&l) final;
0099    Int_t ReadArray(ULong64_t *&l) final;
0100    Int_t ReadArray(Float_t *&f) final;
0101    Int_t ReadArray(Double_t *&d) final;
0102 
0103    Int_t ReadStaticArray(Bool_t *b) final;
0104    Int_t ReadStaticArray(Char_t *c) final;
0105    Int_t ReadStaticArray(UChar_t *c) final;
0106    Int_t ReadStaticArray(Short_t *h) final;
0107    Int_t ReadStaticArray(UShort_t *h) final;
0108    Int_t ReadStaticArray(Int_t *i) final;
0109    Int_t ReadStaticArray(UInt_t *i) final;
0110    Int_t ReadStaticArray(Long_t *l) final;
0111    Int_t ReadStaticArray(ULong_t *l) final;
0112    Int_t ReadStaticArray(Long64_t *l) final;
0113    Int_t ReadStaticArray(ULong64_t *l) final;
0114    Int_t ReadStaticArray(Float_t *f) final;
0115    Int_t ReadStaticArray(Double_t *d) final;
0116 
0117    void ReadFastArray(Bool_t *b, Int_t n) final;
0118    void ReadFastArray(Char_t *c, Int_t n) final;
0119    void ReadFastArray(UChar_t *c, Int_t n) final;
0120    void ReadFastArray(Short_t *h, Int_t n) final;
0121    void ReadFastArray(UShort_t *h, Int_t n) final;
0122    void ReadFastArray(Int_t *i, Int_t n) final;
0123    void ReadFastArray(UInt_t *i, Int_t n) final;
0124    void ReadFastArray(Long_t *l, Int_t n) final;
0125    void ReadFastArray(ULong_t *l, Int_t n) final;
0126    void ReadFastArray(Long64_t *l, Int_t n) final;
0127    void ReadFastArray(ULong64_t *l, Int_t n) final;
0128    void ReadFastArray(Float_t *f, Int_t n) final;
0129    void ReadFastArray(Double_t *d, Int_t n) final;
0130    void ReadFastArrayString(Char_t *c, Int_t n) final;
0131    void ReadFastArray(void *start, const TClass *cl, Int_t n = 1, TMemberStreamer *s = nullptr,
0132                       const TClass *onFileClass = nullptr) final;
0133    void ReadFastArray(void **startp, const TClass *cl, Int_t n = 1, Bool_t isPreAlloc = kFALSE,
0134                       TMemberStreamer *s = nullptr, const TClass *onFileClass = nullptr) final;
0135 
0136    void WriteArray(const Bool_t *b, Int_t n) final;
0137    void WriteArray(const Char_t *c, Int_t n) final;
0138    void WriteArray(const UChar_t *c, Int_t n) final;
0139    void WriteArray(const Short_t *h, Int_t n) final;
0140    void WriteArray(const UShort_t *h, Int_t n) final;
0141    void WriteArray(const Int_t *i, Int_t n) final;
0142    void WriteArray(const UInt_t *i, Int_t n) final;
0143    void WriteArray(const Long_t *l, Int_t n) final;
0144    void WriteArray(const ULong_t *l, Int_t n) final;
0145    void WriteArray(const Long64_t *l, Int_t n) final;
0146    void WriteArray(const ULong64_t *l, Int_t n) final;
0147    void WriteArray(const Float_t *f, Int_t n) final;
0148    void WriteArray(const Double_t *d, Int_t n) final;
0149 
0150    void WriteFastArray(const Bool_t *b, Long64_t n) final;
0151    void WriteFastArray(const Char_t *c, Long64_t n) final;
0152    void WriteFastArray(const UChar_t *c, Long64_t n) final;
0153    void WriteFastArray(const Short_t *h, Long64_t n) final;
0154    void WriteFastArray(const UShort_t *h, Long64_t n) final;
0155    void WriteFastArray(const Int_t *i, Long64_t n) final;
0156    void WriteFastArray(const UInt_t *i, Long64_t n) final;
0157    void WriteFastArray(const Long_t *l, Long64_t n) final;
0158    void WriteFastArray(const ULong_t *l, Long64_t n) final;
0159    void WriteFastArray(const Long64_t *l, Long64_t n) final;
0160    void WriteFastArray(const ULong64_t *l, Long64_t n) final;
0161    void WriteFastArray(const Float_t *f, Long64_t n) final;
0162    void WriteFastArray(const Double_t *d, Long64_t n) final;
0163    void WriteFastArrayString(const Char_t *c, Long64_t n) final;
0164    void WriteFastArray(void *start, const TClass *cl, Long64_t n = 1, TMemberStreamer *s = nullptr) final;
0165    Int_t WriteFastArray(void **startp, const TClass *cl, Long64_t n = 1, Bool_t isPreAlloc = kFALSE,
0166                         TMemberStreamer *s = nullptr) final;
0167 
0168    void StreamObject(void *obj, const TClass *cl, const TClass *onFileClass = nullptr) final;
0169    using TBufferText::StreamObject;
0170 
0171    void ReadBool(Bool_t &b) final;
0172    void ReadChar(Char_t &c) final;
0173    void ReadUChar(UChar_t &c) final;
0174    void ReadShort(Short_t &s) final;
0175    void ReadUShort(UShort_t &s) final;
0176    void ReadInt(Int_t &i) final;
0177    void ReadUInt(UInt_t &i) final;
0178    void ReadLong(Long_t &l) final;
0179    void ReadULong(ULong_t &l) final;
0180    void ReadLong64(Long64_t &l) final;
0181    void ReadULong64(ULong64_t &l) final;
0182    void ReadFloat(Float_t &f) final;
0183    void ReadDouble(Double_t &d) final;
0184    void ReadCharP(Char_t *c) final;
0185    void ReadTString(TString &s) final;
0186    void ReadStdString(std::string *s) final;
0187    using TBuffer::ReadStdString;
0188    void ReadCharStar(char *&s) final;
0189 
0190    void WriteBool(Bool_t b) final;
0191    void WriteChar(Char_t c) final;
0192    void WriteUChar(UChar_t c) final;
0193    void WriteShort(Short_t s) final;
0194    void WriteUShort(UShort_t s) final;
0195    void WriteInt(Int_t i) final;
0196    void WriteUInt(UInt_t i) final;
0197    void WriteLong(Long_t l) final;
0198    void WriteULong(ULong_t l) final;
0199    void WriteLong64(Long64_t l) final;
0200    void WriteULong64(ULong64_t l) final;
0201    void WriteFloat(Float_t f) final;
0202    void WriteDouble(Double_t d) final;
0203    void WriteCharP(const Char_t *c) final;
0204    void WriteTString(const TString &s) final;
0205    void WriteStdString(const std::string *s) final;
0206    using TBuffer::WriteStdString;
0207    void WriteCharStar(char *s) final;
0208 
0209    TVirtualStreamerInfo *GetInfo() final;
0210 
0211 protected:
0212    // redefined protected virtual functions
0213 
0214    void WriteObjectClass(const void *actualObjStart, const TClass *actualClass, Bool_t cacheReuse) final;
0215 
0216    // end redefined protected virtual functions
0217 
0218    static void *ConvertFromXMLChecked(const char *xml, const TClass *expectedClass, Bool_t GenericLayout = kFALSE,
0219                                       Bool_t UseNamespaces = kFALSE);
0220 
0221    TXMLFile *XmlFile();
0222 
0223    Int_t GetCompressionAlgorithm() const;
0224    Int_t GetCompressionLevel() const;
0225    Int_t GetCompressionSettings() const;
0226    void SetCompressionAlgorithm(Int_t algorithm = ROOT::RCompressionSetting::EAlgorithm::kUseGlobal);
0227    void SetCompressionLevel(Int_t level = ROOT::RCompressionSetting::ELevel::kUseMin);
0228    void SetCompressionSettings(Int_t settings = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault);
0229    void SetXML(TXMLEngine *xml) { fXML = xml; }
0230 
0231    XMLNodePointer_t XmlWriteAny(const void *obj, const TClass *cl);
0232 
0233    void *XmlReadAny(XMLNodePointer_t node, void *obj, TClass **cl);
0234 
0235    TXMLStackObj *PushStack(XMLNodePointer_t current, Bool_t simple = kFALSE);
0236    TXMLStackObj *PopStack();
0237    void ShiftStack(const char *info = nullptr);
0238 
0239    XMLNodePointer_t StackNode();
0240    TXMLStackObj *Stack(UInt_t depth = 0)
0241    {
0242       return (depth < fStack.size()) ? (depth ? fStack[fStack.size() - depth - 1].get() : fStack.back().get()) : nullptr;
0243    }
0244 
0245    void WorkWithClass(TStreamerInfo *info, const TClass *cl = nullptr);
0246    void WorkWithElement(TStreamerElement *elem, Int_t comp_type);
0247    Bool_t VerifyNode(XMLNodePointer_t node, const char *name, const char *errinfo = nullptr);
0248    Bool_t VerifyStackNode(const char *name, const char *errinfo = nullptr);
0249 
0250    Bool_t VerifyAttr(XMLNodePointer_t node, const char *name, const char *value, const char *errinfo = nullptr);
0251    Bool_t VerifyStackAttr(const char *name, const char *value, const char *errinfo = nullptr);
0252 
0253    Bool_t ProcessPointer(const void *ptr, XMLNodePointer_t node);
0254    Bool_t ExtractPointer(XMLNodePointer_t node, void *&ptr, TClass *&cl);
0255    void ExtractReference(XMLNodePointer_t node, const void *ptr, const TClass *cl);
0256 
0257    XMLNodePointer_t CreateItemNode(const char *name);
0258    Bool_t VerifyItemNode(const char *name, const char *errinfo = nullptr);
0259 
0260    void CreateElemNode(const TStreamerElement *elem);
0261    Bool_t VerifyElemNode(const TStreamerElement *elem);
0262 
0263    void PerformPreProcessing(const TStreamerElement *elem, XMLNodePointer_t elemnode);
0264    void PerformPostProcessing();
0265 
0266    XMLNodePointer_t XmlWriteBasic(Char_t value);
0267    XMLNodePointer_t XmlWriteBasic(Short_t value);
0268    XMLNodePointer_t XmlWriteBasic(Int_t value);
0269    XMLNodePointer_t XmlWriteBasic(Long_t value);
0270    XMLNodePointer_t XmlWriteBasic(Long64_t value);
0271    XMLNodePointer_t XmlWriteBasic(Float_t value);
0272    XMLNodePointer_t XmlWriteBasic(Double_t value);
0273    XMLNodePointer_t XmlWriteBasic(Bool_t value);
0274    XMLNodePointer_t XmlWriteBasic(UChar_t value);
0275    XMLNodePointer_t XmlWriteBasic(UShort_t value);
0276    XMLNodePointer_t XmlWriteBasic(UInt_t value);
0277    XMLNodePointer_t XmlWriteBasic(ULong_t value);
0278    XMLNodePointer_t XmlWriteBasic(ULong64_t value);
0279    XMLNodePointer_t XmlWriteValue(const char *value, const char *name);
0280 
0281    void XmlReadBasic(Char_t &value);
0282    void XmlReadBasic(Short_t &value);
0283    void XmlReadBasic(Int_t &value);
0284    void XmlReadBasic(Long_t &value);
0285    void XmlReadBasic(Long64_t &value);
0286    void XmlReadBasic(Float_t &value);
0287    void XmlReadBasic(Double_t &value);
0288    void XmlReadBasic(Bool_t &value);
0289    void XmlReadBasic(UChar_t &value);
0290    void XmlReadBasic(UShort_t &value);
0291    void XmlReadBasic(UInt_t &value);
0292    void XmlReadBasic(ULong_t &value);
0293    void XmlReadBasic(ULong64_t &value);
0294    const char *XmlReadValue(const char *name);
0295 
0296    template <typename T>
0297    R__ALWAYS_INLINE void XmlReadArrayContent(T *arr, Int_t arrsize);
0298 
0299    template <typename T>
0300    R__ALWAYS_INLINE Int_t XmlReadArray(T *&arr, bool is_static = false);
0301 
0302    template <typename T>
0303    R__ALWAYS_INLINE void XmlReadFastArray(T *arr, Int_t n);
0304 
0305    template <typename T>
0306    R__ALWAYS_INLINE void XmlWriteArrayContent(const T *arr, Int_t arrsize);
0307 
0308    template <typename T>
0309    R__ALWAYS_INLINE void XmlWriteArray(const T *arr, Int_t arrsize);
0310 
0311    template <typename T>
0312    R__ALWAYS_INLINE void XmlWriteFastArray(const T *arr, Long64_t n);
0313 
0314    XMLNodePointer_t XmlWriteObject(const void *obj, const TClass *objClass, Bool_t cacheReuse);
0315    void *XmlReadObject(void *obj, TClass **cl = nullptr);
0316 
0317    void BeforeIOoperation();
0318    void CheckVersionBuf();
0319 
0320    TXMLEngine *fXML{nullptr};                        ///<! instance of TXMLEngine for working with XML structures
0321    std::deque<std::unique_ptr<TXMLStackObj>> fStack; ///<! Stack of processed objects
0322    Version_t fVersionBuf{-111};                      ///<! Current version buffer
0323    TString fValueBuf;                                ///<! Current value buffer
0324    Int_t fErrorFlag{0};                              ///<! Error flag
0325    Bool_t fCanUseCompact{kFALSE};                    ///<! Flag indicate that basic type (like Int_t) can be placed in the same tag
0326    TClass *fExpectedBaseClass{nullptr};              ///<! Pointer to class, which should be stored as parent of current
0327    Int_t fCompressLevel{0};                          ///<! Compression level and algorithm
0328    Int_t fIOVersion{3};                              ///<! Indicates format of ROOT xml file
0329 
0330    ClassDefOverride(TBufferXML, 0); // a specialized TBuffer to read/write to XML files
0331 };
0332 
0333 //______________________________________________________________________________
0334 inline Int_t TBufferXML::GetCompressionAlgorithm() const
0335 {
0336    return (fCompressLevel < 0) ? -1 : fCompressLevel / 100;
0337 }
0338 
0339 //______________________________________________________________________________
0340 inline Int_t TBufferXML::GetCompressionLevel() const
0341 {
0342    return (fCompressLevel < 0) ? -1 : fCompressLevel % 100;
0343 }
0344 
0345 //______________________________________________________________________________
0346 inline Int_t TBufferXML::GetCompressionSettings() const
0347 {
0348    return (fCompressLevel < 0) ? -1 : fCompressLevel;
0349 }
0350 
0351 #endif