Fawkes API  Fawkes Development Version
GroundedPDDLPredicate.cpp
1 
2 /****************************************************************************
3  * GroundedPDDLPredicate
4  * (auto-generated, do not modify directly)
5  *
6  * CLIPS Executive REST API.
7  * Enables access to goals, plans, and all items in the domain model.
8  *
9  * API Contact: Tim Niemueller <niemueller@kbsg.rwth-aachen.de>
10  * API Version: v1beta1
11  * API License: Apache 2.0
12  ****************************************************************************/
13 
14 #include "GroundedPDDLPredicate.h"
15 
16 #include <rapidjson/document.h>
17 #include <rapidjson/prettywriter.h>
18 #include <rapidjson/stringbuffer.h>
19 #include <rapidjson/writer.h>
20 
21 #include <numeric>
22 #include <sstream>
23 
25 {
26 }
27 
29 {
30  from_json(json);
31 }
32 
34 {
35  from_json_value(v);
36 }
37 
39 {
40 }
41 
42 std::string
44 {
45  rapidjson::Document d;
46 
47  to_json_value(d, d);
48 
49  rapidjson::StringBuffer buffer;
50  if (pretty) {
51  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
52  d.Accept(writer);
53  } else {
54  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
55  d.Accept(writer);
56  }
57 
58  return buffer.GetString();
59 }
60 
61 void
62 GroundedPDDLPredicate::to_json_value(rapidjson::Document &d, rapidjson::Value &v) const
63 {
64  rapidjson::Document::AllocatorType &allocator = d.GetAllocator();
65  v.SetObject();
66  // Avoid unused variable warnings
67  (void)allocator;
68 
69  if (kind_) {
70  rapidjson::Value v_kind;
71  v_kind.SetString(*kind_, allocator);
72  v.AddMember("kind", v_kind, allocator);
73  }
74  if (apiVersion_) {
75  rapidjson::Value v_apiVersion;
76  v_apiVersion.SetString(*apiVersion_, allocator);
77  v.AddMember("apiVersion", v_apiVersion, allocator);
78  }
79  if (id_) {
80  rapidjson::Value v_id;
81  v_id.SetString(*id_, allocator);
82  v.AddMember("id", v_id, allocator);
83  }
84  if (predicate_id_) {
85  rapidjson::Value v_predicate_id;
86  v_predicate_id.SetString(*predicate_id_, allocator);
87  v.AddMember("predicate-id", v_predicate_id, allocator);
88  }
89  if (grounding_) {
90  rapidjson::Value v_grounding;
91  v_grounding.SetString(*grounding_, allocator);
92  v.AddMember("grounding", v_grounding, allocator);
93  }
94  if (is_satisfied_) {
95  rapidjson::Value v_is_satisfied;
96  v_is_satisfied.SetBool(*is_satisfied_);
97  v.AddMember("is-satisfied", v_is_satisfied, allocator);
98  }
99 }
100 
101 void
102 GroundedPDDLPredicate::from_json(const std::string &json)
103 {
104  rapidjson::Document d;
105  d.Parse(json);
106 
107  from_json_value(d);
108 }
109 
110 void
111 GroundedPDDLPredicate::from_json_value(const rapidjson::Value &d)
112 {
113  if (d.HasMember("kind") && d["kind"].IsString()) {
114  kind_ = d["kind"].GetString();
115  }
116  if (d.HasMember("apiVersion") && d["apiVersion"].IsString()) {
117  apiVersion_ = d["apiVersion"].GetString();
118  }
119  if (d.HasMember("id") && d["id"].IsString()) {
120  id_ = d["id"].GetString();
121  }
122  if (d.HasMember("predicate-id") && d["predicate-id"].IsString()) {
123  predicate_id_ = d["predicate-id"].GetString();
124  }
125  if (d.HasMember("grounding") && d["grounding"].IsString()) {
126  grounding_ = d["grounding"].GetString();
127  }
128  if (d.HasMember("is-satisfied") && d["is-satisfied"].IsBool()) {
129  is_satisfied_ = d["is-satisfied"].GetBool();
130  }
131 }
132 
133 void
135 {
136  std::vector<std::string> missing;
137  if (!kind_) {
138  missing.push_back("kind");
139  }
140  if (!apiVersion_) {
141  missing.push_back("apiVersion");
142  }
143  if (!id_) {
144  missing.push_back("id");
145  }
146  if (!predicate_id_) {
147  missing.push_back("predicate-id");
148  }
149  if (!grounding_) {
150  missing.push_back("grounding");
151  }
152  if (!is_satisfied_) {
153  missing.push_back("is-satisfied");
154  }
155 
156  if (!missing.empty()) {
157  if (subcall) {
158  throw missing;
159  } else {
160  std::string s =
161  std::accumulate(std::next(missing.begin()),
162  missing.end(),
163  missing.front(),
164  [](std::string &s, const std::string &n) { return s + ", " + n; });
165  throw std::runtime_error("GroundedPDDLPredicate is missing " + s);
166  }
167  }
168 }
virtual ~GroundedPDDLPredicate()
Destructor.
virtual void from_json_value(const rapidjson::Value &v)
Retrieve data from JSON string.
virtual std::string to_json(bool pretty=false) const
Render object to JSON.
virtual void from_json(const std::string &json)
Retrieve data from JSON string.
virtual void validate(bool subcall=false) const
Validate if all required fields have been set.
virtual void to_json_value(rapidjson::Document &d, rapidjson::Value &v) const
Render object to JSON.