Logo ROOT   6.08/07
Reference Guide
TRootSnifferStore.cxx
Go to the documentation of this file.
1 #include "TRootSnifferStore.h"
2 
3 //////////////////////////////////////////////////////////////////////////
4 // //
5 // TRootSnifferStore //
6 // //
7 // Used to store different results of objects scanning by TRootSniffer //
8 // //
9 //////////////////////////////////////////////////////////////////////////
10 
12 
13 ////////////////////////////////////////////////////////////////////////////////
14 /// normal constructor
15 
17  TObject(),
18  fResPtr(0),
19  fResClass(0),
20  fResMember(0),
21  fResNumChilds(-1),
22  fResRestrict(0)
23 {
24 }
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// destructor
28 
30 {
31 }
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// set pointer on found element, class and number of childs
35 
36 void TRootSnifferStore::SetResult(void *_res, TClass *_rescl,
37  TDataMember *_resmemb, Int_t _res_chld, Int_t _restr)
38 {
39  fResPtr = _res;
40  fResClass = _rescl;
41  fResMember = _resmemb;
42  fResNumChilds = _res_chld;
43  fResRestrict = _restr;
44 }
45 
46 // =================================================================================
47 
48 //////////////////////////////////////////////////////////////////////////
49 // //
50 // TRootSnifferStoreXml //
51 // //
52 // Used to store scanned objects hierarchy in XML form //
53 // //
54 //////////////////////////////////////////////////////////////////////////
55 
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// starts new xml node, will be closed by CloseNode
60 
61 void TRootSnifferStoreXml::CreateNode(Int_t lvl, const char *nodename)
62 {
63  fBuf->Append(TString::Format("%*s<item _name=\"%s\"", fCompact ? 0 : (lvl + 1) * 2, "", nodename));
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// set field (xml attribute) in current node
68 
69 void TRootSnifferStoreXml::SetField(Int_t, const char *field, const char *value,
70  Bool_t)
71 {
72  if (strpbrk(value, "<>&\'\"") == 0) {
73  fBuf->Append(TString::Format(" %s=\"%s\"", field, value));
74  } else {
75  fBuf->Append(TString::Format(" %s=\"", field));
76  const char *v = value;
77  while (*v != 0) {
78  switch (*v) {
79  case '<' :
80  fBuf->Append("&lt;");
81  break;
82  case '>' :
83  fBuf->Append("&gt;");
84  break;
85  case '&' :
86  fBuf->Append("&amp;");
87  break;
88  case '\'' :
89  fBuf->Append("&apos;");
90  break;
91  case '\"' :
92  fBuf->Append("&quot;");
93  break;
94  default:
95  fBuf->Append(*v);
96  break;
97  }
98  v++;
99  }
100 
101  fBuf->Append("\"");
102  }
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// called before next child node created
107 
109 {
110  if (nchld == 0) fBuf->Append(TString::Format(">%s", (fCompact ? "" : "\n")));
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// called when node should be closed
115 /// depending from number of childs different xml format is applied
116 
118 {
119  if (numchilds > 0)
120  fBuf->Append(TString::Format("%*s</item>%s", fCompact ? 0 : (lvl + 1) * 2, "", (fCompact ? "" : "\n")));
121  else
122  fBuf->Append(TString::Format("/>%s", (fCompact ? "" : "\n")));
123 }
124 
125 // ============================================================================
126 
127 //////////////////////////////////////////////////////////////////////////
128 // //
129 // TRootSnifferStoreJson //
130 // //
131 // Used to store scanned objects hierarchy in JSON form //
132 // //
133 //////////////////////////////////////////////////////////////////////////
134 
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// starts new json object, will be closed by CloseNode
139 
140 void TRootSnifferStoreJson::CreateNode(Int_t lvl, const char *nodename)
141 {
142  fBuf->Append(TString::Format("%*s{", fCompact ? 0 : lvl * 4, ""));
143  if (!fCompact) fBuf->Append("\n");
144  fBuf->Append(TString::Format("%*s\"_name\"%s\"%s\"", fCompact ? 0 : lvl * 4 + 2, "", (fCompact ? ":" : " : "), nodename));
145 }
146 
147 ////////////////////////////////////////////////////////////////////////////////
148 /// set field (json field) in current node
149 
150 void TRootSnifferStoreJson::SetField(Int_t lvl, const char *field,
151  const char *value, Bool_t with_quotes)
152 {
153  fBuf->Append(",");
154  if (!fCompact) fBuf->Append("\n");
155  fBuf->Append(TString::Format("%*s\"%s\"%s", fCompact ? 0 : lvl * 4 + 2, "", field, (fCompact ? ":" : " : ")));
156  if (!with_quotes) {
157  fBuf->Append(value);
158  } else {
159  fBuf->Append("\"");
160  for (const char *v = value; *v != 0; v++)
161  switch (*v) {
162  case '\n':
163  fBuf->Append("\\n");
164  break;
165  case '\t':
166  fBuf->Append("\\t");
167  break;
168  case '\"':
169  fBuf->Append("\\\"");
170  break;
171  case '\\':
172  fBuf->Append("\\\\");
173  break;
174  case '\b':
175  fBuf->Append("\\b");
176  break;
177  case '\f':
178  fBuf->Append("\\f");
179  break;
180  case '\r':
181  fBuf->Append("\\r");
182  break;
183  case '/':
184  fBuf->Append("\\/");
185  break;
186  default:
187  if ((*v > 31) && (*v < 127))
188  fBuf->Append(*v);
189  else
190  fBuf->Append(TString::Format("\\u%04x", (unsigned) *v));
191  }
192  fBuf->Append("\"");
193  }
194 }
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// called before next child node created
198 
200 {
201  fBuf->Append(",");
202  if (!fCompact) fBuf->Append("\n");
203  if (nchld == 0)
204  fBuf->Append(TString::Format("%*s\"_childs\"%s", (fCompact ? 0 : lvl * 4 + 2), "", (fCompact ? ":[" : " : [\n")));
205 }
206 
207 ////////////////////////////////////////////////////////////////////////////////
208 /// called when node should be closed
209 /// depending from number of childs different xml format is applied
210 
212 {
213  if (numchilds > 0)
214  fBuf->Append(TString::Format("%s%*s]", (fCompact ? "" : "\n"), fCompact ? 0 : lvl * 4 + 2, ""));
215  fBuf->Append(TString::Format("%s%*s}", (fCompact ? "" : "\n"), fCompact ? 0 : lvl * 4, ""));
216 }
217 
All ROOT classes may have RTTI (run time type identification) support added.
Definition: TDataMember.h:33
Storage of hierarchy scan in TRootSniffer in JSON format.
TDataMember * fResMember
class of found item
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Int_t fResRestrict
count of found childs, -1 by default
Int_t fResNumChilds
datamember pointer of found item
Abstract interface for storage of hierarchy scan in TRootSniffer.
virtual void BeforeNextChild(Int_t lvl, Int_t nchld, Int_t nfld)
called before next child node created
virtual void CloseNode(Int_t lvl, Int_t numchilds)
called when node should be closed depending from number of childs different xml format is applied ...
virtual ~TRootSnifferStore()
destructor
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2335
virtual void CloseNode(Int_t lvl, Int_t numchilds)
called when node should be closed depending from number of childs different xml format is applied ...
virtual void SetField(Int_t lvl, const char *field, const char *value, Bool_t with_quotes)
set field (json field) in current node
Storage of hierarchy scan in TRootSniffer in XML format.
void SetResult(void *_res, TClass *_rescl, TDataMember *_resmemb, Int_t _res_chld, Int_t restr=0)
set pointer on found element, class and number of childs
SVector< double, 2 > v
Definition: Dict.h:5
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
virtual void BeforeNextChild(Int_t lvl, Int_t nchld, Int_t)
called before next child node created
#define ClassImp(name)
Definition: Rtypes.h:279
TClass * fResClass
pointer on found item
virtual void CreateNode(Int_t, const char *)
Mother of all ROOT objects.
Definition: TObject.h:37
typedef void((*Func_t)())
virtual void SetField(Int_t lvl, const char *field, const char *value, Bool_t)
set field (xml attribute) in current node