summaryrefslogtreecommitdiff
path: root/src/json.hh
blob: f2aae92200d4cf186c45de6cfa1e37b132c9de6b (plain)
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
#ifndef JSON_HH
#define JSON_HH

#include <cstdint>
#include <iosfwd>
#include <memory>
#include <string>
#include <string_view>

namespace json {

class Writer {
 public:
  virtual ~Writer() = default;

  virtual void value(std::string_view value) = 0;
  virtual void value(int64_t value) = 0;
  virtual void value(uint64_t value) = 0;
  virtual void value(float value) = 0;
  virtual void value(double value) = 0;
  virtual void value(bool value) = 0;
  virtual void value(std::nullptr_t) = 0;

  void value(char const* value);
  void value(int32_t value);
  void value(uint32_t value);

  virtual void start_array() = 0;
  virtual void end_array() = 0;

  virtual void start_object() = 0;
  virtual void key(std::string_view name) = 0;
  virtual void end_object() = 0;

  virtual void clear() = 0;

 protected:
  Writer() = default;
  Writer(Writer const&) = delete;
  Writer& operator=(Writer const&) = delete;
};

std::unique_ptr<Writer> writer(std::string& out);
std::unique_ptr<Writer> writer(std::ostream& out);

}  // namespace json

#endif  // JSON_HH