Skip to content

Commit 14029b0

Browse files
committed
Update to extract values with the new millijson library.
1 parent 13e2e78 commit 14029b0

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

include/uzuki2/parse_json.hpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ inline const std::vector<std::shared_ptr<millijson::Base> >& extract_array(
5555
throw std::runtime_error("expected an array in '" + path + "." + name + "'");
5656
}
5757

58-
return static_cast<const millijson::Array*>(values_ptr.get())->values;
58+
return static_cast<const millijson::Array*>(values_ptr.get())->value();
5959
}
6060

6161
inline const millijson::Array* has_names(const std::unordered_map<std::string, std::shared_ptr<millijson::Base> >& properties, const std::string& path) {
@@ -73,7 +73,7 @@ inline const millijson::Array* has_names(const std::unordered_map<std::string, s
7373

7474
template<class Destination_>
7575
void fill_names(const millijson::Array* names_ptr, Destination_* dest, const std::string& path) {
76-
const auto& names = names_ptr->values;
76+
const auto& names = names_ptr->value();
7777
if (names.size() != dest->size()) {
7878
throw std::runtime_error("length of 'names' and 'values' should be the same in '" + path + "'");
7979
}
@@ -82,7 +82,7 @@ void fill_names(const millijson::Array* names_ptr, Destination_* dest, const std
8282
if (names[i]->type() != millijson::STRING) {
8383
throw std::runtime_error("expected a string at '" + path + ".names[" + std::to_string(i) + "]'");
8484
}
85-
dest->set_name(i, static_cast<const millijson::String*>(names[i].get())->value);
85+
dest->set_name(i, static_cast<const millijson::String*>(names[i].get())->value());
8686
}
8787
}
8888

@@ -104,7 +104,7 @@ auto process_array_or_scalar_values(
104104

105105
const auto& values_ptr = vIt->second;
106106
if (values_ptr->type() == millijson::ARRAY) {
107-
out_ptr = fun(static_cast<const millijson::Array*>(values_ptr.get())->values, has_names, false);
107+
out_ptr = fun(static_cast<const millijson::Array*>(values_ptr.get())->value(), has_names, false);
108108
} else {
109109
std::vector<std::shared_ptr<millijson::Base> > temp { values_ptr };
110110
out_ptr = fun(temp, has_names, true);
@@ -128,7 +128,7 @@ void extract_integers(const std::vector<std::shared_ptr<millijson::Base> >& valu
128128
throw std::runtime_error("expected a number at '" + path + ".values[" + std::to_string(i) + "]'");
129129
}
130130

131-
auto val = static_cast<const millijson::Number*>(values[i].get())->value;
131+
auto val = static_cast<const millijson::Number*>(values[i].get())->value();
132132
if (val != std::floor(val)) {
133133
throw std::runtime_error("expected an integer at '" + path + ".values[" + std::to_string(i) + "]'");
134134
}
@@ -162,7 +162,7 @@ void extract_strings(const std::vector<std::shared_ptr<millijson::Base> >& value
162162
throw std::runtime_error("expected a string at '" + path + ".values[" + std::to_string(i) + "]'");
163163
}
164164

165-
const auto& str = static_cast<const millijson::String*>(values[i].get())->value;
165+
const auto& str = static_cast<const millijson::String*>(values[i].get())->value();
166166
check(str);
167167
dest->set(i, str);
168168
}
@@ -173,9 +173,7 @@ std::shared_ptr<Base> parse_object(const millijson::Base* contents, Externals_&
173173
if (contents->type() != millijson::OBJECT) {
174174
throw std::runtime_error("each R object should be represented by a JSON object at '" + path + "'");
175175
}
176-
177-
auto optr = static_cast<const millijson::Object*>(contents);
178-
const auto& map = optr->values;
176+
const auto& map = static_cast<const millijson::Object*>(contents)->value();
179177

180178
auto tIt = map.find("type");
181179
if (tIt == map.end()) {
@@ -185,7 +183,7 @@ std::shared_ptr<Base> parse_object(const millijson::Base* contents, Externals_&
185183
if (type_ptr->type() != millijson::STRING) {
186184
throw std::runtime_error("expected a string at '" + path + ".type'");
187185
}
188-
const auto& type = static_cast<const millijson::String*>(type_ptr.get())->value;
186+
const auto& type = static_cast<const millijson::String*>(type_ptr.get())->value();
189187

190188
std::shared_ptr<Base> output;
191189
if (type == "nothing") {
@@ -200,7 +198,7 @@ std::shared_ptr<Base> parse_object(const millijson::Base* contents, Externals_&
200198
if (index_ptr->type() != millijson::NUMBER) {
201199
throw std::runtime_error("expected a number at '" + path + ".index'");
202200
}
203-
auto index = static_cast<const millijson::Number*>(index_ptr.get())->value;
201+
auto index = static_cast<const millijson::Number*>(index_ptr.get())->value();
204202

205203
if (index != std::floor(index)) {
206204
throw std::runtime_error("expected an integer at '" + path + ".index'");
@@ -227,8 +225,7 @@ std::shared_ptr<Base> parse_object(const millijson::Base* contents, Externals_&
227225
if (oIt->second->type() != millijson::BOOLEAN) {
228226
throw std::runtime_error("expected a boolean at '" + path + ".ordered'");
229227
}
230-
auto optr = static_cast<const millijson::Boolean*>((oIt->second).get());
231-
ordered = optr->value;
228+
ordered = static_cast<const millijson::Boolean*>((oIt->second).get())->value();
232229
}
233230
}
234231

@@ -252,7 +249,7 @@ std::shared_ptr<Base> parse_object(const millijson::Base* contents, Externals_&
252249
throw std::runtime_error("expected strings at '" + path + ".levels[" + std::to_string(l) + "]'");
253250
}
254251

255-
const auto& level = static_cast<const millijson::String*>(lvals[l].get())->value;
252+
const auto& level = static_cast<const millijson::String*>(lvals[l].get())->value();
256253
if (existing.find(level) != existing.end()) {
257254
throw std::runtime_error("detected duplicate string at '" + path + ".levels[" + std::to_string(l) + "]'");
258255
}
@@ -274,7 +271,7 @@ std::shared_ptr<Base> parse_object(const millijson::Base* contents, Externals_&
274271
if (vals[i]->type() != millijson::BOOLEAN) {
275272
throw std::runtime_error("expected a boolean at '" + path + ".values[" + std::to_string(i) + "]'");
276273
}
277-
ptr->set(i, static_cast<const millijson::Boolean*>(vals[i].get())->value);
274+
ptr->set(i, static_cast<const millijson::Boolean*>(vals[i].get())->value());
278275
}
279276

280277
return ptr;
@@ -292,9 +289,9 @@ std::shared_ptr<Base> parse_object(const millijson::Base* contents, Externals_&
292289
}
293290

294291
if (vals[i]->type() == millijson::NUMBER) {
295-
ptr->set(i, static_cast<const millijson::Number*>(vals[i].get())->value);
292+
ptr->set(i, static_cast<const millijson::Number*>(vals[i].get())->value());
296293
} else if (vals[i]->type() == millijson::STRING) {
297-
auto str = static_cast<const millijson::String*>(vals[i].get())->value;
294+
auto str = static_cast<const millijson::String*>(vals[i].get())->value();
298295
if (str == "NaN") {
299296
ptr->set(i, std::numeric_limits<double>::quiet_NaN());
300297
} else if (str == "Inf") {
@@ -327,12 +324,12 @@ std::shared_ptr<Base> parse_object(const millijson::Base* contents, Externals_&
327324
throw std::runtime_error("expected a string at '" + path + ".format'");
328325
}
329326
auto fptr = static_cast<const millijson::String*>(fIt->second.get());
330-
if (fptr->value == "date") {
327+
if (fptr->value() == "date") {
331328
format = StringVector::DATE;
332-
} else if (fptr->value == "date-time") {
329+
} else if (fptr->value() == "date-time") {
333330
format = StringVector::DATETIME;
334331
} else {
335-
throw std::runtime_error("unsupported format '" + fptr->value + "' at '" + path + ".format'");
332+
throw std::runtime_error("unsupported format '" + fptr->value() + "' at '" + path + ".format'");
336333
}
337334
}
338335
}
@@ -438,14 +435,13 @@ ParsedList parse(byteme::Reader& reader, Externals_ ext, const Options& options)
438435

439436
Version version;
440437
if (contents->type() == millijson::OBJECT) {
441-
auto optr = static_cast<const millijson::Object*>(contents.get());
442-
const auto& map = optr->values;
438+
const auto& map = static_cast<const millijson::Object*>(contents.get())->value();
443439
auto vIt = map.find("version");
444440
if (vIt != map.end()) {
445441
if (vIt->second->type() != millijson::STRING) {
446442
throw std::runtime_error("expected a string in 'version'");
447443
}
448-
const auto& vstr = static_cast<const millijson::String*>(vIt->second.get())->value;
444+
const auto& vstr = static_cast<const millijson::String*>(vIt->second.get())->value();
449445
auto vraw = ritsuko::parse_version_string(vstr.c_str(), vstr.size(), /* skip_patch = */ true);
450446
version.major = vraw.major;
451447
version.minor = vraw.minor;

0 commit comments

Comments
 (0)