gusimplewhiteboard
MachineFilteredVision.hpp
Go to the documentation of this file.
1/*
2 * file MachineFilteredVision.hpp
3 *
4 * This file was generated by classgenerator from machine_filtered_vision.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_MachineFilteredVision_h
61#define guWhiteboard_MachineFilteredVision_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_MachineFilteredVision_DEFINED
73#define guWhiteboard_MachineFilteredVision_DEFINED
74
75#undef MachineFilteredVision_DEFINED
76#define MachineFilteredVision_DEFINED
77
78namespace guWhiteboard {
79
84
85 private:
86
90 void init(int8_t t_ball_direction = 0, uint16_t t_ball_distance = 0, bool t_ball_visible = 0, int8_t t_goal_direction = 0, uint16_t t_goal_distance = 0, bool t_goal_visible = 0, enum GoalSightingType t_goal_sightingType = NoSightingType) {
91 set_ball_direction(t_ball_direction);
92 set_ball_distance(t_ball_distance);
93 set_ball_visible(t_ball_visible);
94 set_goal_direction(t_goal_direction);
95 set_goal_distance(t_goal_distance);
96 set_goal_visible(t_goal_visible);
97 set_goal_sightingType(t_goal_sightingType);
98 }
99
100 public:
101
105 MachineFilteredVision(int8_t t_ball_direction = 0, uint16_t t_ball_distance = 0, bool t_ball_visible = 0, int8_t t_goal_direction = 0, uint16_t t_goal_distance = 0, bool t_goal_visible = 0, enum GoalSightingType t_goal_sightingType = NoSightingType) {
106 this->init(t_ball_direction, t_ball_distance, t_ball_visible, t_goal_direction, t_goal_distance, t_goal_visible, t_goal_sightingType);
107 }
108
113 this->init(t_other.ball_direction(), t_other.ball_distance(), t_other.ball_visible(), t_other.goal_direction(), t_other.goal_distance(), t_other.goal_visible(), t_other.goal_sightingType());
114 }
115
120 this->init(t_other.ball_direction, t_other.ball_distance, t_other.ball_visible, t_other.goal_direction, t_other.goal_distance, t_other.goal_visible, t_other.goal_sightingType);
121 }
122
127 this->init(t_other.ball_direction(), t_other.ball_distance(), t_other.ball_visible(), t_other.goal_direction(), t_other.goal_distance(), t_other.goal_visible(), t_other.goal_sightingType());
128 return *this;
129 }
130
135 this->init(t_other.ball_direction, t_other.ball_distance, t_other.ball_visible, t_other.goal_direction, t_other.goal_distance, t_other.goal_visible, t_other.goal_sightingType);
136 return *this;
137 }
138
139 bool operator ==(const MachineFilteredVision &t_other) const
140 {
141 return ball_direction() == t_other.ball_direction()
142 && ball_distance() == t_other.ball_distance()
143 && ball_visible() == t_other.ball_visible()
144 && goal_direction() == t_other.goal_direction()
145 && goal_distance() == t_other.goal_distance()
146 && goal_visible() == t_other.goal_visible()
147 && goal_sightingType() == t_other.goal_sightingType();
148 }
149
150 bool operator !=(const MachineFilteredVision &t_other) const
151 {
152 return !(*this == t_other);
153 }
154
155 bool operator ==(const wb_machine_filtered_vision &t_other) const
156 {
157 return *this == MachineFilteredVision(t_other);
158 }
159
160 bool operator !=(const wb_machine_filtered_vision &t_other) const
161 {
162 return !(*this == t_other);
163 }
164
165 int8_t & ball_direction()
166 {
168 }
169
170 const int8_t & ball_direction() const
171 {
173 }
174
175 void set_ball_direction(const int8_t &t_newValue)
176 {
178 }
179
180 uint16_t & ball_distance()
181 {
183 }
184
185 const uint16_t & ball_distance() const
186 {
188 }
189
190 void set_ball_distance(const uint16_t &t_newValue)
191 {
193 }
194
196 {
198 }
199
200 const bool & ball_visible() const
201 {
203 }
204
205 void set_ball_visible(const bool &t_newValue)
206 {
208 }
209
210 int8_t & goal_direction()
211 {
213 }
214
215 const int8_t & goal_direction() const
216 {
218 }
219
220 void set_goal_direction(const int8_t &t_newValue)
221 {
223 }
224
225 uint16_t & goal_distance()
226 {
228 }
229
230 const uint16_t & goal_distance() const
231 {
233 }
234
235 void set_goal_distance(const uint16_t &t_newValue)
236 {
238 }
239
241 {
243 }
244
245 const bool & goal_visible() const
246 {
248 }
249
250 void set_goal_visible(const bool &t_newValue)
251 {
253 }
254
256 {
258 }
259
261 {
263 }
264
265 void set_goal_sightingType(const enum GoalSightingType &t_newValue)
266 {
268 }
269
270#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
274 MachineFilteredVision(const std::string &t_str) {
275 this->init();
276 this->from_string(t_str);
277 }
278
279 std::string description() {
280#ifdef USE_WB_MACHINE_FILTERED_VISION_C_CONVERSION
282 wb_machine_filtered_vision_description(this, buffer, sizeof(buffer));
283 std::string descr = buffer;
284 return descr;
285#else
286 std::ostringstream ss;
287 ss << "ball_direction=" << static_cast<signed>(this->ball_direction());
288 ss << ", ";
289 ss << "ball_distance=" << static_cast<unsigned>(this->ball_distance());
290 ss << ", ";
291 ss << "ball_visible=" << (this->ball_visible() ? "true" : "false");
292 ss << ", ";
293 ss << "goal_direction=" << static_cast<signed>(this->goal_direction());
294 ss << ", ";
295 ss << "goal_distance=" << static_cast<unsigned>(this->goal_distance());
296 ss << ", ";
297 ss << "goal_visible=" << (this->goal_visible() ? "true" : "false");
298 ss << ", ";
299 switch (this->goal_sightingType()) {
300 case GoalSightingType:
301 {
302 ss << "goal_sightingType=" << "GoalSightingType";
303 break;
304 }
306 {
307 ss << "goal_sightingType=" << "LeftPostSightingType";
308 break;
309 }
310 case NoSightingType:
311 {
312 ss << "goal_sightingType=" << "NoSightingType";
313 break;
314 }
316 {
317 ss << "goal_sightingType=" << "RightPostSightingType";
318 break;
319 }
320 }
321 return ss.str();
322#endif
323 }
324
325 std::string to_string() {
326#ifdef USE_WB_MACHINE_FILTERED_VISION_C_CONVERSION
328 wb_machine_filtered_vision_to_string(this, buffer, sizeof(buffer));
329 std::string toString = buffer;
330 return toString;
331#else
332 std::ostringstream ss;
333 ss << static_cast<signed>(this->ball_direction());
334 ss << ", ";
335 ss << static_cast<unsigned>(this->ball_distance());
336 ss << ", ";
337 ss << (this->ball_visible() ? "true" : "false");
338 ss << ", ";
339 ss << static_cast<signed>(this->goal_direction());
340 ss << ", ";
341 ss << static_cast<unsigned>(this->goal_distance());
342 ss << ", ";
343 ss << (this->goal_visible() ? "true" : "false");
344 ss << ", ";
345 switch (this->goal_sightingType()) {
346 case GoalSightingType:
347 {
348 ss << "GoalSightingType";
349 break;
350 }
352 {
353 ss << "LeftPostSightingType";
354 break;
355 }
356 case NoSightingType:
357 {
358 ss << "NoSightingType";
359 break;
360 }
362 {
363 ss << "RightPostSightingType";
364 break;
365 }
366 }
367 return ss.str();
368#endif
369 }
370
371#ifdef USE_WB_MACHINE_FILTERED_VISION_C_CONVERSION
372 void from_string(const std::string &t_str) {
373 wb_machine_filtered_vision_from_string(this, t_str.c_str());
374#else
375 void from_string(const std::string &t_str) {
376 char * str_cstr = const_cast<char *>(t_str.c_str());
377 size_t temp_length = strlen(str_cstr);
378 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
379 if (length < 1 || length > MACHINE_FILTERED_VISION_DESC_BUFFER_SIZE) {
380 return;
381 }
382 char var_str_buffer[MACHINE_FILTERED_VISION_DESC_BUFFER_SIZE + 1];
383 char* var_str = &var_str_buffer[0];
384 char key_buffer[18];
385 char* key = &key_buffer[0];
386 int bracecount = 0;
387 int startVar = 0;
388 int index = 0;
389 int startKey = 0;
390 int endKey = -1;
391 int varIndex = 0;
392 if (index == 0 && str_cstr[0] == '{') {
393 index = 1;
394 }
395 startVar = index;
396 startKey = startVar;
397 do {
398 for (int i = index; i < length; i++) {
399 index = i + 1;
400 if (bracecount == 0 && str_cstr[i] == '=') {
401 endKey = i - 1;
402 startVar = index;
403 continue;
404 }
405 if (bracecount == 0 && isspace(str_cstr[i])) {
406 startVar = index;
407 if (endKey == -1) {
408 startKey = index;
409 }
410 continue;
411 }
412 if (bracecount == 0 && str_cstr[i] == ',') {
413 index = i - 1;
414 break;
415 }
416 if (str_cstr[i] == '{') {
417 bracecount++;
418 continue;
419 }
420 if (str_cstr[i] == '}') {
421 bracecount--;
422 if (bracecount < 0) {
423 index = i - 1;
424 break;
425 }
426 }
427 if (i == length - 1) {
428 index = i;
429 }
430 }
431 if (endKey >= startKey && endKey - startKey < length) {
432 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
433 key[(endKey - startKey) + 1] = 0;
434 } else {
435 key[0] = 0;
436 }
437 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
438 var_str[(index - startVar) + 1] = 0;
439 bracecount = 0;
440 index += 2;
441 startVar = index;
442 startKey = startVar;
443 endKey = -1;
444 if (strlen(key) > 0) {
445 if (0 == strcmp("ball_direction", key)) {
446 varIndex = 0;
447 } else if (0 == strcmp("ball_distance", key)) {
448 varIndex = 1;
449 } else if (0 == strcmp("ball_visible", key)) {
450 varIndex = 2;
451 } else if (0 == strcmp("goal_direction", key)) {
452 varIndex = 3;
453 } else if (0 == strcmp("goal_distance", key)) {
454 varIndex = 4;
455 } else if (0 == strcmp("goal_visible", key)) {
456 varIndex = 5;
457 } else if (0 == strcmp("goal_sightingType", key)) {
458 varIndex = 6;
459 } else {
460 varIndex = -1;
461 }
462 }
463 switch (varIndex) {
464 case -1: { break; }
465 case 0:
466 {
467 this->set_ball_direction(static_cast<int8_t>(atoi(var_str)));
468 break;
469 }
470 case 1:
471 {
472 this->set_ball_distance(static_cast<uint16_t>(atoi(var_str)));
473 break;
474 }
475 case 2:
476 {
477 this->set_ball_visible(strcmp(var_str, "true") == 0 || strcmp(var_str, "1") == 0);
478 break;
479 }
480 case 3:
481 {
482 this->set_goal_direction(static_cast<int8_t>(atoi(var_str)));
483 break;
484 }
485 case 4:
486 {
487 this->set_goal_distance(static_cast<uint16_t>(atoi(var_str)));
488 break;
489 }
490 case 5:
491 {
492 this->set_goal_visible(strcmp(var_str, "true") == 0 || strcmp(var_str, "1") == 0);
493 break;
494 }
495 case 6:
496 {
497 if (strcmp("GoalSightingType", var_str) == 0) {
498#pragma clang diagnostic push
499#pragma clang diagnostic ignored "-Wbad-function-cast"
501#pragma clang diagnostic pop
502 } else if (strcmp("LeftPostSightingType", var_str) == 0) {
503#pragma clang diagnostic push
504#pragma clang diagnostic ignored "-Wbad-function-cast"
506#pragma clang diagnostic pop
507 } else if (strcmp("NoSightingType", var_str) == 0) {
508#pragma clang diagnostic push
509#pragma clang diagnostic ignored "-Wbad-function-cast"
511#pragma clang diagnostic pop
512 } else if (strcmp("RightPostSightingType", var_str) == 0) {
513#pragma clang diagnostic push
514#pragma clang diagnostic ignored "-Wbad-function-cast"
516#pragma clang diagnostic pop
517 } else {
518#pragma clang diagnostic push
519#pragma clang diagnostic ignored "-Wbad-function-cast"
520 this->set_goal_sightingType(static_cast<enum GoalSightingType>(atoi(var_str)));
521#pragma clang diagnostic pop
522 }
523 break;
524 }
525 }
526 if (varIndex >= 0) {
527 varIndex++;
528 }
529 } while(index < length);
530#endif
531 }
532#endif
533 };
534
535}
536
537#endif
Provides a C++ wrapper around wb_machine_filtered_vision.
void set_goal_visible(const bool &t_newValue)
MachineFilteredVision(const MachineFilteredVision &t_other)
Copy Constructor.
void set_ball_distance(const uint16_t &t_newValue)
void set_ball_visible(const bool &t_newValue)
void set_goal_sightingType(const enum GoalSightingType &t_newValue)
MachineFilteredVision(int8_t t_ball_direction=0, uint16_t t_ball_distance=0, bool t_ball_visible=0, int8_t t_goal_direction=0, uint16_t t_goal_distance=0, bool t_goal_visible=0, enum GoalSightingType t_goal_sightingType=NoSightingType)
Create a new MachineFilteredVision.
enum GoalSightingType & goal_sightingType() const
void set_goal_direction(const int8_t &t_newValue)
MachineFilteredVision & operator=(const MachineFilteredVision &t_other)
Copy Assignment Operator.
bool operator!=(const MachineFilteredVision &t_other) const
void set_goal_distance(const uint16_t &t_newValue)
MachineFilteredVision(const std::string &t_str)
String Constructor.
MachineFilteredVision(const struct wb_machine_filtered_vision &t_other)
Copy Constructor.
void from_string(const std::string &t_str)
void set_ball_direction(const int8_t &t_newValue)
bool operator==(const MachineFilteredVision &t_other) const
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
uint16_t goal_distance
CM distance to the ball.
enum GoalSightingType goal_sightingType
The type of the goal sighting.
bool ball_visible
has the ball been seen enough by vision to be considered actually 'visible'.
bool goal_visible
has the ball been seen enough by vision to be considered actually 'visible'.
uint16_t ball_distance
CM distance to the ball.
int8_t goal_direction
degrees, relative to the center of the nao torso.
int8_t ball_direction
degrees, relative to the center of the nao torso.
const char * wb_machine_filtered_vision_to_string(const struct wb_machine_filtered_vision *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_machine_filtered_vision * wb_machine_filtered_vision_from_string(struct wb_machine_filtered_vision *self, const char *str)
Convert from a string.
const char * wb_machine_filtered_vision_description(const struct wb_machine_filtered_vision *self, char *descString, size_t bufferSize)
Convert to a description string.
#define MACHINE_FILTERED_VISION_TO_STRING_BUFFER_SIZE
#define MACHINE_FILTERED_VISION_DESC_BUFFER_SIZE
@ LeftPostSightingType
@ RightPostSightingType