Logo ROOT   6.14/05
Reference Guide
TRootSnifferStore.cxx
Go to the documentation of this file.
1 // $Id$
2 // Author: Sergey Linev 22/12/2013
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2013, 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 #include "TRootSnifferStore.h"
13 
14 //////////////////////////////////////////////////////////////////////////
15 // //
16 // TRootSnifferStore //
17 // //
18 // Used to store different results of objects scanning by TRootSniffer //
19 // //
20 //////////////////////////////////////////////////////////////////////////
21 
23 
24  ////////////////////////////////////////////////////////////////////////////////
25  /// normal constructor
26 
28  : TObject(), fResPtr(0), fResClass(0), fResMember(0), fResNumChilds(-1), fResRestrict(0)
29 {
30 }
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 /// destructor
34 
36 {
37 }
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// set pointer on found element, class and number of childs
41 
42 void TRootSnifferStore::SetResult(void *_res, TClass *_rescl, TDataMember *_resmemb, Int_t _res_chld, Int_t _restr)
43 {
44  fResPtr = _res;
45  fResClass = _rescl;
46  fResMember = _resmemb;
47  fResNumChilds = _res_chld;
48  fResRestrict = _restr;
49 }
50 
51 // =================================================================================
52 
53 //////////////////////////////////////////////////////////////////////////
54 // //
55 // TRootSnifferStoreXml //
56 // //
57 // Used to store scanned objects hierarchy in XML form //
58 // //
59 //////////////////////////////////////////////////////////////////////////
60 
62 
63  ////////////////////////////////////////////////////////////////////////////////
64  /// starts new xml node, will be closed by CloseNode
65 
66  void TRootSnifferStoreXml::CreateNode(Int_t lvl, const char *nodename)
67 {
68  fBuf->Append(TString::Format("%*s<item _name=\"%s\"", fCompact ? 0 : (lvl + 1) * 2, "", nodename));
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// set field (xml attribute) in current node
73 
74 void TRootSnifferStoreXml::SetField(Int_t, const char *field, const char *value, Bool_t)
75 {
76  if (strpbrk(value, "<>&\'\"") == 0) {
77  fBuf->Append(TString::Format(" %s=\"%s\"", field, value));
78  } else {
79  fBuf->Append(TString::Format(" %s=\"", field));
80  const char *v = value;
81  while (*v != 0) {
82  switch (*v) {
83  case '<': fBuf->Append("&lt;"); break;
84  case '>': fBuf->Append("&gt;"); break;
85  case '&': fBuf->Append("&amp;"); break;
86  case '\'': fBuf->Append("&apos;"); break;
87  case '\"': fBuf->Append("&quot;"); break;
88  default: fBuf->Append(*v); break;
89  }
90  v++;
91  }
92 
93  fBuf->Append("\"");
94  }
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// called before next child node created
99 
101 {
102  if (nchld == 0) fBuf->Append(TString::Format(">%s", (fCompact ? "" : "\n")));
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// called when node should be closed
107 /// depending from number of childs different xml format is applied
108 
110 {
111  if (numchilds > 0)
112  fBuf->Append(TString::Format("%*s</item>%s", fCompact ? 0 : (lvl + 1) * 2, "", (fCompact ? "" : "\n")));
113  else
114  fBuf->Append(TString::Format("/>%s", (fCompact ? "" : "\n")));
115 }
116 
117 // ============================================================================
118 
119 //////////////////////////////////////////////////////////////////////////
120 // //
121 // TRootSnifferStoreJson //
122 // //
123 // Used to store scanned objects hierarchy in JSON form //
124 // //
125 //////////////////////////////////////////////////////////////////////////
126 
128 
129  ////////////////////////////////////////////////////////////////////////////////
130  /// starts new json object, will be closed by CloseNode
131 
132  void TRootSnifferStoreJson::CreateNode(Int_t lvl, const char *nodename)
133 {
134  fBuf->Append(TString::Format("%*s{", fCompact ? 0 : lvl * 4, ""));
135  if (!fCompact) fBuf->Append("\n");
136  fBuf->Append(
137  TString::Format("%*s\"_name\"%s\"%s\"", fCompact ? 0 : lvl * 4 + 2, "", (fCompact ? ":" : " : "), nodename));
138 }
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 /// set field (json field) in current node
142 
143 void TRootSnifferStoreJson::SetField(Int_t lvl, const char *field, const char *value, Bool_t with_quotes)
144 {
145  fBuf->Append(",");
146  if (!fCompact) fBuf->Append("\n");
147  fBuf->Append(TString::Format("%*s\"%s\"%s", fCompact ? 0 : lvl * 4 + 2, "", field, (fCompact ? ":" : " : ")));
148  if (!with_quotes) {
149  fBuf->Append(value);
150  } else {
151  fBuf->Append("\"");
152  for (const char *v = value; *v != 0; v++) switch (*v) {
153  case '\n': fBuf->Append("\\n"); break;
154  case '\t': fBuf->Append("\\t"); break;
155  case '\"': fBuf->Append("\\\""); break;
156  case '\\': fBuf->Append("\\\\"); break;
157  case '\b': fBuf->Append("\\b"); break;
158  case '\f': fBuf->Append("\\f"); break;
159  case '\r': fBuf->Append("\\r"); break;
160  case '/': fBuf->Append("\\/"); break;
161  default:
162  if ((*v > 31) && (*v < 127))
163  fBuf->Append(*v);
164  else
165  fBuf->Append(TString::Format("\\u%04x", (unsigned)*v));
166  }
167  fBuf->Append("\"");
168  }
169 }
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 /// called before next child node created
173 
175 {
176  fBuf->Append(",");
177  if (!fCompact) fBuf->Append("\n");
178  if (nchld == 0)
179  fBuf->Append(TString::Format("%*s\"_childs\"%s", (fCompact ? 0 : lvl * 4 + 2), "", (fCompact ? ":[" : " : [\n")));
180 }
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 /// called when node should be closed
184 /// depending from number of childs different xml format is applied
185 
187 {
188  if (numchilds > 0) fBuf->Append(TString::Format("%s%*s]", (fCompact ? "" : "\n"), fCompact ? 0 : lvl * 4 + 2, ""));
189  fBuf->Append(TString::Format("%s%*s}", (fCompact ? "" : "\n"), fCompact ? 0 : lvl * 4, ""));
190 }
void * fResPtr
! pointer on found item
All ROOT classes may have RTTI (run time type identification) support added.
Definition: TDataMember.h:31
Storage of hierarchy scan in TRootSniffer in JSON format.
virtual void CreateNode(Int_t lvl, const char *nodename)
starts new xml node, will be closed by CloseNode
TDataMember * fResMember
! datamember pointer of found item
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Int_t fResRestrict
! restriction for result, 0-default, 1-readonly, 2-full
Int_t fResNumChilds
! count of found childs, -1 by default
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 CreateNode(Int_t lvl, const char *nodename)
starts new json object, will be closed by CloseNode
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
TRootSnifferStore()
normal constructor
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:2286
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:75
virtual void BeforeNextChild(Int_t lvl, Int_t nchld, Int_t)
called before next child node created
#define ClassImp(name)
Definition: Rtypes.h:359
TClass * fResClass
! class of found item
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void SetField(Int_t lvl, const char *field, const char *value, Bool_t)
set field (xml attribute) in current node