|
|
@ -76,6 +76,7 @@ class Json { |
|
|
|
|
|
|
|
|
|
|
|
// Construct from copying a string.
|
|
|
|
// Construct from copying a string.
|
|
|
|
// If is_number is true, the type will be NUMBER instead of STRING.
|
|
|
|
// If is_number is true, the type will be NUMBER instead of STRING.
|
|
|
|
|
|
|
|
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
|
|
Json(const std::string& string, bool is_number = false) |
|
|
|
Json(const std::string& string, bool is_number = false) |
|
|
|
: type_(is_number ? Type::NUMBER : Type::STRING), string_value_(string) {} |
|
|
|
: type_(is_number ? Type::NUMBER : Type::STRING), string_value_(string) {} |
|
|
|
Json& operator=(const std::string& string) { |
|
|
|
Json& operator=(const std::string& string) { |
|
|
@ -85,12 +86,14 @@ class Json { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Same thing for C-style strings, both const and mutable.
|
|
|
|
// Same thing for C-style strings, both const and mutable.
|
|
|
|
|
|
|
|
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
|
|
Json(const char* string, bool is_number = false) |
|
|
|
Json(const char* string, bool is_number = false) |
|
|
|
: Json(std::string(string), is_number) {} |
|
|
|
: Json(std::string(string), is_number) {} |
|
|
|
Json& operator=(const char* string) { |
|
|
|
Json& operator=(const char* string) { |
|
|
|
*this = std::string(string); |
|
|
|
*this = std::string(string); |
|
|
|
return *this; |
|
|
|
return *this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
|
|
Json(char* string, bool is_number = false) |
|
|
|
Json(char* string, bool is_number = false) |
|
|
|
: Json(std::string(string), is_number) {} |
|
|
|
: Json(std::string(string), is_number) {} |
|
|
|
Json& operator=(char* string) { |
|
|
|
Json& operator=(char* string) { |
|
|
@ -99,6 +102,7 @@ class Json { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Construct by moving a string.
|
|
|
|
// Construct by moving a string.
|
|
|
|
|
|
|
|
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
|
|
Json(std::string&& string) |
|
|
|
Json(std::string&& string) |
|
|
|
: type_(Type::STRING), string_value_(std::move(string)) {} |
|
|
|
: type_(Type::STRING), string_value_(std::move(string)) {} |
|
|
|
Json& operator=(std::string&& string) { |
|
|
|
Json& operator=(std::string&& string) { |
|
|
@ -108,6 +112,7 @@ class Json { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Construct from bool.
|
|
|
|
// Construct from bool.
|
|
|
|
|
|
|
|
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
|
|
Json(bool b) : type_(b ? Type::JSON_TRUE : Type::JSON_FALSE) {} |
|
|
|
Json(bool b) : type_(b ? Type::JSON_TRUE : Type::JSON_FALSE) {} |
|
|
|
Json& operator=(bool b) { |
|
|
|
Json& operator=(bool b) { |
|
|
|
type_ = b ? Type::JSON_TRUE : Type::JSON_FALSE; |
|
|
|
type_ = b ? Type::JSON_TRUE : Type::JSON_FALSE; |
|
|
@ -116,6 +121,7 @@ class Json { |
|
|
|
|
|
|
|
|
|
|
|
// Construct from any numeric type.
|
|
|
|
// Construct from any numeric type.
|
|
|
|
template <typename NumericType> |
|
|
|
template <typename NumericType> |
|
|
|
|
|
|
|
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
|
|
Json(NumericType number) |
|
|
|
Json(NumericType number) |
|
|
|
: type_(Type::NUMBER), string_value_(std::to_string(number)) {} |
|
|
|
: type_(Type::NUMBER), string_value_(std::to_string(number)) {} |
|
|
|
template <typename NumericType> |
|
|
|
template <typename NumericType> |
|
|
@ -126,6 +132,7 @@ class Json { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Construct by copying object.
|
|
|
|
// Construct by copying object.
|
|
|
|
|
|
|
|
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
|
|
Json(const Object& object) : type_(Type::OBJECT), object_value_(object) {} |
|
|
|
Json(const Object& object) : type_(Type::OBJECT), object_value_(object) {} |
|
|
|
Json& operator=(const Object& object) { |
|
|
|
Json& operator=(const Object& object) { |
|
|
|
type_ = Type::OBJECT; |
|
|
|
type_ = Type::OBJECT; |
|
|
@ -134,6 +141,7 @@ class Json { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Construct by moving object.
|
|
|
|
// Construct by moving object.
|
|
|
|
|
|
|
|
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
|
|
Json(Object&& object) |
|
|
|
Json(Object&& object) |
|
|
|
: type_(Type::OBJECT), object_value_(std::move(object)) {} |
|
|
|
: type_(Type::OBJECT), object_value_(std::move(object)) {} |
|
|
|
Json& operator=(Object&& object) { |
|
|
|
Json& operator=(Object&& object) { |
|
|
@ -143,6 +151,7 @@ class Json { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Construct by copying array.
|
|
|
|
// Construct by copying array.
|
|
|
|
|
|
|
|
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
|
|
Json(const Array& array) : type_(Type::ARRAY), array_value_(array) {} |
|
|
|
Json(const Array& array) : type_(Type::ARRAY), array_value_(array) {} |
|
|
|
Json& operator=(const Array& array) { |
|
|
|
Json& operator=(const Array& array) { |
|
|
|
type_ = Type::ARRAY; |
|
|
|
type_ = Type::ARRAY; |
|
|
@ -151,6 +160,7 @@ class Json { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Construct by moving array.
|
|
|
|
// Construct by moving array.
|
|
|
|
|
|
|
|
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
|
|
Json(Array&& array) : type_(Type::ARRAY), array_value_(std::move(array)) {} |
|
|
|
Json(Array&& array) : type_(Type::ARRAY), array_value_(std::move(array)) {} |
|
|
|
Json& operator=(Array&& array) { |
|
|
|
Json& operator=(Array&& array) { |
|
|
|
type_ = Type::ARRAY; |
|
|
|
type_ = Type::ARRAY; |
|
|
|