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