37 using array = std::vector<value>;
56 type(value_type::null) {}
59 type(value_type::null) {}
62 type(value_type::boolean), b(b) {}
65 type(value_type::integer), i(i) {}
68 type(value_type::fractional), f(f) {}
71 type(value_type::object), o(o) {}
74 type(value_type::array) {
75 new (&a) array(value);
79 type(value_type::string), s(s) { }
81 value(
const value& other): type(other.type) {
83 case value_type::array:
84 new (&a) array(other.a);
86 case value_type::object:
87 new (&o)
object(other.o);
89 case value_type::integer:
90 new (&i) bigint(other.i);
92 case value_type::boolean:
95 case value_type::null:
97 case value_type::string:
98 new (&s)
string(other.s);
100 case value_type::fractional:
101 new (&f) fractional(other.f);
106 value(value&& other): type(std::move(other.type)) {
107 switch (other.type) {
108 case value_type::array:
109 new (&a) array(std::move(other.a));
111 case value_type::object:
112 new (&o)
object(std::move(other.o));
114 case value_type::integer:
115 new (&i) bigint(std::move(other.i));
117 case value_type::boolean:
120 case value_type::null:
122 case value_type::string:
123 new (&s)
string(std::move(other.s));
125 case value_type::fractional:
126 new (&f) fractional(std::move(other.f));
129 other.type = value_type::null;
132 value& operator=(
const value& other) {
134 switch (other.type) {
135 case value_type::array:
136 new (&a) array(other.a);
138 case value_type::object:
139 new (&o)
object(other.o);
141 case value_type::integer:
142 new (&i) bigint(other.i);
144 case value_type::boolean:
147 case value_type::null:
149 case value_type::string:
150 new (&s)
string(other.s);
152 case value_type::fractional:
153 new (&f) fractional(other.f);
159 value& operator=(value&& other) {
160 type = std::move(other.type);
161 switch (other.type) {
162 case value_type::array:
163 new (&a) array(std::move(other.a));
165 case value_type::object:
166 new (&o)
object(std::move(other.o));
168 case value_type::integer:
169 new (&i) bigint(std::move(other.i));
171 case value_type::boolean:
174 case value_type::null:
176 case value_type::string:
177 new (&s)
string(std::move(other.s));
179 case value_type::fractional:
180 new (&f) fractional(std::move(other.f));
183 other.type = value_type::null;
189 case value_type::string:
192 case value_type::fractional:
195 case value_type::array:
198 case value_type::object:
201 case value_type::boolean:
203 case value_type::integer:
206 case value_type::null:
211 inline value_type get_type()
const noexcept {
215 inline bool& as_boolean() {
216 ZEN_ASSERT(type == value_type::boolean);
220 inline const bool& as_boolean()
const {
221 ZEN_ASSERT(type == value_type::boolean);
225 inline string& as_string() {
226 ZEN_ASSERT(type == value_type::string);
230 inline const string& as_string()
const {
231 ZEN_ASSERT(type == value_type::string);
235 inline bigint& as_integer() {
236 ZEN_ASSERT(type == value_type::integer);
240 inline const bigint& as_integer()
const {
241 ZEN_ASSERT(type == value_type::integer);
245 inline fractional& as_fractional() {
246 ZEN_ASSERT(type == value_type::fractional);
250 inline const fractional& as_fractional()
const {
251 ZEN_ASSERT(type == value_type::fractional);
255 inline array& as_array() {
256 ZEN_ASSERT(type == value_type::array);
260 inline const array& as_array()
const {
261 ZEN_ASSERT(type == value_type::array);
265 inline object& as_object() {
266 ZEN_ASSERT(type == value_type::object);
270 inline const object& as_object()
const {
271 ZEN_ASSERT(type == value_type::object);
275 inline bool is_true()
const noexcept {
276 return type == value_type::boolean && b;
279 inline bool is_false()
const noexcept {
280 return type == value_type::boolean && !b;
283 inline bool is_boolean()
const noexcept {
284 return type == value_type::boolean;
287 inline bool is_integer()
const noexcept {
288 return type == value_type::integer;
291 inline bool is_fractional()
const noexcept {
292 return type == value_type::fractional;
295 inline bool is_null()
const noexcept {
296 return type == value_type::null;
299 inline bool is_string()
const noexcept {
300 return type == value_type::string;
303 inline bool is_object()
const noexcept {
304 return type == value_type::object;
307 inline bool is_array()
const noexcept {
308 return type == value_type::array;