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
21
22////////////////////////////////////////////////////////////////////////////////
23/// set pointer on found element, class and number of childs
24
33
34// =================================================================================
35
36/** \class TRootSnifferStoreXml
37\ingroup http
38
39Used to store scanned objects hierarchy in XML form
40*/
41
42
43////////////////////////////////////////////////////////////////////////////////
44/// starts new xml node, will be closed by CloseNode
45
47{
48 fBuf.Append(TString::Format("%*s<item _name=\"%s\"", fCompact ? 0 : (lvl + 1) * 2, "", nodename));
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// set field (xml attribute) in current node
53
54void TRootSnifferStoreXml::SetField(Int_t, const char *field, const char *value, Bool_t)
55{
56 if (strpbrk(value, "<>&\'\"") == 0) {
57 fBuf.Append(TString::Format(" %s=\"%s\"", field, value));
58 } else {
59 fBuf.Append(TString::Format(" %s=\"", field));
60 const char *v = value;
61 while (*v) {
62 switch (*v) {
63 case '<': fBuf.Append("&lt;"); break;
64 case '>': fBuf.Append("&gt;"); break;
65 case '&': fBuf.Append("&amp;"); break;
66 case '\'': fBuf.Append("&apos;"); break;
67 case '\"': fBuf.Append("&quot;"); break;
68 default: fBuf.Append(*v); break;
69 }
70 v++;
71 }
72
73 fBuf.Append("\"");
74 }
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// called before next child node created
79
84
85////////////////////////////////////////////////////////////////////////////////
86/// Called when node should be closed
87///
88/// depending from number of childs different xml format is applied
89
91{
92 if (numchilds > 0)
93 fBuf.Append(TString::Format("%*s</item>%s", fCompact ? 0 : (lvl + 1) * 2, "", (fCompact ? "" : "\n")));
94 else
95 fBuf.Append(TString::Format("/>%s", (fCompact ? "" : "\n")));
96}
97
98// ============================================================================
99
100/** \class TRootSnifferStoreJson
101\ingroup http
102
103Used to store scanned objects hierarchy in JSON form
104*/
105
106
107////////////////////////////////////////////////////////////////////////////////
108/// starts new json object, will be closed by CloseNode
109
111{
112 fBuf.Append(TString::Format("%*s{", fCompact ? 0 : lvl * 4, ""));
113 if (!fCompact) fBuf.Append("\n");
114 fBuf.Append(
115 TString::Format("%*s\"_name\"%s\"%s\"", fCompact ? 0 : lvl * 4 + 2, "", (fCompact ? ":" : " : "), nodename));
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// set field (json field) in current node
120
122{
123 fBuf.Append(",");
124 if (!fCompact)
125 fBuf.Append("\n");
126 fBuf.Append(TString::Format("%*s\"%s\"%s", fCompact ? 0 : lvl * 4 + 2, "", field, (fCompact ? ":" : " : ")));
127 if (!with_quotes) {
129 } else {
130 fBuf.Append("\"");
131 for (const char *v = value; *v != 0; v++)
132 switch (*v) {
133 case '\n': fBuf.Append("\\n"); break;
134 case '\t': fBuf.Append("\\t"); break;
135 case '\"': fBuf.Append("\\\""); break;
136 case '\\': fBuf.Append("\\\\"); break;
137 case '\b': fBuf.Append("\\b"); break;
138 case '\f': fBuf.Append("\\f"); break;
139 case '\r': fBuf.Append("\\r"); break;
140 case '/': fBuf.Append("\\/"); break;
141 default:
142 if ((*v > 31) && (*v < 127))
143 fBuf.Append(*v);
144 else
145 fBuf.Append(TString::Format("\\u%04x", (unsigned)*v));
146 }
147 fBuf.Append("\"");
148 }
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// called before next child node created
153
155{
156 fBuf.Append(",");
157 if (!fCompact) fBuf.Append("\n");
158 if (nchld == 0)
159 fBuf.Append(TString::Format("%*s\"_childs\"%s", (fCompact ? 0 : lvl * 4 + 2), "", (fCompact ? ":[" : " : [\n")));
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// called when node should be closed
164/// depending from number of childs different xml format is applied
165
167{
168 if (numchilds > 0)
169 fBuf.Append(TString::Format("%s%*s]", (fCompact ? "" : "\n"), fCompact ? 0 : lvl * 4 + 2, ""));
170 fBuf.Append(TString::Format("%s%*s}", (fCompact ? "" : "\n"), fCompact ? 0 : lvl * 4, ""));
171}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:84
All ROOT classes may have RTTI (run time type identification) support added.
Definition TDataMember.h:31
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
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
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:580
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:2384