cesium-native 0.43.0
Loading...
Searching...
No Matches
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
14namespace CesiumJsonWriter {
15
21 rapidjson::StringBuffer _prettyBuffer;
22 std::unique_ptr<rapidjson::PrettyWriter<rapidjson::StringBuffer>> pretty;
23
24public:
25 PrettyJsonWriter() noexcept;
27
28 bool Null() override;
29 bool Bool(bool b) override;
30 bool Int(int i) override;
31 bool Uint(unsigned int i) override;
32 bool Uint64(std::uint64_t i) override;
33 bool Int64(std::int64_t i) override;
34 bool Double(double d) override;
35 bool RawNumber(const char* str, unsigned int length, bool copy) override;
36 bool Key(std::string_view string) override;
37 bool String(std::string_view string) override;
38 bool StartObject() override;
39 bool EndObject() override;
40 bool StartArray() override;
41 bool EndArray() override;
42
43 void Primitive(std::int32_t value) override;
44 void Primitive(std::uint32_t value) override;
45 void Primitive(std::int64_t value) override;
46 void Primitive(std::uint64_t value) override;
47 void Primitive(float value) override;
48 void Primitive(double value) override;
49 void Primitive(std::nullptr_t value) override;
50 void Primitive(std::string_view string) override;
51
52 void KeyPrimitive(std::string_view keyName, std::int32_t value) override;
53 void KeyPrimitive(std::string_view keyName, std::uint32_t value) override;
54 void KeyPrimitive(std::string_view keyName, std::int64_t value) override;
55 void KeyPrimitive(std::string_view keyName, std::uint64_t value) override;
56 void KeyPrimitive(std::string_view keyName, std::string_view value) override;
57 void KeyPrimitive(std::string_view keyName, float value) override;
58 void KeyPrimitive(std::string_view keyName, double value) override;
59 void KeyPrimitive(std::string_view keyName, std::nullptr_t value) override;
60
61 void KeyArray(std::string_view keyName, std::function<void(void)> insideArray)
62 override;
64 std::string_view keyName,
65 std::function<void(void)> insideObject) override;
66
67 std::string toString() override;
68 std::string_view toStringView() override;
69 std::vector<std::byte> toBytes() override;
70};
71} // namespace CesiumJsonWriter
Wrapper around rapidjson::Writer for writing objects to JSON.
Definition JsonWriter.h:18
Implementation of JsonWriter that "pretty-prints" JSON to the output, formatted with new lines and in...
void KeyPrimitive(std::string_view keyName, std::nullptr_t value) override
Writes the given key and its corresponding value primitive to the output. This is a convenience funct...
void Primitive(std::int32_t value) override
Writes the given primitive to the output. This is a convenience function for Int.
bool StartArray() override
Writes the start of a JSON array to the output.
bool Null() override
Writes a null value to the output.
std::string toString() override
Obtains the written output as a string.
void Primitive(double value) override
Writes the given primitive to the output. This is a convenience function for Double.
bool String(std::string_view string) override
Writes the given string as a value to the output.
void KeyPrimitive(std::string_view keyName, std::uint64_t value) override
Writes the given key and its corresponding value primitive to the output. This is a convenience funct...
void KeyObject(std::string_view keyName, std::function< void(void)> insideObject) override
Writes an object to the output with the given key and calls the provided callback to write values ins...
void KeyPrimitive(std::string_view keyName, float value) override
Writes the given key and its corresponding value primitive to the output. This is a convenience funct...
bool RawNumber(const char *str, unsigned int length, bool copy) override
Writes the given string as a number to the output without any kind of special handling.
std::string_view toStringView() override
Obtains the written output as a string_view.
bool Bool(bool b) override
Writes a boolean value to the output.
void KeyPrimitive(std::string_view keyName, double value) override
Writes the given key and its corresponding value primitive to the output. This is a convenience funct...
bool Uint(unsigned int i) override
Writes an unsigned integer value to the output.
void Primitive(float value) override
Writes the given primitive to the output. This is a convenience function for Double.
bool EndArray() override
Writes the end of a JSON array to the output.
void Primitive(std::uint32_t value) override
Writes the given primitive to the output. This is a convenience function for Uint.
bool StartObject() override
Writes the start of a JSON object to the output.
void KeyPrimitive(std::string_view keyName, std::int32_t value) override
Writes the given key and its corresponding value primitive to the output. This is a convenience funct...
bool Double(double d) override
Writes a 64-bit floating point value to the output.
bool Key(std::string_view string) override
Writes the given string as an object key to the output.
std::vector< std::byte > toBytes() override
Obtains the written output as a buffer of bytes.
void Primitive(std::string_view string) override
Writes the given primitive to the output. This is a convenience function for String.
bool Int(int i) override
Writes a signed integer value to the output.
bool Int64(std::int64_t i) override
Writes an signed 64-bit integer value to the output.
void KeyPrimitive(std::string_view keyName, std::uint32_t value) override
Writes the given key and its corresponding value primitive to the output. This is a convenience funct...
void KeyPrimitive(std::string_view keyName, std::string_view value) override
Writes the given key and its corresponding value primitive to the output. This is a convenience funct...
void KeyArray(std::string_view keyName, std::function< void(void)> insideArray) override
Writes an array to the output with the given key and calls the provided callback to write values insi...
void Primitive(std::uint64_t value) override
Writes the given primitive to the output. This is a convenience function for Uint64.
bool EndObject() override
Writes the end of a JSON object to the output.
void Primitive(std::int64_t value) override
Writes the given primitive to the output. This is a convenience function for Int64.
bool Uint64(std::uint64_t i) override
Writes an unsigned 64-bit integer value to the output.
void KeyPrimitive(std::string_view keyName, std::int64_t value) override
Writes the given key and its corresponding value primitive to the output. This is a convenience funct...
void Primitive(std::nullptr_t value) override
Writes the given primitive to the output. This is a convenience function for Null.
Classes for writing JSON.