8#include <initializer_list>
15namespace hegel::internal {
19namespace hegel::internal::json {
23 struct json_ref_holder;
27 std::unique_ptr<json_ref_holder> ref;
28 friend class ImplUtil;
31 json_raw_ref(json_ref_holder* ref_);
32 json_raw_ref(
const json_raw_ref& other);
35 std::string get_string() const noexcept;
36 bool get_bool() const noexcept;
37 uint32_t get_uint32_t() const noexcept;
38 uint64_t get_uint64_t() const noexcept;
39 int64_t get_int64_t() const noexcept;
40 double get_double() const noexcept;
42 size_t size() const noexcept;
44 bool is_string() const noexcept;
45 bool is_null() const noexcept;
46 bool is_boolean() const noexcept;
47 bool is_number() const noexcept;
48 bool is_number_integer() const noexcept;
49 bool is_number_unsigned() const noexcept;
50 bool is_array() const noexcept;
51 bool is_object() const noexcept;
53 json_raw_ref& operator=(const
size_t& other);
54 json_raw_ref& operator=(const
double& other);
55 json_raw_ref& operator=(const std::nullptr_t& other);
56 json_raw_ref& operator=(
bool other);
57 json_raw_ref& operator=(const std::
string& other);
58 json_raw_ref& operator=(const json& other);
60 json_raw_ref& operator=(
const uint64_t& other);
63 json_raw_ref operator[](
size_t index)
const;
65 std::vector<json_raw_ref> iterate()
const;
66 std::vector<std::pair<std::string, json_raw_ref>> items()
const;
67 std::optional<json_raw_ref> find(
const std::string& key)
const;
71 using initializer_list_t = std::initializer_list<json_ref>;
74 json(
const json& init);
76 json(json&& init)
noexcept;
78 json(initializer_list_t init);
80 json(
const char* init);
82 json(
const int32_t init);
83 json(
const int64_t init);
84 json(
const uint32_t init);
85 json(
const uint64_t init);
87 json(
const unsigned long init);
89 json(
const bool init);
90 json(
const double init);
91 json(
const std::string& init);
92 json(std::nullptr_t init =
nullptr);
93 json(
const json_raw_ref& init);
96 json_raw_ref operator[](
const std::string& key);
98 json& operator=(json other)
noexcept;
100 std::string value(
const std::string& key,
101 const std::string& default_value);
102 uint32_t value(
const std::string& key,
const uint32_t& default_value);
104 bool contains(
const std::string& key);
106 static json array(initializer_list_t init = {});
107 void push_back(json&& val);
108 void push_back(
const json& val);
109 void push_back(
const std::string& val);
111 std::string dump()
const;
113 std::vector<unsigned char>& get_binary();
115 static json parse(
const char* arg);
118 std::unique_ptr<json_holder> impl;
119 friend class ImplUtil;
124 json_ref(json&& value) : owned_value(std::move(value)) {}
126 json_ref(
const json& value) : value_ref(&value) {}
128 json_ref(std::initializer_list<json_ref> init) : owned_value(init) {}
130 template <
class... Args,
131 std::enable_if_t<std::is_constructible<json, Args...>::value,
133 json_ref(Args&&... args) : owned_value(std::forward<Args>(args)...) {}
136 json_ref(json_ref&&) noexcept = default;
137 json_ref(const json_ref&) = delete;
138 json_ref& operator=(const json_ref&) = delete;
139 json_ref& operator=(json_ref&&) = delete;
140 ~json_ref() = default;
142 json const& operator*()
const {
143 return value_ref ? *value_ref : owned_value;
147 mutable json owned_value =
nullptr;
148 json
const* value_ref =
nullptr;