Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
27void 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
59void 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
117void 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
128void 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}
#define ClassImp(name)
Definition Rtypes.h:364
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
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.
void CreateNode(Int_t lvl, const char *nodename) final
starts new json object, will be closed by 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
void SetField(Int_t lvl, const char *field, const char *value, Bool_t with_quotes) final
set field (json field) in current node
TString & fBuf
! output buffer
void BeforeNextChild(Int_t lvl, Int_t nchld, Int_t nfld) final
called before next child node created
Bool_t fCompact
! produce compact json code
Storage of hierarchy scan in TRootSniffer in XML format.
void SetField(Int_t lvl, const char *field, const char *value, Bool_t) final
set field (xml attribute) in current node
Bool_t fCompact
! produce compact xml code
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
TString & fBuf
! output buffer
void CreateNode(Int_t lvl, const char *nodename) final
starts new xml node, will be closed by CloseNode
void BeforeNextChild(Int_t lvl, Int_t nchld, Int_t) final
called before next child node created
Abstract interface for storage of hierarchy scan in TRootSniffer.
TClass * fResClass
! class of found item
Int_t fResRestrict
! restriction for result, 0-default, 1-readonly, 2-full
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
void * fResPtr
! pointer on found item
TDataMember * fResMember
! datamember pointer of found item
Int_t fResNumChilds
! count of found childs, -1 by default
TString & Append(const char *cs)
Definition TString.h:564
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:2336