File tree Expand file tree Collapse file tree 1 file changed +116
-0
lines changed
Expand file tree Collapse file tree 1 file changed +116
-0
lines changed Original file line number Diff line number Diff line change 1+ // Copyright (c) 2016 Dr. Colin Hirsch and Daniel Frey
2+ // Please see LICENSE for license or visit https://github.com/taocpp/json/
3+
4+ #ifndef TAOCPP_JSON_INCLUDE_SAX_DEBUG_HH
5+ #define TAOCPP_JSON_INCLUDE_SAX_DEBUG_HH
6+
7+ #include < ostream>
8+ #include < cstdint>
9+
10+ #include " ../external/double.hh"
11+
12+ #include " ../internal/escape.hh"
13+
14+ namespace tao
15+ {
16+ namespace json
17+ {
18+ namespace sax
19+ {
20+ // SAX consumer that writes the events to a stream for debug purposed
21+ class debug
22+ {
23+ private:
24+ std::ostream & os;
25+
26+ public:
27+ explicit debug ( std::ostream & os ) noexcept
28+ : os( os )
29+ { }
30+
31+ void null ()
32+ {
33+ os << " null\n " ;
34+ }
35+
36+ void boolean ( const bool v )
37+ {
38+ if ( v ) {
39+ os << " boolean: true\n " ;
40+ }
41+ else {
42+ os << " boolean: false\n " ;
43+ }
44+ }
45+
46+ void number ( const std::int64_t v )
47+ {
48+ os << " std::int64_t: " << v << ' \n ' ;
49+ }
50+
51+ void number ( const std::uint64_t v )
52+ {
53+ os << " std::uint64_t: " << v << ' \n ' ;
54+ }
55+
56+ void number ( const double v )
57+ {
58+ os << " double: " ;
59+ json_double_conversion::Dtostr ( os, v );
60+ os << ' \n ' ;
61+ }
62+
63+ void string ( const std::string & v )
64+ {
65+ os << " string: " ;
66+ internal::escape ( os, v );
67+ os << ' \n ' ;
68+ }
69+
70+ // array
71+ void begin_array ()
72+ {
73+ os << " begin array\n " ;
74+ }
75+
76+ void element ()
77+ {
78+ os << " element\n " ;
79+ }
80+
81+ void end_array ()
82+ {
83+ os << " end array\n " ;
84+ }
85+
86+ // object
87+ void begin_object ()
88+ {
89+ os << " begin object\n " ;
90+ }
91+
92+ void key ( const std::string & v )
93+ {
94+ os << " key: " ;
95+ internal::escape ( os, v );
96+ os << ' \n ' ;
97+ }
98+
99+ void member ()
100+ {
101+ os << " member\n " ;
102+ }
103+
104+ void end_object ()
105+ {
106+ os << " end object\n " ;
107+ }
108+ };
109+
110+ } // sax
111+
112+ } // json
113+
114+ } // tao
115+
116+ #endif
You can’t perform that action at this time.
0 commit comments