libwreport 3.40
json.h
1#ifndef WREPORT_UTILS_JSON_H
2#define WREPORT_UTILS_JSON_H
3
7
8#include <cstdint>
9#include <sstream>
10
11namespace wreport::json {
12class Dict;
13class List;
14
15class JSON
16{
17protected:
18 std::stringstream& out;
19
20 void addc(char c);
21 void adds(const std::string& val);
22 void addu(unsigned val);
23 void addq(const std::string& val);
24
25public:
26 explicit JSON(std::stringstream& out);
27};
28
29class JSONL : public JSON
30{
31public:
32 explicit JSONL(std::stringstream& out);
33 ~JSONL();
34
35 Dict dict();
36};
37
38class Sequence : public JSON
39{
40protected:
41 bool first = true;
42
43 void maybe_add_comma();
44
45public:
46 using JSON::JSON;
47};
48
49class Dict : public Sequence
50{
51public:
52 explicit Dict(std::stringstream& out);
53 ~Dict();
54
55 void add_null(const char* key);
56 void add_bool(const char* key, bool val);
57 void add(const char* key, const std::string& val);
58 void add_unsigned(const char* key, unsigned val);
59 void add_nullable(const char* key, uint8_t val, uint8_t nullval);
60 void add_nullable(const char* key, uint16_t val, uint16_t nullval);
61 Dict add_dict(const char* key);
62 List add_list(const char* key);
63};
64
65class List : public Sequence
66{
67public:
68 explicit List(std::stringstream& out);
69 ~List();
70
71 Dict add_dict();
72 List add_list();
73};
74
75} // namespace wreport::json
76
77#endif
Definition json.h:50
Definition json.h:66
Definition json.h:39
Limited JSON output used for tests.
Definition json.h:11