14 using value_type = Json::Value;
15 using string_type = std::string;
18 using value_type = Json::Value;
22 explicit array_type(
const Json::Value& o) : Json::Value(o) {}
24 explicit array_type(Json::Value&& o) : Json::Value(o) {}
25 template<
typename Iterator>
27 for (Iterator it = begin; it != end; ++it) {
37 value_type
const& front()
const {
return this->operator[](0U); }
39 using number_type = double;
40 using integer_type = Json::Value::Int;
41 using boolean_type = bool;
44 using key_type = std::string;
45 using mapped_type = Json::Value;
46 using size_type = size_t;
50 explicit object_type(
const Json::Value& o) : Json::Value(o) {}
52 explicit object_type(Json::Value&& o) : Json::Value(o) {}
58 const mapped_type& at(
const key_type& key)
const {
59 Json::Value
const* found = find(key.data(), key.data() + key.length());
60 if (!found)
throw std::out_of_range(
"invalid key");
64 size_type count(
const key_type& key)
const {
return this->isMember(key) ? 1 : 0; }
73 else if (val.isString())
78 else if (val.isNumeric())
80 else if (val.isBool())
82 else if (val.isObject())
85 throw std::logic_error(
"invalid type");
88 static integer_type as_integer(
const value_type& val) {
90 case Json::intValue:
return val.asInt64();
91 case Json::uintValue:
return static_cast<integer_type
>(val.asUInt64());
92 default:
throw std::bad_cast();
96 static boolean_type as_boolean(
const value_type& val) {
97 if (!val.isBool())
throw std::bad_cast();
101 static number_type as_number(
const value_type& val) {
102 if (!val.isNumeric())
throw std::bad_cast();
103 return val.asDouble();
106 static string_type as_string(
const value_type& val) {
107 if (!val.isString())
throw std::bad_cast();
108 return val.asString();
111 static object_type as_object(
const value_type& val) {
112 if (!val.isObject())
throw std::bad_cast();
113 return object_type(val);
116 static array_type as_array(
const value_type& val) {
117 if (!val.isArray())
throw std::bad_cast();
118 return array_type(val);
121 static bool parse(value_type& val, string_type str) {
122 Json::CharReaderBuilder builder;
123 const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
125 return reader->parse(
reinterpret_cast<const char*
>(str.c_str()),
126 reinterpret_cast<const char*
>(str.c_str() + str.size()), &val,
nullptr);
129 static string_type serialize(
const value_type& val) {
130 Json::StreamWriterBuilder builder;
131 builder[
"commentStyle"] =
"None";
132 builder[
"indentation"] =
"";
133 std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
134 return Json::writeString(builder, val);