Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TXMLSetup.cxx
Go to the documentation of this file.
1// @(#)root/xml:$Id$
2// Author: Sergey Linev 10.05.2004
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, 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//________________________________________________________________________
13//
14// Class TXMLSetup is used as storage of xml file settings
15// This class is used in TXMLFile and in TXmlBuffer classes.
16// Xml settings can be coded via a string in following format
17//
18// "2xoo"
19// ||| \ .
20// || \ usage of name spaces.
21// | \ usage of DTD;
22// \ storage of TStreamerInfo objects in file;
23// layout of xml file (= 2 - specialized (default), = 3 - generic)
24//
25// For last three boolean parameters "x" means true, "o" - false
26//
27// Such string can be set as argument of TXMLFile constructor. In that
28// case new TXMLFile with such parameters will be created.
29// These settings automatically stored in xml file.
30
31//________________________________________________________________________
32
33#include "TXMLSetup.h"
34
35#include "TROOT.h"
36#include "TList.h"
37#include "TClass.h"
38#include "TStreamerElement.h"
39
40#include <iostream>
41#include <cstdlib>
42
44
45namespace xmlio {
46
47const char *Root = "root";
48const char *Setup = "setup";
49const char *ClassVersion = "version";
50const char *IOVersion = "version";
51const char *OnlyVersion = "Version";
52const char *Ptr = "ptr";
53const char *Ref = "ref";
54const char *Null = "null";
55const char *IdBase = "id";
56const char *Size = "size";
57const char *Xmlobject = "XmlObject";
58const char *Xmlkey = "XmlKey";
59const char *Cycle = "cycle";
60const char *XmlBlock = "XmlBlock";
61const char *Zip = "zip";
62const char *Object = "Object";
63const char *ObjClass = "class";
64const char *Class = "Class";
65const char *Member = "Member";
66const char *Item = "Item";
67const char *Name = "name";
68const char *Title = "title";
69const char *CreateTm = "created";
70const char *ModifyTm = "modified";
71const char *ObjectUUID = "uuid";
72const char *Type = "type";
73const char *Value = "value";
74const char *v = "v";
75const char *cnt = "cnt";
76const char *True = "true";
77const char *False = "false";
78const char *SInfos = "StreamerInfos";
79
80const char *Array = "Array";
81const char *Bool = "Bool_t";
82const char *Char = "Char_t";
83const char *Short = "Short_t";
84const char *Int = "Int_t";
85const char *Long = "Long_t";
86const char *Long64 = "Long64_t";
87const char *Float = "Float_t";
88const char *Double = "Double_t";
89const char *UChar = "UChar_t";
90const char *UShort = "UShort_t";
91const char *UInt = "UInt_t";
92const char *ULong = "ULong_t";
93const char *ULong64 = "ULong64_t";
94const char *String = "string";
95const char *CharStar = "CharStar";
96};
97
98const TString fgROOTDocNameSpaceBase = "https://root.cern.ch/doc/master/";
100
101////////////////////////////////////////////////////////////////////////////////
102/// return default value for XML setup
103
105{
106 return TString("2xoo");
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// set namespace base
111
112void TXMLSetup::SetNameSpaceBase(const char *namespacebase)
113{
114 fgNameSpaceBase = namespacebase;
115}
116
117////////////////////////////////////////////////////////////////////////////////
118/// creates TXMLSetup object getting values from string
119
120TXMLSetup::TXMLSetup(const char *opt)
121{
122 ReadSetupFromStr(opt);
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// copy constructor of TXMLSetup class
127
129 : fXmlLayout(src.fXmlLayout), fStoreStreamerInfos(src.fStoreStreamerInfos), fUseDtd(src.fUseDtd),
130 fUseNamespaces(src.fUseNamespaces)
131{
132}
133
134////////////////////////////////////////////////////////////////////////////////
135/// assign operator
136
138{
141 fUseDtd = rhs.fUseDtd;
143 return *this;
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// return setup values as string
148
150{
151 char setupstr[10] = "2xxx";
152
153 setupstr[0] = char(48 + fXmlLayout);
154 setupstr[1] = fStoreStreamerInfos ? 'x' : 'o';
155 setupstr[2] = fUseDtd ? 'x' : 'o';
156 setupstr[3] = fUseNamespaces ? 'x' : 'o';
157
158 return TString(setupstr);
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// checks if string is valid setup
163
165{
166 if (!setupstr || (strlen(setupstr) != 4))
167 return kFALSE;
168 TString str = setupstr;
169 str.ToLower();
170 if ((str[0] < 48) || (str[0] > 53))
171 return kFALSE;
172 for (int n = 1; n < 4; n++)
173 if ((str[n] != 'o') && (str[n] != 'x'))
174 return kFALSE;
175 return kTRUE;
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// get values from string
180
182{
183 if (!setupstr || (strlen(setupstr) < 4))
184 return kFALSE;
185 Int_t lay = EXMLLayout(setupstr[0] - 48);
186 if (lay == kGeneralized)
188 else
190
191 fStoreStreamerInfos = setupstr[1] == 'x';
192 fUseDtd = kFALSE;
193 fUseNamespaces = setupstr[3] == 'x';
194 return kTRUE;
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// show setup values
199
201{
202 std::cout << " *** Setup printout ***" << std::endl;
203 std::cout << "Attribute mode = " << fXmlLayout << std::endl;
204 std::cout << "Store streamer infos = " << (fStoreStreamerInfos ? "true" : "false") << std::endl;
205 std::cout << "Use dtd = " << (fUseDtd ? "true" : "false") << std::endl;
206 std::cout << "Use name spaces = " << (fUseNamespaces ? "true" : "false") << std::endl;
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// convert class name to exclude any special symbols like ':', '<' '>' ',' and spaces
211
212const char *TXMLSetup::XmlConvertClassName(const char *clname)
213{
214 fStrBuf = clname;
215 fStrBuf.ReplaceAll("<", "_");
216 fStrBuf.ReplaceAll(">", "_");
217 fStrBuf.ReplaceAll(",", "_");
218 fStrBuf.ReplaceAll(" ", "_");
219 fStrBuf.ReplaceAll(":", "_");
220 return fStrBuf.Data();
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// produce string which used as reference in class namespace definition
225
227{
228 TString clname = XmlConvertClassName(cl->GetName());
231 fStrBuf += "class";
232 fStrBuf += clname;
233 fStrBuf += ".html";
234 }
235 else {
236 fStrBuf += clname;
237 }
238 return fStrBuf.Data();
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// return converted name for TStreamerElement
243
245{
246 if (!el)
247 return nullptr;
249 return el->GetName();
250 if (strcmp(el->GetName(), el->GetClassPointer()->GetName()) != 0)
251 return el->GetName();
252 return XmlConvertClassName(el->GetName());
253}
254
255////////////////////////////////////////////////////////////////////////////////
256/// get item name for given element
257
259{
260 if (!el)
261 return nullptr;
262 fStrBuf = el->GetName();
263 fStrBuf += "_item";
264 return fStrBuf.Data();
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// define class for the converted class name, where
269/// special symbols were replaced by '_'
270
271TClass *TXMLSetup::XmlDefineClass(const char *xmlClassName)
272{
273 if (!strchr(xmlClassName, '_'))
274 return TClass::GetClass(xmlClassName);
275
276 TIter iter(gROOT->GetListOfClasses());
277 TClass *cl = nullptr;
278 while ((cl = (TClass *)iter()) != nullptr) {
279 const char *name = XmlConvertClassName(cl->GetName());
280 if (strcmp(xmlClassName, name) == 0)
281 return cl;
282 }
283 return nullptr;
284}
285
286////////////////////////////////////////////////////////////////////////////////
287/// converts string to integer.
288/// if error, returns default value
289
290Int_t TXMLSetup::AtoI(const char *sbuf, Int_t def, const char *errinfo)
291{
292 if (sbuf)
293 return atoi(sbuf);
294 if (errinfo)
295 std::cerr << "<Error in TXMLSetup::AtoI>" << errinfo << " not valid integer: sbuf <NULL>" << std::endl;
296 return def;
297}
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassImp(name)
Definition Rtypes.h:382
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
char name[80]
Definition TGX11.cxx:110
#define gROOT
Definition TROOT.h:406
const TString fgROOTDocNameSpaceBase
Definition TXMLSetup.cxx:98
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2968
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:530
virtual TClass * GetClassPointer() const
Returns a pointer to the TClass of this element.
static TClass * Class()
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
const char * Data() const
Definition TString.h:376
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
Bool_t fUseNamespaces
Definition TXMLSetup.h:128
TClass * XmlDefineClass(const char *xmlClassName)
define class for the converted class name, where special symbols were replaced by '_'
const char * XmlClassNameSpaceRef(const TClass *cl)
produce string which used as reference in class namespace definition
static void SetNameSpaceBase(const char *namespacebase)
set namespace base
Bool_t fUseDtd
Definition TXMLSetup.h:127
const char * XmlConvertClassName(const char *name)
convert class name to exclude any special symbols like ':', '<' '>' ',' and spaces
TString GetSetupAsString()
return setup values as string
Bool_t IsValidXmlSetup(const char *setupstr)
checks if string is valid setup
Bool_t ReadSetupFromStr(const char *setupstr)
get values from string
const char * GetElItemName(TStreamerElement *el)
get item name for given element
Int_t AtoI(const char *sbuf, Int_t def=0, const char *errinfo=nullptr)
converts string to integer.
static TString DefaultXmlSetup()
return default value for XML setup
const char * XmlGetElementName(const TStreamerElement *el)
return converted name for TStreamerElement
TXMLSetup()=default
EXMLLayout fXmlLayout
Definition TXMLSetup.h:125
Bool_t fStoreStreamerInfos
Definition TXMLSetup.h:126
static TString fgNameSpaceBase
buffer, used in XmlDefineClass() function
Definition TXMLSetup.h:134
TString fStrBuf
counter , used to build id of xml references
Definition TXMLSetup.h:132
void PrintSetup()
show setup values
@ kSpecialized
Definition TXMLSetup.h:84
@ kGeneralized
Definition TXMLSetup.h:84
TXMLSetup & operator=(const TXMLSetup &rhs)
assign operator
const Int_t n
Definition legend1.C:16
const char * UChar
Definition TXMLSetup.cxx:89
const char * Root
Definition TXMLSetup.cxx:47
const char * Ptr
Definition TXMLSetup.cxx:52
const char * Name
Definition TXMLSetup.cxx:67
const char * SInfos
Definition TXMLSetup.cxx:78
const char * IOVersion
Definition TXMLSetup.cxx:50
const char * v
Definition TXMLSetup.cxx:74
const char * Bool
Definition TXMLSetup.cxx:81
const char * Xmlobject
Definition TXMLSetup.cxx:57
const char * Long64
Definition TXMLSetup.cxx:86
const char * ModifyTm
Definition TXMLSetup.cxx:70
const char * False
Definition TXMLSetup.cxx:77
const char * True
Definition TXMLSetup.cxx:76
const char * Int
Definition TXMLSetup.cxx:84
const char * ULong64
Definition TXMLSetup.cxx:93
const char * Member
Definition TXMLSetup.cxx:65
const char * OnlyVersion
Definition TXMLSetup.cxx:51
const char * Long
Definition TXMLSetup.cxx:85
const char * Title
Definition TXMLSetup.cxx:68
const char * Float
Definition TXMLSetup.cxx:87
const char * Array
Definition TXMLSetup.cxx:80
const char * ClassVersion
Definition TXMLSetup.cxx:49
const char * String
Definition TXMLSetup.cxx:94
const char * Double
Definition TXMLSetup.cxx:88
const char * Object
Definition TXMLSetup.cxx:62
const char * Ref
Definition TXMLSetup.cxx:53
const char * cnt
Definition TXMLSetup.cxx:75
const char * IdBase
Definition TXMLSetup.cxx:55
const char * Size
Definition TXMLSetup.cxx:56
const char * XmlBlock
Definition TXMLSetup.cxx:60
const char * Cycle
Definition TXMLSetup.cxx:59
const char * Type
Definition TXMLSetup.cxx:72
const char * Null
Definition TXMLSetup.cxx:54
const char * Char
Definition TXMLSetup.cxx:82
const char * UShort
Definition TXMLSetup.cxx:90
const char * CharStar
Definition TXMLSetup.cxx:95
const char * UInt
Definition TXMLSetup.cxx:91
const char * ULong
Definition TXMLSetup.cxx:92
const char * CreateTm
Definition TXMLSetup.cxx:69
const char * Class
Definition TXMLSetup.cxx:64
const char * ObjClass
Definition TXMLSetup.cxx:63
const char * Short
Definition TXMLSetup.cxx:83
const char * Zip
Definition TXMLSetup.cxx:61
const char * Setup
Definition TXMLSetup.cxx:48
const char * ObjectUUID
Definition TXMLSetup.cxx:71
const char * Xmlkey
Definition TXMLSetup.cxx:58
const char * Item
Definition TXMLSetup.cxx:66