Logo ROOT  
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 /// set pointer on found element, class and number of childs
26 
27 void TRootSnifferStore::SetResult(void *_res, TClass *_rescl, TDataMember *_resmemb, Int_t _res_chld, Int_t _restr)
28 {
29  fResPtr = _res;
30  fResClass = _rescl;
31  fResMember = _resmemb;
32  fResNumChilds = _res_chld;
33  fResRestrict = _restr;
34 }
35 
36 // =================================================================================
37 
38 //////////////////////////////////////////////////////////////////////////
39 // //
40 // TRootSnifferStoreXml //
41 // //
42 // Used to store scanned objects hierarchy in XML form //
43 // //
44 //////////////////////////////////////////////////////////////////////////
45 
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// starts new xml node, will be closed by CloseNode
50 
51  void TRootSnifferStoreXml::CreateNode(Int_t lvl, const char *nodename)
52 {
53  fBuf.Append(TString::Format("%*s<item _name=\"%s\"", fCompact ? 0 : (lvl + 1) * 2, "", nodename));
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// set field (xml attribute) in current node
58 
59 void TRootSnifferStoreXml::SetField(Int_t, const char *field, const char *value, Bool_t)
60 {
61  if (strpbrk(value, "<>&\'\"") == 0) {
62  fBuf.Append(TString::Format(" %s=\"%s\"", field, value));
63  } else {
64  fBuf.Append(TString::Format(" %s=\"", field));
65  const char *v = value;
66  while (*v != 0) {
67  switch (*v) {
68  case '<': fBuf.Append("&lt;"); break;
69  case '>': fBuf.Append("&gt;"); break;
70  case '&': fBuf.Append("&amp;"); break;
71  case '\'': fBuf.Append("&apos;"); break;
72  case '\"': fBuf.Append("&quot;"); break;
73  default: fBuf.Append(*v); break;
74  }
75  v++;
76  }
77 
78  fBuf.Append("\"");
79  }
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// called before next child node created
84 
86 {
87  if (nchld == 0) fBuf.Append(TString::Format(">%s", (fCompact ? "" : "\n")));
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// called when node should be closed
92 /// depending from number of childs different xml format is applied
93 
95 {
96  if (numchilds > 0)
97  fBuf.Append(TString::Format("%*s</item>%s", fCompact ? 0 : (lvl + 1) * 2, "", (fCompact ? "" : "\n")));
98  else
99  fBuf.Append(TString::Format("/>%s", (fCompact ? "" : "\n")));
100 }
101 
102 // ============================================================================
103 
104 //////////////////////////////////////////////////////////////////////////
105 // //
106 // TRootSnifferStoreJson //
107 // //
108 // Used to store scanned objects hierarchy in JSON form //
109 // //
110 //////////////////////////////////////////////////////////////////////////
111 
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// starts new json object, will be closed by CloseNode
116 
117 void TRootSnifferStoreJson::CreateNode(Int_t lvl, const char *nodename)
118 {
119  fBuf.Append(TString::Format("%*s{", fCompact ? 0 : lvl * 4, ""));
120  if (!fCompact) fBuf.Append("\n");
121  fBuf.Append(
122  TString::Format("%*s\"_name\"%s\"%s\"", fCompact ? 0 : lvl * 4 + 2, "", (fCompact ? ":" : " : "), nodename));
123 }
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// set field (json field) in current node
127 
128 void TRootSnifferStoreJson::SetField(Int_t lvl, const char *field, const char *value, Bool_t with_quotes)
129 {
130  fBuf.Append(",");
131  if (!fCompact) fBuf.Append("\n");
132  fBuf.Append(TString::Format("%*s\"%s\"%s", fCompact ? 0 : lvl * 4 + 2, "", field, (fCompact ? ":" : " : ")));
133  if (!with_quotes) {
134  fBuf.Append(value);
135  } else {
136  fBuf.Append("\"");
137  for (const char *v = value; *v != 0; v++) switch (*v) {
138  case '\n': fBuf.Append("\\n"); break;
139  case '\t': fBuf.Append("\\t"); break;
140  case '\"': fBuf.Append("\\\""); break;
141  case '\\': fBuf.Append("\\\\"); break;
142  case '\b': fBuf.Append("\\b"); break;
143  case '\f': fBuf.Append("\\f"); break;
144  case '\r': fBuf.Append("\\r"); break;
145  case '/': fBuf.Append("\\/"); break;
146  default:
147  if ((*v > 31) && (*v < 127))
148  fBuf.Append(*v);
149  else
150  fBuf.Append(TString::Format("\\u%04x", (unsigned)*v));
151  }
152  fBuf.Append("\"");
153  }
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// called before next child node created
158 
160 {
161  fBuf.Append(",");
162  if (!fCompact) fBuf.Append("\n");
163  if (nchld == 0)
164  fBuf.Append(TString::Format("%*s\"_childs\"%s", (fCompact ? 0 : lvl * 4 + 2), "", (fCompact ? ":[" : " : [\n")));
165 }
166 
167 ////////////////////////////////////////////////////////////////////////////////
168 /// called when node should be closed
169 /// depending from number of childs different xml format is applied
170 
172 {
173  if (numchilds > 0)
174  fBuf.Append(TString::Format("%s%*s]", (fCompact ? "" : "\n"), fCompact ? 0 : lvl * 4 + 2, ""));
175  fBuf.Append(TString::Format("%s%*s}", (fCompact ? "" : "\n"), fCompact ? 0 : lvl * 4, ""));
176 }
TRootSnifferStore::fResClass
TClass * fResClass
! class of found item
Definition: TRootSnifferStore.h:27
TRootSnifferStoreXml::SetField
void SetField(Int_t lvl, const char *field, const char *value, Bool_t) final
set field (xml attribute) in current node
Definition: TRootSnifferStore.cxx:59
TRootSnifferStore::fResMember
TDataMember * fResMember
! datamember pointer of found item
Definition: TRootSnifferStore.h:28
TRootSnifferStore::fResNumChilds
Int_t fResNumChilds
! count of found childs, -1 by default
Definition: TRootSnifferStore.h:29
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TRootSnifferStore
Abstract interface for storage of hierarchy scan in TRootSniffer.
Definition: TRootSnifferStore.h:24
TRootSnifferStoreJson::SetField
void SetField(Int_t lvl, const char *field, const char *value, Bool_t with_quotes) final
set field (json field) in current node
Definition: TRootSnifferStore.cxx:128
TDataMember
All ROOT classes may have RTTI (run time type identification) support added.
Definition: TDataMember.h:31
TRootSnifferStoreXml::CloseNode
void CloseNode(Int_t lvl, Int_t numchilds) final
called when node should be closed depending from number of childs different xml format is applied
Definition: TRootSnifferStore.cxx:94
TRootSnifferStoreXml::fCompact
Bool_t fCompact
! produce compact xml code
Definition: TRootSnifferStore.h:58
TString::Format
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:2311
v
@ v
Definition: rootcling_impl.cxx:3635
bool
TRootSnifferStoreJson::CloseNode
void CloseNode(Int_t lvl, Int_t numchilds) final
called when node should be closed depending from number of childs different xml format is applied
Definition: TRootSnifferStore.cxx:171
TRootSnifferStore::fResRestrict
Int_t fResRestrict
! restriction for result, 0-default, 1-readonly, 2-full
Definition: TRootSnifferStore.h:30
TRootSnifferStoreJson::fBuf
TString & fBuf
! output buffer
Definition: TRootSnifferStore.h:81
TRootSnifferStoreXml::fBuf
TString & fBuf
! output buffer
Definition: TRootSnifferStore.h:57
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
TRootSnifferStoreJson::fCompact
Bool_t fCompact
! produce compact json code
Definition: TRootSnifferStore.h:82
TRootSnifferStoreXml::BeforeNextChild
void BeforeNextChild(Int_t lvl, Int_t nchld, Int_t) final
called before next child node created
Definition: TRootSnifferStore.cxx:85
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TRootSnifferStore::SetResult
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
Definition: TRootSnifferStore.cxx:27
TRootSnifferStoreJson
Storage of hierarchy scan in TRootSniffer in JSON format.
Definition: TRootSnifferStore.h:79
TRootSnifferStoreXml::CreateNode
void CreateNode(Int_t lvl, const char *nodename) final
starts new xml node, will be closed by CloseNode
Definition: TRootSnifferStore.cxx:51
TRootSnifferStoreJson::CreateNode
void CreateNode(Int_t lvl, const char *nodename) final
starts new json object, will be closed by CloseNode
Definition: TRootSnifferStore.cxx:117
TRootSnifferStoreJson::BeforeNextChild
void BeforeNextChild(Int_t lvl, Int_t nchld, Int_t nfld) final
called before next child node created
Definition: TRootSnifferStore.cxx:159
TRootSnifferStore::fResPtr
void * fResPtr
! pointer on found item
Definition: TRootSnifferStore.h:26
TRootSnifferStore.h
TRootSnifferStoreXml
Storage of hierarchy scan in TRootSniffer in XML format.
Definition: TRootSnifferStore.h:55
int