-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSONXMLConverter.h
89 lines (64 loc) · 2.14 KB
/
JSONXMLConverter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef JSON_JSON2XMLConverter_INCLUDED
#define JSON_JSON2XMLConverter_INCLUDED
#include "Poco/JSON/JSON.h"
#include "Poco/JSON/Handler.h"
class JSON2XMLConverter : public Poco::JSON::Handler
/// JSON2XMLConverter converts JSON to XML.
{
public:
JSON2XMLConverter(unsigned indent = 0);
/// Creates the JSON2XMLConverter.
JSON2XMLConverter(std::ostream& out, unsigned indent = 0);
/// Creates the JSON2XMLConverter.
~JSON2XMLConverter();
/// Destroys the JSON2XMLConverter.
void reset();
/// Resets the handler state.
void startObject();
/// The parser has read a '{'; a new object is started.
void endObject();
/// The parser has read a '}'; the object is closed.
void startArray();
/// The parser has read a [; a new array will be started.
void endArray();
/// The parser has read a ]; the array is closed.
void key(const std::string& k);
/// A key of an object is read; it will be written to the output.
void null();
/// A null value is read; "null" will be written to the output.
void value(int v);
/// An integer value is read.
void value(unsigned v);
/// An unsigned value is read. This will only be triggered if the
/// value cannot fit into a signed int.
void value(Poco::Int64 v);
/// A 64-bit integer value is read; it will be written to the output.
void value(Poco::UInt64 v);
/// An unsigned 64-bit integer value is read; it will be written to the output.
void value(const std::string& value);
/// A string value is read; it will be fromatted and written to the output.
void value(double d);
/// A double value is read; it will be written to the output.
void value(bool b);
/// A boolean value is read; it will be written to the output.
void setIndent(unsigned indent);
/// Sets indentation.
template <typename T>
void doValue(T val)
{
if (_array)
{
++_index;
_out << '<' << _key << _index << ">" << val << "</" << _key << _index << '>';
}
else
_out << val << "</" << _key << '>';
}
private:
std::ostream& _out;
bool _object;
std::string _key;
bool _array;
int _index;
};
#endif // JSON_JSON2XMLConverter_INCLUDED