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
17Used to store different results of objects scanning by TRootSniffer
18*/
19
20
21////////////////////////////////////////////////////////////////////////////////
22/// set pointer on found element, class and number of childs
23
32
33// =================================================================================
34
35/** \class TRootSnifferStoreXml
36
37Used to store scanned objects hierarchy in XML form
38*/
39
40
41////////////////////////////////////////////////////////////////////////////////
42/// starts new xml node, will be closed by CloseNode
43
45{
46 fBuf.Append(TString::Format("%*s<item _name=\"%s\"", fCompact ? 0 : (lvl + 1) * 2, "", nodename));
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// set field (xml attribute) in current node
51
52void TRootSnifferStoreXml::SetField(Int_t, const char *field, const char *value, Bool_t)
53{
54 if (strpbrk(value, "<>&\'\"") == 0) {
55 fBuf.Append(TString::Format(" %s=\"%s\"", field, value));
56 } else {
57 fBuf.Append(TString::Format(" %s=\"", field));
58 const char *v = value;
59 while (*v) {
60 switch (*v) {
61 case '<': fBuf.Append("&lt;"); break;
62 case '>': fBuf.Append("&gt;"); break;
63 case '&': fBuf.Append("&amp;"); break;
64 case '\'': fBuf.Append("&apos;"); break;
65 case '\"': fBuf.Append("&quot;"); break;
66 default: fBuf.Append(*v); break;
67 }
68 v++;
69 }
70
71 fBuf.Append("\"");
72 }
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// called before next child node created
77
82
83////////////////////////////////////////////////////////////////////////////////
84/// Called when node should be closed
85///
86/// depending from number of childs different xml format is applied
87
89{
90 if (numchilds > 0)
91 fBuf.Append(TString::Format("%*s</item>%s", fCompact ? 0 : (lvl + 1) * 2, "", (fCompact ? "" : "\n")));
92 else
93 fBuf.Append(TString::Format("/>%s", (fCompact ? "" : "\n")));
94}
95
96// ============================================================================
97
98/** \class TRootSnifferStoreJson
99
100Used to store scanned objects hierarchy in JSON form
101*/
102
103
104////////////////////////////////////////////////////////////////////////////////
105/// starts new json object, will be closed by CloseNode
106
108{
109 fBuf.Append(TString::Format("%*s{", fCompact ? 0 : lvl * 4, ""));
110 if (!fCompact) fBuf.Append("\n");
111 fBuf.Append(
112 TString::Format("%*s\"_name\"%s\"%s\"", fCompact ? 0 : lvl * 4 + 2, "", (fCompact ? ":" : " : "), nodename));
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// set field (json field) in current node
117
119{
120 fBuf.Append(",");
121 if (!fCompact)
122 fBuf.Append("\n");
123 fBuf.Append(TString::Format("%*s\"%s\"%s", fCompact ? 0 : lvl * 4 + 2, "", field, (fCompact ? ":" : " : ")));
124 if (!with_quotes) {
126 } else {
127 fBuf.Append("\"");
128 for (const char *v = value; *v != 0; v++)
129 switch (*v) {
130 case '\n': fBuf.Append("\\n"); break;
131 case '\t': fBuf.Append("\\t"); break;
132 case '\"': fBuf.Append("\\\""); break;
133 case '\\': fBuf.Append("\\\\"); break;
134 case '\b': fBuf.Append("\\b"); break;
135 case '\f': fBuf.Append("\\f"); break;
136 case '\r': fBuf.Append("\\r"); break;
137 case '/': fBuf.Append("\\/"); break;
138 default:
139 if ((*v > 31) && (*v < 127))
140 fBuf.Append(*v);
141 else
142 fBuf.Append(TString::Format("\\u%04x", (unsigned)*v));
143 }
144 fBuf.Append("\"");
145 }
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// called before next child node created
150
152{
153 fBuf.Append(",");
154 if (!fCompact) fBuf.Append("\n");
155 if (nchld == 0)
156 fBuf.Append(TString::Format("%*s\"_childs\"%s", (fCompact ? 0 : lvl * 4 + 2), "", (fCompact ? ":[" : " : [\n")));
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// called when node should be closed
161/// depending from number of childs different xml format is applied
162
164{
165 if (numchilds > 0)
166 fBuf.Append(TString::Format("%s%*s]", (fCompact ? "" : "\n"), fCompact ? 0 : lvl * 4 + 2, ""));
167 fBuf.Append(TString::Format("%s%*s}", (fCompact ? "" : "\n"), fCompact ? 0 : lvl * 4, ""));
168}
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:581
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