Skip to content

Commit c6e3971

Browse files
committed
atdcpp: update expected files
1 parent 860c0c8 commit c6e3971

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

atdcpp/test/cpp-expected/everything_atd.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ template <typename T>
113113
return val.GetString();
114114
}
115115

116+
[[maybe_unused]] std::string _atd_read_abstract(const rapidjson::Value &val)
117+
{
118+
// will convert val to string
119+
rapidjson::StringBuffer buffer;
120+
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
121+
val.Accept(writer);
122+
return buffer.GetString();
123+
}
124+
116125
template <typename F>
117126
[[maybe_unused]] auto _atd_read_array(F read_func, const rapidjson::Value &val)
118127
{
@@ -265,6 +274,12 @@ template <typename T>
265274
writer.String(value.c_str());
266275
}
267276

277+
[[maybe_unused]] void _atd_write_abstract(const std::string &value, rapidjson::Writer<rapidjson::StringBuffer>& writer)
278+
{
279+
// writes string value as raw json
280+
writer.RawValue(value.c_str(), value.size(), rapidjson::kStringType);
281+
}
282+
268283
template <typename F, typename V>
269284
[[maybe_unused]] void _atd_write_array(F write_func, const V& values, rapidjson::Writer<rapidjson::StringBuffer>& writer)
270285
{
@@ -952,6 +967,9 @@ Root Root::from_json(const rapidjson::Value & doc) {
952967
if (doc.HasMember("options"))
953968
record.options = _atd_read_array([](const auto &v){return _atd_read_option([](const auto &v){return _atd_read_int(v);}, v);}, doc["options"]);
954969
else record.options = _atd_missing_json_field<decltype(record.options)>("Root", "options");
970+
if (doc.HasMember("untyped_things"))
971+
record.untyped_things = _atd_read_array([](const auto &v){return _atd_read_abstract(v);}, doc["untyped_things"]);
972+
else record.untyped_things = _atd_missing_json_field<decltype(record.untyped_things)>("Root", "untyped_things");
955973
if (doc.HasMember("parametrized_record"))
956974
record.parametrized_record = IntFloatParametrizedRecord::from_json(doc["parametrized_record"]);
957975
else record.parametrized_record = _atd_missing_json_field<decltype(record.parametrized_record)>("Root", "parametrized_record");
@@ -1040,6 +1058,8 @@ void Root::to_json(const Root &t, rapidjson::Writer<rapidjson::StringBuffer> &wr
10401058
_atd_write_array([](auto v, auto &w){_atd_write_nullable([](auto v, auto &w){_atd_write_int(v, w);}, v, w);}, t.nullables, writer);
10411059
writer.Key("options");
10421060
_atd_write_array([](auto v, auto &w){_atd_write_option([](auto v, auto &w){_atd_write_int(v, w);}, v, w);}, t.options, writer);
1061+
writer.Key("untyped_things");
1062+
_atd_write_array([](auto v, auto &w){_atd_write_abstract(v, w);}, t.untyped_things, writer);
10431063
writer.Key("parametrized_record");
10441064
IntFloatParametrizedRecord::to_json(t.parametrized_record, writer);
10451065
writer.Key("parametrized_tuple");

atdcpp/test/cpp-expected/everything_atd.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ struct Root {
284284
std::map<std::string, int> assoc4;
285285
std::vector<std::optional<int>> nullables;
286286
std::vector<std::optional<int>> options;
287+
std::vector<std::string> untyped_things;
287288
typedefs::IntFloatParametrizedRecord parametrized_record;
288289
typedefs::KindParametrizedTuple parametrized_tuple;
289290
uint16_t wrapped;

0 commit comments

Comments
 (0)