12 #ifndef ROOT_TBufferXML
13 #define ROOT_TBufferXML
26 class TVirtualStreamerInfo;
28 class TStreamerElement;
30 class TMemberStreamer;
34 class TBufferXML final :
public TBufferText,
public TXMLSetup {
39 TBufferXML(TBuffer::EMode mode);
40 TBufferXML(TBuffer::EMode mode, TXMLFile *file);
41 virtual ~TBufferXML();
43 static TString ConvertToXML(
const TObject *obj, Bool_t GenericLayout = kFALSE, Bool_t UseNamespaces = kFALSE);
45 ConvertToXML(
const void *obj,
const TClass *cl, Bool_t GenericLayout = kFALSE, Bool_t UseNamespaces = kFALSE);
48 static TString ToXML(
const T *obj, Bool_t GenericLayout = kFALSE, Bool_t UseNamespaces = kFALSE)
50 return ConvertToXML(obj, TClass::GetClass<T>(), GenericLayout, UseNamespaces);
53 static TObject *ConvertFromXML(
const char *str, Bool_t GenericLayout = kFALSE, Bool_t UseNamespaces = kFALSE);
54 static void *ConvertFromXMLAny(
const char *str, TClass **cl =
nullptr, Bool_t GenericLayout = kFALSE,
55 Bool_t UseNamespaces = kFALSE);
58 static Bool_t FromXML(T *&obj,
const char *xml, Bool_t GenericLayout = kFALSE, Bool_t UseNamespaces = kFALSE)
62 obj = (T *)ConvertFromXMLChecked(xml, TClass::GetClass<T>(), GenericLayout, UseNamespaces);
63 return obj !=
nullptr;
66 Int_t GetIOVersion()
const {
return fIOVersion; }
67 void SetIOVersion(Int_t v) { fIOVersion = v; }
71 TClass *ReadClass(
const TClass *cl =
nullptr, UInt_t *objTag =
nullptr) final;
72 void WriteClass(const TClass *cl) final;
76 Version_t ReadVersion(UInt_t *start =
nullptr, UInt_t *bcnt =
nullptr, const TClass *cl =
nullptr) final;
77 UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt = kFALSE) final;
79 void *ReadObjectAny(const TClass *clCast) final;
80 void SkipObjectAny() final;
82 void IncrementLevel(TVirtualStreamerInfo *) final;
83 void SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type) final;
84 void DecrementLevel(TVirtualStreamerInfo *) final;
86 void ClassBegin(const TClass *, Version_t = -1) final;
87 void ClassEnd(const TClass *) final;
88 void ClassMember(const
char *name, const
char *typeName =
nullptr, Int_t arrsize1 = -1, Int_t arrsize2 = -1) final;
90 Int_t ReadArray(Bool_t *&b) final;
91 Int_t ReadArray(Char_t *&c) final;
92 Int_t ReadArray(UChar_t *&c) final;
93 Int_t ReadArray(Short_t *&h) final;
94 Int_t ReadArray(UShort_t *&h) final;
95 Int_t ReadArray(Int_t *&i) final;
96 Int_t ReadArray(UInt_t *&i) final;
97 Int_t ReadArray(Long_t *&l) final;
98 Int_t ReadArray(ULong_t *&l) final;
99 Int_t ReadArray(Long64_t *&l) final;
100 Int_t ReadArray(ULong64_t *&l) final;
101 Int_t ReadArray(Float_t *&f) final;
102 Int_t ReadArray(Double_t *&d) final;
104 Int_t ReadStaticArray(Bool_t *b) final;
105 Int_t ReadStaticArray(Char_t *c) final;
106 Int_t ReadStaticArray(UChar_t *c) final;
107 Int_t ReadStaticArray(Short_t *h) final;
108 Int_t ReadStaticArray(UShort_t *h) final;
109 Int_t ReadStaticArray(Int_t *i) final;
110 Int_t ReadStaticArray(UInt_t *i) final;
111 Int_t ReadStaticArray(Long_t *l) final;
112 Int_t ReadStaticArray(ULong_t *l) final;
113 Int_t ReadStaticArray(Long64_t *l) final;
114 Int_t ReadStaticArray(ULong64_t *l) final;
115 Int_t ReadStaticArray(Float_t *f) final;
116 Int_t ReadStaticArray(Double_t *d) final;
118 void ReadFastArray(Bool_t *b, Int_t n) final;
119 void ReadFastArray(Char_t *c, Int_t n) final;
120 void ReadFastArray(UChar_t *c, Int_t n) final;
121 void ReadFastArray(Short_t *h, Int_t n) final;
122 void ReadFastArray(UShort_t *h, Int_t n) final;
123 void ReadFastArray(Int_t *i, Int_t n) final;
124 void ReadFastArray(UInt_t *i, Int_t n) final;
125 void ReadFastArray(Long_t *l, Int_t n) final;
126 void ReadFastArray(ULong_t *l, Int_t n) final;
127 void ReadFastArray(Long64_t *l, Int_t n) final;
128 void ReadFastArray(ULong64_t *l, Int_t n) final;
129 void ReadFastArray(Float_t *f, Int_t n) final;
130 void ReadFastArray(Double_t *d, Int_t n) final;
131 void ReadFastArrayString(Char_t *c, Int_t n) final;
132 void ReadFastArray(
void *start, const TClass *cl, Int_t n = 1, TMemberStreamer *s =
nullptr,
133 const TClass *onFileClass =
nullptr) final;
134 void ReadFastArray(
void **startp, const TClass *cl, Int_t n = 1, Bool_t isPreAlloc = kFALSE,
135 TMemberStreamer *s =
nullptr, const TClass *onFileClass =
nullptr) final;
137 void WriteArray(const Bool_t *b, Int_t n) final;
138 void WriteArray(const Char_t *c, Int_t n) final;
139 void WriteArray(const UChar_t *c, Int_t n) final;
140 void WriteArray(const Short_t *h, Int_t n) final;
141 void WriteArray(const UShort_t *h, Int_t n) final;
142 void WriteArray(const Int_t *i, Int_t n) final;
143 void WriteArray(const UInt_t *i, Int_t n) final;
144 void WriteArray(const Long_t *l, Int_t n) final;
145 void WriteArray(const ULong_t *l, Int_t n) final;
146 void WriteArray(const Long64_t *l, Int_t n) final;
147 void WriteArray(const ULong64_t *l, Int_t n) final;
148 void WriteArray(const Float_t *f, Int_t n) final;
149 void WriteArray(const Double_t *d, Int_t n) final;
151 void WriteFastArray(const Bool_t *b, Int_t n) final;
152 void WriteFastArray(const Char_t *c, Int_t n) final;
153 void WriteFastArray(const UChar_t *c, Int_t n) final;
154 void WriteFastArray(const Short_t *h, Int_t n) final;
155 void WriteFastArray(const UShort_t *h, Int_t n) final;
156 void WriteFastArray(const Int_t *i, Int_t n) final;
157 void WriteFastArray(const UInt_t *i, Int_t n) final;
158 void WriteFastArray(const Long_t *l, Int_t n) final;
159 void WriteFastArray(const ULong_t *l, Int_t n) final;
160 void WriteFastArray(const Long64_t *l, Int_t n) final;
161 void WriteFastArray(const ULong64_t *l, Int_t n) final;
162 void WriteFastArray(const Float_t *f, Int_t n) final;
163 void WriteFastArray(const Double_t *d, Int_t n) final;
164 void WriteFastArrayString(const Char_t *c, Int_t n) final;
165 void WriteFastArray(
void *start, const TClass *cl, Int_t n = 1, TMemberStreamer *s =
nullptr) final;
166 Int_t WriteFastArray(
void **startp, const TClass *cl, Int_t n = 1, Bool_t isPreAlloc = kFALSE,
167 TMemberStreamer *s =
nullptr) final;
169 void StreamObject(
void *obj, const TClass *cl, const TClass *onFileClass =
nullptr) final;
170 using TBufferText::StreamObject;
172 void ReadBool(Bool_t &b) final;
173 void ReadChar(Char_t &c) final;
174 void ReadUChar(UChar_t &c) final;
175 void ReadShort(Short_t &s) final;
176 void ReadUShort(UShort_t &s) final;
177 void ReadInt(Int_t &i) final;
178 void ReadUInt(UInt_t &i) final;
179 void ReadLong(Long_t &l) final;
180 void ReadULong(ULong_t &l) final;
181 void ReadLong64(Long64_t &l) final;
182 void ReadULong64(ULong64_t &l) final;
183 void ReadFloat(Float_t &f) final;
184 void ReadDouble(Double_t &d) final;
185 void ReadCharP(Char_t *c) final;
186 void ReadTString(TString &s) final;
187 void ReadStdString(std::
string *s) final;
188 using TBuffer::ReadStdString;
189 void ReadCharStar(
char *&s) final;
191 void WriteBool(Bool_t b) final;
192 void WriteChar(Char_t c) final;
193 void WriteUChar(UChar_t c) final;
194 void WriteShort(Short_t s) final;
195 void WriteUShort(UShort_t s) final;
196 void WriteInt(Int_t i) final;
197 void WriteUInt(UInt_t i) final;
198 void WriteLong(Long_t l) final;
199 void WriteULong(ULong_t l) final;
200 void WriteLong64(Long64_t l) final;
201 void WriteULong64(ULong64_t l) final;
202 void WriteFloat(Float_t f) final;
203 void WriteDouble(Double_t d) final;
204 void WriteCharP(const Char_t *c) final;
205 void WriteTString(const TString &s) final;
206 void WriteStdString(const std::
string *s) final;
207 using TBuffer::WriteStdString;
208 void WriteCharStar(
char *s) final;
210 TVirtualStreamerInfo *GetInfo() final;
215 void WriteObjectClass(const
void *actualObjStart, const TClass *actualClass, Bool_t cacheReuse) final;
219 static
void *ConvertFromXMLChecked(const
char *xml, const TClass *expectedClass, Bool_t GenericLayout = kFALSE,
220 Bool_t UseNamespaces = kFALSE);
224 Int_t GetCompressionAlgorithm() const;
225 Int_t GetCompressionLevel() const;
226 Int_t GetCompressionSettings() const;
227 void SetCompressionAlgorithm(Int_t algorithm = ROOT::RCompressionSetting::EAlgorithm::kUseGlobal);
228 void SetCompressionLevel(Int_t level = ROOT::RCompressionSetting::ELevel::kUseMin);
229 void SetCompressionSettings(Int_t settings = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault);
230 void SetXML(TXMLEngine *xml) { fXML = xml; }
232 void XmlWriteBlock(XMLNodePointer_t node);
233 XMLNodePointer_t XmlWriteAny(
const void *obj,
const TClass *cl);
235 void XmlReadBlock(XMLNodePointer_t node);
236 void *XmlReadAny(XMLNodePointer_t node,
void *obj, TClass **cl);
238 TXMLStackObj *PushStack(XMLNodePointer_t current, Bool_t simple = kFALSE);
239 TXMLStackObj *PopStack();
240 void ShiftStack(
const char *info =
nullptr);
242 XMLNodePointer_t StackNode();
243 TXMLStackObj *Stack(UInt_t depth = 0)
245 return (depth < fStack.size()) ? (depth ? fStack[fStack.size() - depth - 1].get() : fStack.back().get()) :
nullptr;
248 void WorkWithClass(TStreamerInfo *info,
const TClass *cl =
nullptr);
249 void WorkWithElement(TStreamerElement *elem, Int_t comp_type);
250 Bool_t VerifyNode(XMLNodePointer_t node,
const char *name,
const char *errinfo =
nullptr);
251 Bool_t VerifyStackNode(
const char *name,
const char *errinfo =
nullptr);
253 Bool_t VerifyAttr(XMLNodePointer_t node,
const char *name,
const char *value,
const char *errinfo =
nullptr);
254 Bool_t VerifyStackAttr(
const char *name,
const char *value,
const char *errinfo =
nullptr);
256 Bool_t ProcessPointer(
const void *ptr, XMLNodePointer_t node);
257 Bool_t ExtractPointer(XMLNodePointer_t node,
void *&ptr, TClass *&cl);
258 void ExtractReference(XMLNodePointer_t node,
const void *ptr,
const TClass *cl);
260 XMLNodePointer_t CreateItemNode(
const char *name);
261 Bool_t VerifyItemNode(
const char *name,
const char *errinfo =
nullptr);
263 void CreateElemNode(
const TStreamerElement *elem);
264 Bool_t VerifyElemNode(
const TStreamerElement *elem);
266 void PerformPreProcessing(
const TStreamerElement *elem, XMLNodePointer_t elemnode);
267 void PerformPostProcessing();
269 XMLNodePointer_t XmlWriteBasic(Char_t value);
270 XMLNodePointer_t XmlWriteBasic(Short_t value);
271 XMLNodePointer_t XmlWriteBasic(Int_t value);
272 XMLNodePointer_t XmlWriteBasic(Long_t value);
273 XMLNodePointer_t XmlWriteBasic(Long64_t value);
274 XMLNodePointer_t XmlWriteBasic(Float_t value);
275 XMLNodePointer_t XmlWriteBasic(Double_t value);
276 XMLNodePointer_t XmlWriteBasic(Bool_t value);
277 XMLNodePointer_t XmlWriteBasic(UChar_t value);
278 XMLNodePointer_t XmlWriteBasic(UShort_t value);
279 XMLNodePointer_t XmlWriteBasic(UInt_t value);
280 XMLNodePointer_t XmlWriteBasic(ULong_t value);
281 XMLNodePointer_t XmlWriteBasic(ULong64_t value);
282 XMLNodePointer_t XmlWriteValue(
const char *value,
const char *name);
284 void XmlReadBasic(Char_t &value);
285 void XmlReadBasic(Short_t &value);
286 void XmlReadBasic(Int_t &value);
287 void XmlReadBasic(Long_t &value);
288 void XmlReadBasic(Long64_t &value);
289 void XmlReadBasic(Float_t &value);
290 void XmlReadBasic(Double_t &value);
291 void XmlReadBasic(Bool_t &value);
292 void XmlReadBasic(UChar_t &value);
293 void XmlReadBasic(UShort_t &value);
294 void XmlReadBasic(UInt_t &value);
295 void XmlReadBasic(ULong_t &value);
296 void XmlReadBasic(ULong64_t &value);
297 const char *XmlReadValue(
const char *name);
299 template <
typename T>
300 R__ALWAYS_INLINE
void XmlReadArrayContent(T *arr, Int_t arrsize);
302 template <
typename T>
303 R__ALWAYS_INLINE Int_t XmlReadArray(T *&arr,
bool is_static =
false);
305 template <
typename T>
306 R__ALWAYS_INLINE
void XmlReadFastArray(T *arr, Int_t n);
308 template <
typename T>
309 R__ALWAYS_INLINE
void XmlWriteArrayContent(
const T *arr, Int_t arrsize);
311 template <
typename T>
312 R__ALWAYS_INLINE
void XmlWriteArray(
const T *arr, Int_t arrsize);
314 template <
typename T>
315 R__ALWAYS_INLINE
void XmlWriteFastArray(
const T *arr, Int_t n);
317 XMLNodePointer_t XmlWriteObject(
const void *obj,
const TClass *objClass, Bool_t cacheReuse);
318 void *XmlReadObject(
void *obj, TClass **cl =
nullptr);
320 void BeforeIOoperation();
321 void CheckVersionBuf();
323 TXMLEngine *fXML{
nullptr};
324 std::deque<std::unique_ptr<TXMLStackObj>> fStack;
325 Version_t fVersionBuf{-111};
328 Bool_t fCanUseCompact{kFALSE};
329 TClass *fExpectedBaseClass{
nullptr};
330 Int_t fCompressLevel{0};
333 ClassDefOverride(TBufferXML, 0);
337 inline Int_t TBufferXML::GetCompressionAlgorithm()
const
339 return (fCompressLevel < 0) ? -1 : fCompressLevel / 100;
343 inline Int_t TBufferXML::GetCompressionLevel()
const
345 return (fCompressLevel < 0) ? -1 : fCompressLevel % 100;
349 inline Int_t TBufferXML::GetCompressionSettings()
const
351 return (fCompressLevel < 0) ? -1 : fCompressLevel;