Fawkes API Fawkes Development Version
BlackboardGraph.cpp
1
2/****************************************************************************
3 * BlackboardGraph
4 * (auto-generated, do not modify directly)
5 *
6 * Fawkes Blackboard REST API.
7 * Access blackboard data through a REST API.
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 "BlackboardGraph.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 <sstream>
22
24{
25}
26
27BlackboardGraph::BlackboardGraph(const std::string &json)
28{
29 from_json(json);
30}
31
32BlackboardGraph::BlackboardGraph(const rapidjson::Value &v)
33{
35}
36
38{
39}
40
41std::string
42BlackboardGraph::to_json(bool pretty) const
43{
44 rapidjson::Document d;
45
46 to_json_value(d, d);
47
48 rapidjson::StringBuffer buffer;
49 if (pretty) {
50 rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
51 d.Accept(writer);
52 } else {
53 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
54 d.Accept(writer);
55 }
56
57 return buffer.GetString();
58}
59
60void
61BlackboardGraph::to_json_value(rapidjson::Document &d, rapidjson::Value &v) const
62{
63 rapidjson::Document::AllocatorType &allocator = d.GetAllocator();
64 v.SetObject();
65 // Avoid unused variable warnings
66 (void)allocator;
67
68 if (kind_) {
69 rapidjson::Value v_kind;
70 v_kind.SetString(*kind_, allocator);
71 v.AddMember("kind", v_kind, allocator);
72 }
73 if (apiVersion_) {
74 rapidjson::Value v_apiVersion;
75 v_apiVersion.SetString(*apiVersion_, allocator);
76 v.AddMember("apiVersion", v_apiVersion, allocator);
77 }
78 if (dotgraph_) {
79 rapidjson::Value v_dotgraph;
80 v_dotgraph.SetString(*dotgraph_, allocator);
81 v.AddMember("dotgraph", v_dotgraph, allocator);
82 }
83}
84
85void
86BlackboardGraph::from_json(const std::string &json)
87{
88 rapidjson::Document d;
89 d.Parse(json);
90
92}
93
94void
95BlackboardGraph::from_json_value(const rapidjson::Value &d)
96{
97 if (d.HasMember("kind") && d["kind"].IsString()) {
98 kind_ = d["kind"].GetString();
99 }
100 if (d.HasMember("apiVersion") && d["apiVersion"].IsString()) {
101 apiVersion_ = d["apiVersion"].GetString();
102 }
103 if (d.HasMember("dotgraph") && d["dotgraph"].IsString()) {
104 dotgraph_ = d["dotgraph"].GetString();
105 }
106}
107
108void
109BlackboardGraph::validate(bool subcall) const
110{
111 std::vector<std::string> missing;
112 if (!kind_)
113 missing.push_back("kind");
114 if (!apiVersion_)
115 missing.push_back("apiVersion");
116 if (!dotgraph_)
117 missing.push_back("dotgraph");
118
119 if (!missing.empty()) {
120 if (subcall) {
121 throw missing;
122 } else {
123 std::ostringstream s;
124 s << "BlackboardGraph is missing field" << ((missing.size() > 0) ? "s" : "") << ": ";
125 for (std::vector<std::string>::size_type i = 0; i < missing.size(); ++i) {
126 s << missing[i];
127 if (i < (missing.size() - 1)) {
128 s << ", ";
129 }
130 }
131 throw std::runtime_error(s.str());
132 }
133 }
134}
virtual std::string to_json(bool pretty=false) const
Render object to JSON.
virtual ~BlackboardGraph()
Destructor.
virtual void from_json_value(const rapidjson::Value &v)
Retrieve data from JSON string.
BlackboardGraph()
Constructor.
virtual void validate(bool subcall=false) const
Validate if all required fields have been set.
virtual void from_json(const std::string &json)
Retrieve data from JSON string.
virtual void to_json_value(rapidjson::Document &d, rapidjson::Value &v) const
Render object to JSON.