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/** \class TRootSnifferStore
16\ingroup http
17
18Used to store different results of objects scanning by TRootSniffer
19*/
20
22
23////////////////////////////////////////////////////////////////////////////////
24/// set pointer on found element, class and number of childs
25
26void TRootSnifferStore::SetResult(void *_res, TClass *_rescl, TDataMember *_resmemb, Int_t _res_chld, Int_t _restr)
27{
28 fResPtr = _res;
29 fResClass = _rescl;
30 fResMember = _resmemb;
31 fResNumChilds = _res_chld;
32 fResRestrict = _restr;
33}
34
35// =================================================================================
36
37/** \class TRootSnifferStoreXml
38\ingroup http
39
40Used to store scanned objects hierarchy in XML form
41*/
42
44
45////////////////////////////////////////////////////////////////////////////////
46/// starts new xml node, will be closed by CloseNode
47
48 void TRootSnifferStoreXml::CreateNode(Int_t lvl, const char *nodename)
49{
50 fBuf.Append(TString::Format("%*s<item _name=\"%s\"", fCompact ? 0 : (lvl + 1) * 2, "", nodename));
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// set field (xml attribute) in current node
55
56void TRootSnifferStoreXml::SetField(Int_t, const char *field, const char *value, Bool_t)
57{
58 if (strpbrk(value, "<>&\'\"") == 0) {
59 fBuf.Append(TString::Format(" %s=\"%s\"", field, value));
60 } else {
61 fBuf.Append(TString::Format(" %s=\"", field));
62 const char *v = value;
63 while (*v != 0) {
64 switch (*v) {
65 case '<': fBuf.Append("&lt;"); break;
66 case '>': fBuf.Append("&gt;"); break;
67 case '&': fBuf.Append("&amp;"); break;
68 case '\'': fBuf.Append("&apos;"); break;
69 case '\"': fBuf.Append("&quot;"); break;
70 default: fBuf.Append(*v); break;
71 }
72 v++;
73 }
74
75 fBuf.Append("\"");
76 }
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// called before next child node created
81
83{
84 if (nchld == 0) fBuf.Append(TString::Format(">%s", (fCompact ? "" : "\n")));
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// Called when node should be closed
89///
90/// depending from number of childs different xml format is applied
91
93{
94 if (numchilds > 0)
95 fBuf.Append(TString::Format("%*s</item>%s", fCompact ? 0 : (lvl + 1) * 2, "", (fCompact ? "" : "\n")));
96 else
97 fBuf.Append(TString::Format("/>%s", (fCompact ? "" : "\n")));
98}
99
100// ============================================================================
101
102/** \class TRootSnifferStoreJson
103\ingroup http
104
105Used to store scanned objects hierarchy in JSON form
106*/
107
109
110////////////////////////////////////////////////////////////////////////////////
111/// starts new json object, will be closed by CloseNode
112
113void TRootSnifferStoreJson::CreateNode(Int_t lvl, const char *nodename)
114{
115 fBuf.Append(TString::Format("%*s{", fCompact ? 0 : lvl * 4, ""));
116 if (!fCompact) fBuf.Append("\n");
117 fBuf.Append(
118 TString::Format("%*s\"_name\"%s\"%s\"", fCompact ? 0 : lvl * 4 + 2, "", (fCompact ? ":" : " : "), nodename));
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// set field (json field) in current node
123
124void TRootSnifferStoreJson::SetField(Int_t lvl, const char *field, const char *value, Bool_t with_quotes)
125{
126 fBuf.Append(",");
127 if (!fCompact) fBuf.Append("\n");
128 fBuf.Append(TString::Format("%*s\"%s\"%s", fCompact ? 0 : lvl * 4 + 2, "", field, (fCompact ? ":" : " : ")));
129 if (!with_quotes) {
131 } else {
132 fBuf.Append("\"");
133 for (const char *v = value; *v != 0; v++) switch (*v) {
134 case '\n': fBuf.Append("\\n"); break;
135 case '\t': fBuf.Append("\\t"); break;
136 case '\"': fBuf.Append("\\\""); break;
137 case '\\': fBuf.Append("\\\\"); break;
138 case '\b': fBuf.Append("\\b"); break;
139 case '\f': fBuf.Append("\\f"); break;
140 case '\r': fBuf.Append("\\r"); break;
141 case '/': fBuf.Append("\\/"); break;
142 default:
143 if ((*v > 31) && (*v < 127))
144 fBuf.Append(*v);
145 else
146 fBuf.Append(TString::Format("\\u%04x", (unsigned)*v));
147 }
148 fBuf.Append("\"");
149 }
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// called before next child node created
154
156{
157 fBuf.Append(",");
158 if (!fCompact) fBuf.Append("\n");
159 if (nchld == 0)
160 fBuf.Append(TString::Format("%*s\"_childs\"%s", (fCompact ? 0 : lvl * 4 + 2), "", (fCompact ? ":[" : " : [\n")));
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// called when node should be closed
165/// depending from number of childs different xml format is applied
166
168{
169 if (numchilds > 0)
170 fBuf.Append(TString::Format("%s%*s]", (fCompact ? "" : "\n"), fCompact ? 0 : lvl * 4 + 2, ""));
171 fBuf.Append(TString::Format("%s%*s}", (fCompact ? "" : "\n"), fCompact ? 0 : lvl * 4, ""));
172}
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
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.
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:574
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:2356