Fawkes API Fawkes Development Version
Skill.cpp
1
2/****************************************************************************
3 * Skill
4 * (auto-generated, do not modify directly)
5 *
6 * Behavior Engine REST API.
7 * Visualize, monitor, and instruct the Skill Execution Run-Time of
8 * the Lua-based Behavior Engine.
9 *
10 * API Contact: Tim Niemueller <niemueller@kbsg.rwth-aachen.de>
11 * API Version: v1beta1
12 * API License: Apache 2.0
13 ****************************************************************************/
14
15#include "Skill.h"
16
17#include <rapidjson/document.h>
18#include <rapidjson/prettywriter.h>
19#include <rapidjson/stringbuffer.h>
20#include <rapidjson/writer.h>
21
22#include <sstream>
23
25{
26}
27
28Skill::Skill(const std::string &json)
29{
30 from_json(json);
31}
32
33Skill::Skill(const rapidjson::Value &v)
34{
36}
37
39{
40}
41
42std::string
43Skill::to_json(bool pretty) const
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
61void
62Skill::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 (name_) {
80 rapidjson::Value v_name;
81 v_name.SetString(*name_, allocator);
82 v.AddMember("name", v_name, allocator);
83 }
84 if (graph_) {
85 rapidjson::Value v_graph;
86 v_graph.SetString(*graph_, allocator);
87 v.AddMember("graph", v_graph, allocator);
88 }
89 if (skill_string_) {
90 rapidjson::Value v_skill_string;
91 v_skill_string.SetString(*skill_string_, allocator);
92 v.AddMember("skill-string", v_skill_string, allocator);
93 }
94 if (error_) {
95 rapidjson::Value v_error;
96 v_error.SetString(*error_, allocator);
97 v.AddMember("error", v_error, allocator);
98 }
99 if (msg_id_) {
100 rapidjson::Value v_msg_id;
101 v_msg_id.SetInt64(*msg_id_);
102 v.AddMember("msg_id", v_msg_id, allocator);
103 }
104 if (exclusive_controller_) {
105 rapidjson::Value v_exclusive_controller;
106 v_exclusive_controller.SetString(*exclusive_controller_, allocator);
107 v.AddMember("exclusive_controller", v_exclusive_controller, allocator);
108 }
109 if (status_) {
110 rapidjson::Value v_status;
111 v_status.SetString(*status_, allocator);
112 v.AddMember("status", v_status, allocator);
113 }
114}
115
116void
117Skill::from_json(const std::string &json)
118{
119 rapidjson::Document d;
120 d.Parse(json);
121
123}
124
125void
126Skill::from_json_value(const rapidjson::Value &d)
127{
128 if (d.HasMember("kind") && d["kind"].IsString()) {
129 kind_ = d["kind"].GetString();
130 }
131 if (d.HasMember("apiVersion") && d["apiVersion"].IsString()) {
132 apiVersion_ = d["apiVersion"].GetString();
133 }
134 if (d.HasMember("name") && d["name"].IsString()) {
135 name_ = d["name"].GetString();
136 }
137 if (d.HasMember("graph") && d["graph"].IsString()) {
138 graph_ = d["graph"].GetString();
139 }
140 if (d.HasMember("skill-string") && d["skill-string"].IsString()) {
141 skill_string_ = d["skill-string"].GetString();
142 }
143 if (d.HasMember("error") && d["error"].IsString()) {
144 error_ = d["error"].GetString();
145 }
146 if (d.HasMember("msg_id") && d["msg_id"].IsInt64()) {
147 msg_id_ = d["msg_id"].GetInt64();
148 }
149 if (d.HasMember("exclusive_controller") && d["exclusive_controller"].IsInt64()) {
150 exclusive_controller_ = d["exclusive_controller"].GetString();
151 }
152 if (d.HasMember("status") && d["status"].IsString()) {
153 status_ = d["status"].GetString();
154 }
155}
156
157void
158Skill::validate(bool subcall) const
159{
160 std::vector<std::string> missing;
161 if (!kind_)
162 missing.push_back("kind");
163 if (!apiVersion_)
164 missing.push_back("apiVersion");
165 if (!name_)
166 missing.push_back("name");
167
168 if (!missing.empty()) {
169 if (subcall) {
170 throw missing;
171 } else {
172 std::ostringstream s;
173 s << "Skill is missing field" << ((missing.size() > 0) ? "s" : "") << ": ";
174 for (std::vector<std::string>::size_type i = 0; i < missing.size(); ++i) {
175 s << missing[i];
176 if (i < (missing.size() - 1)) {
177 s << ", ";
178 }
179 }
180 throw std::runtime_error(s.str());
181 }
182 }
183}
Skill()
Constructor.
Definition: Skill.cpp:24
virtual void validate(bool subcall=false) const
Validate if all required fields have been set.
Definition: Skill.cpp:158
virtual void to_json_value(rapidjson::Document &d, rapidjson::Value &v) const
Render object to JSON.
Definition: Skill.cpp:62
virtual std::string to_json(bool pretty=false) const
Render object to JSON.
Definition: Skill.cpp:43
virtual ~Skill()
Destructor.
Definition: Skill.cpp:38
virtual void from_json(const std::string &json)
Retrieve data from JSON string.
Definition: Skill.cpp:117
virtual void from_json_value(const rapidjson::Value &v)
Retrieve data from JSON string.
Definition: Skill.cpp:126