14 #include "DomainPreconditionCompound.h"
16 #include <rapidjson/document.h>
17 #include <rapidjson/prettywriter.h>
18 #include <rapidjson/stringbuffer.h>
19 #include <rapidjson/writer.h>
44 rapidjson::Document d;
48 rapidjson::StringBuffer buffer;
50 rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
53 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
57 return buffer.GetString();
63 rapidjson::Document::AllocatorType &allocator = d.GetAllocator();
69 rapidjson::Value v_elements(rapidjson::kArrayType);
70 v_elements.Reserve(elements_.size(), allocator);
71 for (
const auto &e : elements_) {
72 rapidjson::Value v(rapidjson::kObjectType);
73 e->to_json_value(d, v);
74 v_elements.PushBack(v, allocator);
76 v.AddMember(
"elements", v_elements, allocator);
82 rapidjson::Document d;
92 if (d.HasMember(
"elements") && d[
"elements"].IsArray()) {
93 const rapidjson::Value &a = d[
"elements"];
94 elements_ = std::vector<std::shared_ptr<DomainPrecondition>>{};
96 elements_.reserve(a.Size());
97 for (
auto &v : a.GetArray()) {
99 nv->from_json_value(v);
100 elements_.push_back(std::move(nv));
108 std::vector<std::string> missing;
111 }
catch (std::vector<std::string> &supertype_missing) {
112 missing.insert(missing.end(), supertype_missing.begin(), supertype_missing.end());
114 for (
size_t i = 0; i < elements_.size(); ++i) {
116 missing.push_back(
"elements[" + std::to_string(i) +
"]");
119 elements_[i]->validate(
true);
120 }
catch (std::vector<std::string> &subcall_missing) {
121 for (
const auto &s : subcall_missing) {
122 missing.push_back(
"elements[" + std::to_string(i) +
"]." + s);
128 if (!missing.empty()) {
132 std::ostringstream s;
133 s <<
"DomainPreconditionCompound is missing field" << ((missing.size() > 0) ?
"s" :
"")
135 for (std::vector<std::string>::size_type i = 0; i < missing.size(); ++i) {
137 if (i < (missing.size() - 1)) {
141 throw std::runtime_error(s.str());