Fawkes API Fawkes Development Version
DomainObjectType.cpp
1
2/****************************************************************************
3 * DomainObjectType
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 "DomainObjectType.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
28DomainObjectType::DomainObjectType(const std::string &json)
29{
30 from_json(json);
31}
32
33DomainObjectType::DomainObjectType(const rapidjson::Value &v)
34{
36}
37
39{
40}
41
42std::string
43DomainObjectType::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
62DomainObjectType::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 (super_type_) {
85 rapidjson::Value v_super_type;
86 v_super_type.SetString(*super_type_, allocator);
87 v.AddMember("super-type", v_super_type, allocator);
88 }
89}
90
91void
92DomainObjectType::from_json(const std::string &json)
93{
94 rapidjson::Document d;
95 d.Parse(json);
96
98}
99
100void
101DomainObjectType::from_json_value(const rapidjson::Value &d)
102{
103 if (d.HasMember("kind") && d["kind"].IsString()) {
104 kind_ = d["kind"].GetString();
105 }
106 if (d.HasMember("apiVersion") && d["apiVersion"].IsString()) {
107 apiVersion_ = d["apiVersion"].GetString();
108 }
109 if (d.HasMember("name") && d["name"].IsString()) {
110 name_ = d["name"].GetString();
111 }
112 if (d.HasMember("super-type") && d["super-type"].IsString()) {
113 super_type_ = d["super-type"].GetString();
114 }
115}
116
117void
118DomainObjectType::validate(bool subcall) const
119{
120 std::vector<std::string> missing;
121 if (!kind_) {
122 missing.push_back("kind");
123 }
124 if (!apiVersion_) {
125 missing.push_back("apiVersion");
126 }
127 if (!name_) {
128 missing.push_back("name");
129 }
130 if (!super_type_) {
131 missing.push_back("super-type");
132 }
133
134 if (!missing.empty()) {
135 if (subcall) {
136 throw missing;
137 } else {
138 std::string s =
139 std::accumulate(std::next(missing.begin()),
140 missing.end(),
141 missing.front(),
142 [](std::string &s, const std::string &n) { return s + ", " + n; });
143 throw std::runtime_error("DomainObjectType is missing " + s);
144 }
145 }
146}
DomainObjectType()
Constructor.
virtual void from_json_value(const rapidjson::Value &v)
Retrieve data from JSON string.
virtual ~DomainObjectType()
Destructor.
virtual void to_json_value(rapidjson::Document &d, rapidjson::Value &v) const
Render object to JSON.
virtual void from_json(const std::string &json)
Retrieve data from JSON string.
virtual std::string to_json(bool pretty=false) const
Render object to JSON.
virtual void validate(bool subcall=false) const
Validate if all required fields have been set.