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