Fawkes API Fawkes Development Version
DomainOperatorParameter.cpp
1
2/****************************************************************************
3 * DomainOperatorParameter
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 "DomainOperatorParameter.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{
36}
37
39{
40}
41
42std::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
61void
62DomainOperatorParameter::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 (name_) {
70 rapidjson::Value v_name;
71 v_name.SetString(*name_, allocator);
72 v.AddMember("name", v_name, allocator);
73 }
74 if (type_) {
75 rapidjson::Value v_type;
76 v_type.SetString(*type_, allocator);
77 v.AddMember("type", v_type, allocator);
78 }
79}
80
81void
82DomainOperatorParameter::from_json(const std::string &json)
83{
84 rapidjson::Document d;
85 d.Parse(json);
86
88}
89
90void
92{
93 if (d.HasMember("name") && d["name"].IsString()) {
94 name_ = d["name"].GetString();
95 }
96 if (d.HasMember("type") && d["type"].IsString()) {
97 type_ = d["type"].GetString();
98 }
99}
100
101void
103{
104 std::vector<std::string> missing;
105 if (!name_) {
106 missing.push_back("name");
107 }
108 if (!type_) {
109 missing.push_back("type");
110 }
111
112 if (!missing.empty()) {
113 if (subcall) {
114 throw missing;
115 } else {
116 std::string s =
117 std::accumulate(std::next(missing.begin()),
118 missing.end(),
119 missing.front(),
120 [](std::string &s, const std::string &n) { return s + ", " + n; });
121 throw std::runtime_error("DomainOperatorParameter is missing " + s);
122 }
123 }
124}
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.
virtual std::string to_json(bool pretty=false) const
Render object to JSON.
virtual void from_json_value(const rapidjson::Value &v)
Retrieve data from JSON string.
virtual void from_json(const std::string &json)
Retrieve data from JSON string.
virtual ~DomainOperatorParameter()
Destructor.