Fawkes API Fawkes Development Version
ImageInfo.cpp
1
2/****************************************************************************
3 * ImageInfo
4 * (auto-generated, do not modify directly)
5 *
6 * Fawkes Image REST API.
7 * Access images 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 "ImageInfo.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
27ImageInfo::ImageInfo(const std::string &json)
28{
29 from_json(json);
30}
31
32ImageInfo::ImageInfo(const rapidjson::Value &v)
33{
35}
36
38{
39}
40
41std::string
42ImageInfo::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
61ImageInfo::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 (id_) {
79 rapidjson::Value v_id;
80 v_id.SetString(*id_, allocator);
81 v.AddMember("id", v_id, allocator);
82 }
83 if (colorspace_) {
84 rapidjson::Value v_colorspace;
85 v_colorspace.SetString(*colorspace_, allocator);
86 v.AddMember("colorspace", v_colorspace, allocator);
87 }
88 if (frame_) {
89 rapidjson::Value v_frame;
90 v_frame.SetString(*frame_, allocator);
91 v.AddMember("frame", v_frame, allocator);
92 }
93 if (width_) {
94 rapidjson::Value v_width;
95 v_width.SetInt64(*width_);
96 v.AddMember("width", v_width, allocator);
97 }
98 if (height_) {
99 rapidjson::Value v_height;
100 v_height.SetInt64(*height_);
101 v.AddMember("height", v_height, allocator);
102 }
103 if (mem_size_) {
104 rapidjson::Value v_mem_size;
105 v_mem_size.SetInt64(*mem_size_);
106 v.AddMember("mem_size", v_mem_size, allocator);
107 }
108}
109
110void
111ImageInfo::from_json(const std::string &json)
112{
113 rapidjson::Document d;
114 d.Parse(json);
115
117}
118
119void
120ImageInfo::from_json_value(const rapidjson::Value &d)
121{
122 if (d.HasMember("kind") && d["kind"].IsString()) {
123 kind_ = d["kind"].GetString();
124 }
125 if (d.HasMember("apiVersion") && d["apiVersion"].IsString()) {
126 apiVersion_ = d["apiVersion"].GetString();
127 }
128 if (d.HasMember("id") && d["id"].IsString()) {
129 id_ = d["id"].GetString();
130 }
131 if (d.HasMember("colorspace") && d["colorspace"].IsString()) {
132 colorspace_ = d["colorspace"].GetString();
133 }
134 if (d.HasMember("frame") && d["frame"].IsString()) {
135 frame_ = d["frame"].GetString();
136 }
137 if (d.HasMember("width") && d["width"].IsInt64()) {
138 width_ = d["width"].GetInt64();
139 }
140 if (d.HasMember("height") && d["height"].IsInt64()) {
141 height_ = d["height"].GetInt64();
142 }
143 if (d.HasMember("mem_size") && d["mem_size"].IsInt64()) {
144 mem_size_ = d["mem_size"].GetInt64();
145 }
146}
147
148void
149ImageInfo::validate(bool subcall) const
150{
151 std::vector<std::string> missing;
152 if (!kind_)
153 missing.push_back("kind");
154 if (!apiVersion_)
155 missing.push_back("apiVersion");
156 if (!id_)
157 missing.push_back("id");
158 if (!colorspace_)
159 missing.push_back("colorspace");
160 if (!frame_)
161 missing.push_back("frame");
162 if (!width_)
163 missing.push_back("width");
164 if (!height_)
165 missing.push_back("height");
166 if (!mem_size_)
167 missing.push_back("mem_size");
168
169 if (!missing.empty()) {
170 if (subcall) {
171 throw missing;
172 } else {
173 std::ostringstream s;
174 s << "ImageInfo is missing field" << ((missing.size() > 0) ? "s" : "") << ": ";
175 for (std::vector<std::string>::size_type i = 0; i < missing.size(); ++i) {
176 s << missing[i];
177 if (i < (missing.size() - 1)) {
178 s << ", ";
179 }
180 }
181 throw std::runtime_error(s.str());
182 }
183 }
184}
ImageInfo()
Constructor.
Definition: ImageInfo.cpp:23
virtual void from_json_value(const rapidjson::Value &v)
Retrieve data from JSON string.
Definition: ImageInfo.cpp:120
virtual void from_json(const std::string &json)
Retrieve data from JSON string.
Definition: ImageInfo.cpp:111
virtual std::string to_json(bool pretty=false) const
Render object to JSON.
Definition: ImageInfo.cpp:42
virtual void to_json_value(rapidjson::Document &d, rapidjson::Value &v) const
Render object to JSON.
Definition: ImageInfo.cpp:61
virtual void validate(bool subcall=false) const
Validate if all required fields have been set.
Definition: ImageInfo.cpp:149
virtual ~ImageInfo()
Destructor.
Definition: ImageInfo.cpp:37