|
18 | 18 | MA 02110-1301, USA. |
19 | 19 | */ |
20 | 20 |
|
21 | | -#include "ValWriter.hh" |
| 21 | +#include "JsonWriter.hh" |
22 | 22 | #include "util/DataStream.hh" |
23 | 23 |
|
24 | 24 | #include <yajl/yajl_gen.h> |
|
27 | 27 |
|
28 | 28 | namespace gr { |
29 | 29 |
|
30 | | -struct ValWriter::Impl |
| 30 | +struct JsonWriter::Impl |
31 | 31 | { |
32 | 32 | yajl_gen gen ; |
33 | 33 | DataStream *out ; |
34 | 34 | } ; |
35 | 35 |
|
36 | | -ValWriter::ValWriter( DataStream *out ) : |
| 36 | +JsonWriter::JsonWriter( DataStream *out ) : |
37 | 37 | m_impl( new Impl ) |
38 | 38 | { |
39 | 39 | assert( out != 0 ) ; |
40 | 40 |
|
41 | 41 | m_impl->out = out ; |
42 | 42 | m_impl->gen = yajl_gen_alloc(0) ; |
43 | | - yajl_gen_config( m_impl->gen, yajl_gen_print_callback, &ValWriter::WriteCallback, this ) ; |
| 43 | + yajl_gen_config( m_impl->gen, yajl_gen_print_callback, &JsonWriter::WriteCallback, this ) ; |
44 | 44 | } |
45 | 45 |
|
46 | | -ValWriter::~ValWriter() |
| 46 | +JsonWriter::~JsonWriter() |
47 | 47 | { |
48 | 48 | yajl_gen_free( m_impl->gen ) ; |
49 | 49 | } |
50 | 50 |
|
51 | | -void ValWriter::Visit( long long t ) |
| 51 | +void JsonWriter::Visit( long long t ) |
52 | 52 | { |
53 | 53 | yajl_gen_integer( m_impl->gen, t ) ; |
54 | 54 | } |
55 | 55 |
|
56 | | -void ValWriter::Visit( double t ) |
| 56 | +void JsonWriter::Visit( double t ) |
57 | 57 | { |
58 | 58 | yajl_gen_double( m_impl->gen, t ) ; |
59 | 59 | } |
60 | 60 |
|
61 | | -void ValWriter::Visit( const std::string& t ) |
| 61 | +void JsonWriter::Visit( const std::string& t ) |
62 | 62 | { |
63 | 63 | yajl_gen_string( m_impl->gen, |
64 | 64 | reinterpret_cast<const unsigned char*>(t.c_str()), t.size() ) ; |
65 | 65 | } |
66 | 66 |
|
67 | | -void ValWriter::Visit( bool t ) |
| 67 | +void JsonWriter::Visit( bool t ) |
68 | 68 | { |
69 | 69 | yajl_gen_bool( m_impl->gen, t ) ; |
70 | 70 | } |
71 | 71 |
|
72 | | -void ValWriter::VisitNull() |
| 72 | +void JsonWriter::VisitNull() |
73 | 73 | { |
74 | 74 | yajl_gen_null( m_impl->gen ) ; |
75 | 75 | } |
76 | 76 |
|
77 | | -void ValWriter::StartArray() |
| 77 | +void JsonWriter::StartArray() |
78 | 78 | { |
79 | 79 | yajl_gen_array_open( m_impl->gen ) ; |
80 | 80 | } |
81 | 81 |
|
82 | | -void ValWriter::EndArray() |
| 82 | +void JsonWriter::EndArray() |
83 | 83 | { |
84 | 84 | yajl_gen_array_close( m_impl->gen ) ; |
85 | 85 | } |
86 | 86 |
|
87 | | -void ValWriter::StartObject() |
| 87 | +void JsonWriter::StartObject() |
88 | 88 | { |
89 | 89 | yajl_gen_map_open( m_impl->gen ) ; |
90 | 90 | } |
91 | 91 |
|
92 | | -void ValWriter::VisitKey( const std::string& t ) |
| 92 | +void JsonWriter::VisitKey( const std::string& t ) |
93 | 93 | { |
94 | 94 | Visit(t) ; |
95 | 95 | } |
96 | 96 |
|
97 | | -void ValWriter::EndObject() |
| 97 | +void JsonWriter::EndObject() |
98 | 98 | { |
99 | 99 | yajl_gen_map_close( m_impl->gen ) ; |
100 | 100 | } |
101 | 101 |
|
102 | | -void ValWriter::WriteCallback( void *ctx, const char *str, std::size_t size ) |
| 102 | +void JsonWriter::WriteCallback( void *ctx, const char *str, std::size_t size ) |
103 | 103 | { |
104 | | - ValWriter *pthis = reinterpret_cast<ValWriter*>(ctx) ; |
| 104 | + JsonWriter *pthis = reinterpret_cast<JsonWriter*>(ctx) ; |
105 | 105 | assert( pthis != 0 ) ; |
106 | 106 | assert( pthis->m_impl->out != 0 ) ; |
107 | 107 |
|
|
0 commit comments