gusimplewhiteboard
VisionDetectionGoal.hpp
Go to the documentation of this file.
1/*
2 * file VisionDetectionGoal.hpp
3 *
4 * This file was generated by classgenerator from vision_detection_goal.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Carl Lusty. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials
19 * provided with the distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgement:
23 *
24 * This product includes software developed by Carl Lusty.
25 *
26 * 4. Neither the name of the author nor the names of contributors
27 * may be used to endorse or promote products derived from this
28 * software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
34 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * -----------------------------------------------------------------------
43 * This program is free software; you can redistribute it and/or
44 * modify it under the above terms or under the terms of the GNU
45 * General Public License as published by the Free Software Foundation;
46 * either version 2 of the License, or (at your option) any later version.
47 *
48 * This program is distributed in the hope that it will be useful,
49 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 * GNU General Public License for more details.
52 *
53 * You should have received a copy of the GNU General Public License
54 * along with this program; if not, see http://www.gnu.org/licenses/
55 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
56 * Fifth Floor, Boston, MA 02110-1301, USA.
57 *
58 */
59
60#ifndef guWhiteboard_VisionDetectionGoal_h
61#define guWhiteboard_VisionDetectionGoal_h
62
63#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
64#include <cstdlib>
65#include <string.h>
66#include <sstream>
67#endif
68
69#include <gu_util.h>
71
72#undef guWhiteboard_VisionDetectionGoal_DEFINED
73#define guWhiteboard_VisionDetectionGoal_DEFINED
74
75#undef VisionDetectionGoal_DEFINED
76#define VisionDetectionGoal_DEFINED
77
79
80namespace guWhiteboard {
81
86
87 private:
88
93 set_sightingType(t_sightingType);
94 set_post1(t_post1);
95 set_post2(t_post2);
96 }
97
98 public:
99
104 this->init(t_sightingType, t_post1, t_post2);
105 }
106
111 this->init(t_other.sightingType(), t_other.post1(), t_other.post2());
112 }
113
118 this->init(t_other.sightingType, t_other.post1, t_other.post2);
119 }
120
125 this->init(t_other.sightingType(), t_other.post1(), t_other.post2());
126 return *this;
127 }
128
133 this->init(t_other.sightingType, t_other.post1, t_other.post2);
134 return *this;
135 }
136
137 bool operator ==(const VisionDetectionGoal &t_other) const
138 {
139 return sightingType() == t_other.sightingType()
142 }
143
144 bool operator !=(const VisionDetectionGoal &t_other) const
145 {
146 return !(*this == t_other);
147 }
148
149 bool operator ==(const wb_vision_detection_goal &t_other) const
150 {
151 return *this == VisionDetectionGoal(t_other);
152 }
153
154 bool operator !=(const wb_vision_detection_goal &t_other) const
155 {
156 return !(*this == t_other);
157 }
158
160 {
162 }
163
164 const enum GoalOptions & sightingType() const
165 {
167 }
168
169 void set_sightingType(const enum GoalOptions &t_newValue)
170 {
172 }
173
175 {
176 return const_cast<VisionDetectionGoalPost &>(static_cast<const VisionDetectionGoalPost &>(wb_vision_detection_goal::post1));
177 }
178
180 {
181 return static_cast<const VisionDetectionGoalPost &>(wb_vision_detection_goal::post1);
182 }
183
184 void set_post1(const VisionDetectionGoalPost &t_newValue)
185 {
187 }
188
190 {
191 return const_cast<VisionDetectionGoalPost &>(static_cast<const VisionDetectionGoalPost &>(wb_vision_detection_goal::post2));
192 }
193
195 {
196 return static_cast<const VisionDetectionGoalPost &>(wb_vision_detection_goal::post2);
197 }
198
199 void set_post2(const VisionDetectionGoalPost &t_newValue)
200 {
202 }
203
204#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
208 VisionDetectionGoal(const std::string &t_str) {
209 this->init();
210 this->from_string(t_str);
211 }
212
213 std::string description() {
214#ifdef USE_WB_VISION_DETECTION_GOAL_C_CONVERSION
216 wb_vision_detection_goal_description(this, buffer, sizeof(buffer));
217 std::string descr = buffer;
218 return descr;
219#else
220 std::ostringstream ss;
221 switch (this->sightingType()) {
222 case DoublePostGoal:
223 {
224 ss << "sightingType=" << "DoublePostGoal";
225 break;
226 }
227 case NoGoalDetected:
228 {
229 ss << "sightingType=" << "NoGoalDetected";
230 break;
231 }
232 case SinglePostGoal:
233 {
234 ss << "sightingType=" << "SinglePostGoal";
235 break;
236 }
237 }
238 ss << ", ";
239 ss << "post1=" << "{" << VisionDetectionGoalPost(this->post1()).description() << "}";
240 ss << ", ";
241 ss << "post2=" << "{" << VisionDetectionGoalPost(this->post2()).description() << "}";
242 return ss.str();
243#endif
244 }
245
246 std::string to_string() {
247#ifdef USE_WB_VISION_DETECTION_GOAL_C_CONVERSION
249 wb_vision_detection_goal_to_string(this, buffer, sizeof(buffer));
250 std::string toString = buffer;
251 return toString;
252#else
253 std::ostringstream ss;
254 switch (this->sightingType()) {
255 case DoublePostGoal:
256 {
257 ss << "DoublePostGoal";
258 break;
259 }
260 case NoGoalDetected:
261 {
262 ss << "NoGoalDetected";
263 break;
264 }
265 case SinglePostGoal:
266 {
267 ss << "SinglePostGoal";
268 break;
269 }
270 }
271 ss << ", ";
272 ss << "{" << VisionDetectionGoalPost(this->post1()).to_string() << "}";
273 ss << ", ";
274 ss << "{" << VisionDetectionGoalPost(this->post2()).to_string() << "}";
275 return ss.str();
276#endif
277 }
278
279#ifdef USE_WB_VISION_DETECTION_GOAL_C_CONVERSION
280 void from_string(const std::string &t_str) {
281 wb_vision_detection_goal_from_string(this, t_str.c_str());
282#else
283 void from_string(const std::string &t_str) {
284 char * str_cstr = const_cast<char *>(t_str.c_str());
285 size_t temp_length = strlen(str_cstr);
286 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
287 if (length < 1 || length > VISION_DETECTION_GOAL_DESC_BUFFER_SIZE) {
288 return;
289 }
290 char var_str_buffer[VISION_DETECTION_GOAL_DESC_BUFFER_SIZE + 1];
291 char* var_str = &var_str_buffer[0];
292 char key_buffer[13];
293 char* key = &key_buffer[0];
294 int bracecount = 0;
295 int startVar = 0;
296 int index = 0;
297 int startKey = 0;
298 int endKey = -1;
299 int varIndex = 0;
300 if (index == 0 && str_cstr[0] == '{') {
301 index = 1;
302 }
303 startVar = index;
304 startKey = startVar;
305 do {
306 for (int i = index; i < length; i++) {
307 index = i + 1;
308 if (bracecount == 0 && str_cstr[i] == '=') {
309 endKey = i - 1;
310 startVar = index;
311 continue;
312 }
313 if (bracecount == 0 && isspace(str_cstr[i])) {
314 startVar = index;
315 if (endKey == -1) {
316 startKey = index;
317 }
318 continue;
319 }
320 if (bracecount == 0 && str_cstr[i] == ',') {
321 index = i - 1;
322 break;
323 }
324 if (str_cstr[i] == '{') {
325 bracecount++;
326 continue;
327 }
328 if (str_cstr[i] == '}') {
329 bracecount--;
330 if (bracecount < 0) {
331 index = i - 1;
332 break;
333 }
334 }
335 if (i == length - 1) {
336 index = i;
337 }
338 }
339 if (endKey >= startKey && endKey - startKey < length) {
340 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
341 key[(endKey - startKey) + 1] = 0;
342 } else {
343 key[0] = 0;
344 }
345 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
346 var_str[(index - startVar) + 1] = 0;
347 bracecount = 0;
348 index += 2;
349 startVar = index;
350 startKey = startVar;
351 endKey = -1;
352 if (strlen(key) > 0) {
353 if (0 == strcmp("sightingType", key)) {
354 varIndex = 0;
355 } else if (0 == strcmp("post1", key)) {
356 varIndex = 1;
357 } else if (0 == strcmp("post2", key)) {
358 varIndex = 2;
359 } else {
360 varIndex = -1;
361 }
362 }
363 switch (varIndex) {
364 case -1: { break; }
365 case 0:
366 {
367 if (strcmp("DoublePostGoal", var_str) == 0) {
368#pragma clang diagnostic push
369#pragma clang diagnostic ignored "-Wbad-function-cast"
371#pragma clang diagnostic pop
372 } else if (strcmp("NoGoalDetected", var_str) == 0) {
373#pragma clang diagnostic push
374#pragma clang diagnostic ignored "-Wbad-function-cast"
376#pragma clang diagnostic pop
377 } else if (strcmp("SinglePostGoal", var_str) == 0) {
378#pragma clang diagnostic push
379#pragma clang diagnostic ignored "-Wbad-function-cast"
381#pragma clang diagnostic pop
382 } else {
383#pragma clang diagnostic push
384#pragma clang diagnostic ignored "-Wbad-function-cast"
385 this->set_sightingType(static_cast<enum GoalOptions>(atoi(var_str)));
386#pragma clang diagnostic pop
387 }
388 break;
389 }
390 case 1:
391 {
393 post1_temp.from_string(var_str);
394 this->set_post1(post1_temp);
395 break;
396 }
397 case 2:
398 {
400 post2_temp.from_string(var_str);
401 this->set_post2(post2_temp);
402 break;
403 }
404 }
405 if (varIndex >= 0) {
406 varIndex++;
407 }
408 } while(index < length);
409#endif
410 }
411#endif
412 };
413
414}
415
416#endif
Provides a C++ wrapper around wb_vision_detection_goal.
void from_string(const std::string &t_str)
VisionDetectionGoal(enum GoalOptions t_sightingType=NoGoalDetected, struct wb_vision_detection_goal_post t_post1=wb_vision_detection_goal_post(), struct wb_vision_detection_goal_post t_post2=wb_vision_detection_goal_post())
Create a new VisionDetectionGoal.
VisionDetectionGoalPost & post2()
void set_sightingType(const enum GoalOptions &t_newValue)
VisionDetectionGoal(const struct wb_vision_detection_goal &t_other)
Copy Constructor.
VisionDetectionGoalPost & post1()
VisionDetectionGoal & operator=(const VisionDetectionGoal &t_other)
Copy Assignment Operator.
const VisionDetectionGoalPost & post2() const
enum GoalOptions & sightingType() const
bool operator!=(const VisionDetectionGoal &t_other) const
VisionDetectionGoal(const std::string &t_str)
String Constructor.
void set_post1(const VisionDetectionGoalPost &t_newValue)
void set_post2(const VisionDetectionGoalPost &t_newValue)
const VisionDetectionGoalPost & post1() const
bool operator==(const VisionDetectionGoal &t_other) const
VisionDetectionGoal(const VisionDetectionGoal &t_other)
Copy Constructor.
Provides a C++ wrapper around wb_vision_detection_goal_post.
void from_string(const std::string &t_str)
std::string to_string()
std::string description()
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
WHITEBOARD_POSTER_STRING_CONVERSION.
struct wb_vision_detection_goal_post post2
Second post found.
enum GoalOptions sightingType
Goal detection details.
struct wb_vision_detection_goal_post post1
First post found.
const char * wb_vision_detection_goal_description(const struct wb_vision_detection_goal *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_vision_detection_goal_to_string(const struct wb_vision_detection_goal *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_vision_detection_goal * wb_vision_detection_goal_from_string(struct wb_vision_detection_goal *self, const char *str)
Convert from a string.
#define VISION_DETECTION_GOAL_TO_STRING_BUFFER_SIZE
#define VISION_DETECTION_GOAL_DESC_BUFFER_SIZE