libwreport  3.40
json.h
1 #ifndef WREPORT_UTILS_JSON_H
2 #define WREPORT_UTILS_JSON_H
3 
8 #include <cstdint>
9 #include <sstream>
10 
11 namespace wreport::json {
12 class Dict;
13 class List;
14 
15 class JSON
16 {
17 protected:
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 
25 public:
26  explicit JSON(std::stringstream& out);
27 };
28 
29 class JSONL : public JSON
30 {
31 public:
32  explicit JSONL(std::stringstream& out);
33  ~JSONL();
34 
35  Dict dict();
36 };
37 
38 class Sequence : public JSON
39 {
40 protected:
41  bool first = true;
42 
43  void maybe_add_comma();
44 
45 public:
46  using JSON::JSON;
47 };
48 
49 class Dict : public Sequence
50 {
51 public:
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 
65 class List : public Sequence
66 {
67 public:
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:30
Definition: json.h:16
Definition: json.h:66
Definition: json.h:39
Limited JSON output used for tests.
Definition: json.h:11