cesium-native  0.41.0
PrettyJsonWriter.h
1 #pragma once
2 
3 #include "JsonWriter.h"
4 
5 #include <rapidjson/prettywriter.h>
6 #include <rapidjson/stringbuffer.h>
7 
8 #include <cstdint>
9 #include <functional>
10 #include <memory>
11 #include <string_view>
12 #include <vector>
13 
14 namespace CesiumJsonWriter {
15 
16 class PrettyJsonWriter : public JsonWriter {
17  rapidjson::StringBuffer _prettyBuffer;
18  std::unique_ptr<rapidjson::PrettyWriter<rapidjson::StringBuffer>> pretty;
19 
20 public:
21  PrettyJsonWriter() noexcept;
22  ~PrettyJsonWriter() {}
23 
24  // rapidjson methods
25  bool Null() override;
26  bool Bool(bool b) override;
27  bool Int(int i) override;
28  bool Uint(unsigned int i) override;
29  bool Uint64(std::uint64_t i) override;
30  bool Int64(std::int64_t i) override;
31  bool Double(double d) override;
32  bool RawNumber(const char* str, unsigned int length, bool copy) override;
33  bool Key(std::string_view string) override;
34  bool String(std::string_view string) override;
35  bool StartObject() override;
36  bool EndObject() override;
37  bool StartArray() override;
38  bool EndArray() override;
39 
40  // Primitive overloads
41  void Primitive(std::int32_t value) override;
42  void Primitive(std::uint32_t value) override;
43  void Primitive(std::int64_t value) override;
44  void Primitive(std::uint64_t value) override;
45  void Primitive(float value) override;
46  void Primitive(double value) override;
47  void Primitive(std::nullptr_t value) override;
48  void Primitive(std::string_view string) override;
49 
50  // Integral
51  void KeyPrimitive(std::string_view keyName, std::int32_t value) override;
52  void KeyPrimitive(std::string_view keyName, std::uint32_t value) override;
53  void KeyPrimitive(std::string_view keyName, std::int64_t value) override;
54  void KeyPrimitive(std::string_view keyName, std::uint64_t value) override;
55 
56  // String
57  void KeyPrimitive(std::string_view keyName, std::string_view value) override;
58 
59  // Floating Point
60  void KeyPrimitive(std::string_view keyName, float value) override;
61  void KeyPrimitive(std::string_view keyName, double value) override;
62 
63  // Null
64  void KeyPrimitive(std::string_view keyName, std::nullptr_t value) override;
65 
66  // Array / Objects
67  void KeyArray(std::string_view keyName, std::function<void(void)> insideArray)
68  override;
69 
70  void KeyObject(
71  std::string_view keyName,
72  std::function<void(void)> insideObject) override;
73 
74  std::string toString() override;
75  std::string_view toStringView() override;
76  std::vector<std::byte> toBytes() override;
77 };
78 } // namespace CesiumJsonWriter
Classes for writing JSON.