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
0002
0003
0004
0005
0006
0007
0008
0009
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
0069
0070 TClass *ReadClass(const TClass *cl = nullptr, UInt_t *objTag = nullptr) final;
0071 void WriteClass(const TClass *cl) final;
0072
0073
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
0213
0214 void WriteObjectClass(const void *actualObjStart, const TClass *actualClass, Bool_t cacheReuse) final;
0215
0216
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 void XmlWriteBlock(XMLNodePointer_t node);
0232 XMLNodePointer_t XmlWriteAny(const void *obj, const TClass *cl);
0233
0234 void XmlReadBlock(XMLNodePointer_t node);
0235 void *XmlReadAny(XMLNodePointer_t node, void *obj, TClass **cl);
0236
0237 TXMLStackObj *PushStack(XMLNodePointer_t current, Bool_t simple = kFALSE);
0238 TXMLStackObj *PopStack();
0239 void ShiftStack(const char *info = nullptr);
0240
0241 XMLNodePointer_t StackNode();
0242 TXMLStackObj *Stack(UInt_t depth = 0)
0243 {
0244 return (depth < fStack.size()) ? (depth ? fStack[fStack.size() - depth - 1].get() : fStack.back().get()) : nullptr;
0245 }
0246
0247 void WorkWithClass(TStreamerInfo *info, const TClass *cl = nullptr);
0248 void WorkWithElement(TStreamerElement *elem, Int_t comp_type);
0249 Bool_t VerifyNode(XMLNodePointer_t node, const char *name, const char *errinfo = nullptr);
0250 Bool_t VerifyStackNode(const char *name, const char *errinfo = nullptr);
0251
0252 Bool_t VerifyAttr(XMLNodePointer_t node, const char *name, const char *value, const char *errinfo = nullptr);
0253 Bool_t VerifyStackAttr(const char *name, const char *value, const char *errinfo = nullptr);
0254
0255 Bool_t ProcessPointer(const void *ptr, XMLNodePointer_t node);
0256 Bool_t ExtractPointer(XMLNodePointer_t node, void *&ptr, TClass *&cl);
0257 void ExtractReference(XMLNodePointer_t node, const void *ptr, const TClass *cl);
0258
0259 XMLNodePointer_t CreateItemNode(const char *name);
0260 Bool_t VerifyItemNode(const char *name, const char *errinfo = nullptr);
0261
0262 void CreateElemNode(const TStreamerElement *elem);
0263 Bool_t VerifyElemNode(const TStreamerElement *elem);
0264
0265 void PerformPreProcessing(const TStreamerElement *elem, XMLNodePointer_t elemnode);
0266 void PerformPostProcessing();
0267
0268 XMLNodePointer_t XmlWriteBasic(Char_t value);
0269 XMLNodePointer_t XmlWriteBasic(Short_t value);
0270 XMLNodePointer_t XmlWriteBasic(Int_t value);
0271 XMLNodePointer_t XmlWriteBasic(Long_t value);
0272 XMLNodePointer_t XmlWriteBasic(Long64_t value);
0273 XMLNodePointer_t XmlWriteBasic(Float_t value);
0274 XMLNodePointer_t XmlWriteBasic(Double_t value);
0275 XMLNodePointer_t XmlWriteBasic(Bool_t value);
0276 XMLNodePointer_t XmlWriteBasic(UChar_t value);
0277 XMLNodePointer_t XmlWriteBasic(UShort_t value);
0278 XMLNodePointer_t XmlWriteBasic(UInt_t value);
0279 XMLNodePointer_t XmlWriteBasic(ULong_t value);
0280 XMLNodePointer_t XmlWriteBasic(ULong64_t value);
0281 XMLNodePointer_t XmlWriteValue(const char *value, const char *name);
0282
0283 void XmlReadBasic(Char_t &value);
0284 void XmlReadBasic(Short_t &value);
0285 void XmlReadBasic(Int_t &value);
0286 void XmlReadBasic(Long_t &value);
0287 void XmlReadBasic(Long64_t &value);
0288 void XmlReadBasic(Float_t &value);
0289 void XmlReadBasic(Double_t &value);
0290 void XmlReadBasic(Bool_t &value);
0291 void XmlReadBasic(UChar_t &value);
0292 void XmlReadBasic(UShort_t &value);
0293 void XmlReadBasic(UInt_t &value);
0294 void XmlReadBasic(ULong_t &value);
0295 void XmlReadBasic(ULong64_t &value);
0296 const char *XmlReadValue(const char *name);
0297
0298 template <typename T>
0299 R__ALWAYS_INLINE void XmlReadArrayContent(T *arr, Int_t arrsize);
0300
0301 template <typename T>
0302 R__ALWAYS_INLINE Int_t XmlReadArray(T *&arr, bool is_static = false);
0303
0304 template <typename T>
0305 R__ALWAYS_INLINE void XmlReadFastArray(T *arr, Int_t n);
0306
0307 template <typename T>
0308 R__ALWAYS_INLINE void XmlWriteArrayContent(const T *arr, Int_t arrsize);
0309
0310 template <typename T>
0311 R__ALWAYS_INLINE void XmlWriteArray(const T *arr, Int_t arrsize);
0312
0313 template <typename T>
0314 R__ALWAYS_INLINE void XmlWriteFastArray(const T *arr, Long64_t n);
0315
0316 XMLNodePointer_t XmlWriteObject(const void *obj, const TClass *objClass, Bool_t cacheReuse);
0317 void *XmlReadObject(void *obj, TClass **cl = nullptr);
0318
0319 void BeforeIOoperation();
0320 void CheckVersionBuf();
0321
0322 TXMLEngine *fXML{nullptr};
0323 std::deque<std::unique_ptr<TXMLStackObj>> fStack;
0324 Version_t fVersionBuf{-111};
0325 TString fValueBuf;
0326 Int_t fErrorFlag{0};
0327 Bool_t fCanUseCompact{kFALSE};
0328 TClass *fExpectedBaseClass{nullptr};
0329 Int_t fCompressLevel{0};
0330 Int_t fIOVersion{3};
0331
0332 ClassDefOverride(TBufferXML, 0);
0333 };
0334
0335
0336 inline Int_t TBufferXML::GetCompressionAlgorithm() const
0337 {
0338 return (fCompressLevel < 0) ? -1 : fCompressLevel / 100;
0339 }
0340
0341
0342 inline Int_t TBufferXML::GetCompressionLevel() const
0343 {
0344 return (fCompressLevel < 0) ? -1 : fCompressLevel % 100;
0345 }
0346
0347
0348 inline Int_t TBufferXML::GetCompressionSettings() const
0349 {
0350 return (fCompressLevel < 0) ? -1 : fCompressLevel;
0351 }
0352
0353 #endif