gusimplewhiteboard
LandmarkSighting.hpp
Go to the documentation of this file.
1/*
2 * file LandmarkSighting.hpp
3 *
4 * This file was generated by classgenerator from landmark_sighting.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Callum McColl. 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 Callum McColl.
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_LandmarkSighting_h
61#define guWhiteboard_LandmarkSighting_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_LandmarkSighting_DEFINED
73#define guWhiteboard_LandmarkSighting_DEFINED
74
75#undef LandmarkSighting_DEFINED
76#define LandmarkSighting_DEFINED
77
78namespace guWhiteboard {
79
84
85 private:
86
90 void init(int16_t t_direction = 0, uint16_t t_distance = 0, enum LandmarkSightingType t_sightingType = static_cast<enum LandmarkSightingType>(0)) {
91 set_direction(t_direction);
92 set_distance(t_distance);
93 set_sightingType(t_sightingType);
94 }
95
96 public:
97
101 LandmarkSighting(int16_t t_direction = 0, uint16_t t_distance = 0, enum LandmarkSightingType t_sightingType = static_cast<enum LandmarkSightingType>(0)) {
102 this->init(t_direction, t_distance, t_sightingType);
103 }
104
109 this->init(t_other.direction(), t_other.distance(), t_other.sightingType());
110 }
111
116 this->init(t_other.direction, t_other.distance, t_other.sightingType);
117 }
118
123 this->init(t_other.direction(), t_other.distance(), t_other.sightingType());
124 return *this;
125 }
126
131 this->init(t_other.direction, t_other.distance, t_other.sightingType);
132 return *this;
133 }
134
135 bool operator ==(const LandmarkSighting &t_other) const
136 {
137 return direction() == t_other.direction()
138 && distance() == t_other.distance()
139 && sightingType() == t_other.sightingType();
140 }
141
142 bool operator !=(const LandmarkSighting &t_other) const
143 {
144 return !(*this == t_other);
145 }
146
147 bool operator ==(const wb_landmark_sighting &t_other) const
148 {
149 return *this == LandmarkSighting(t_other);
150 }
151
152 bool operator !=(const wb_landmark_sighting &t_other) const
153 {
154 return !(*this == t_other);
155 }
156
157 int16_t & direction()
158 {
160 }
161
162 const int16_t & direction() const
163 {
165 }
166
167 void set_direction(const int16_t &t_newValue)
168 {
170 }
171
172 uint16_t & distance()
173 {
175 }
176
177 const uint16_t & distance() const
178 {
180 }
181
182 void set_distance(const uint16_t &t_newValue)
183 {
185 }
186
188 {
190 }
191
193 {
195 }
196
197 void set_sightingType(const enum LandmarkSightingType &t_newValue)
198 {
200 }
201
202#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
206 LandmarkSighting(const std::string &t_str) {
207 this->init();
208 this->from_string(t_str);
209 }
210
211 std::string description() {
212#ifdef USE_WB_LANDMARK_SIGHTING_C_CONVERSION
214 wb_landmark_sighting_description(this, buffer, sizeof(buffer));
215 std::string descr = buffer;
216 return descr;
217#else
218 std::ostringstream ss;
219 ss << "direction=" << static_cast<signed>(this->direction());
220 ss << ", ";
221 ss << "distance=" << static_cast<unsigned>(this->distance());
222 ss << ", ";
223 switch (this->sightingType()) {
224 case BallSightingType:
225 {
226 ss << "sightingType=" << "BallSightingType";
227 break;
228 }
230 {
231 ss << "sightingType=" << "CornerHorizonSightingType";
232 break;
233 }
235 {
236 ss << "sightingType=" << "CornerLineSightingType";
237 break;
238 }
240 {
241 ss << "sightingType=" << "CrossLineSightingType";
242 break;
243 }
245 {
246 ss << "sightingType=" << "GenericGoalPostSightingType";
247 break;
248 }
250 {
251 ss << "sightingType=" << "GoalLandmarkSightingType";
252 break;
253 }
255 {
256 ss << "sightingType=" << "LeftGoalPostSightingType";
257 break;
258 }
260 {
261 ss << "sightingType=" << "LineHorizonSightingType";
262 break;
263 }
265 {
266 ss << "sightingType=" << "RightGoalPostSightingType";
267 break;
268 }
270 {
271 ss << "sightingType=" << "StraightLineSightingType";
272 break;
273 }
275 {
276 ss << "sightingType=" << "TIntersectionLineSightingType";
277 break;
278 }
279 }
280 return ss.str();
281#endif
282 }
283
284 std::string to_string() {
285#ifdef USE_WB_LANDMARK_SIGHTING_C_CONVERSION
287 wb_landmark_sighting_to_string(this, buffer, sizeof(buffer));
288 std::string toString = buffer;
289 return toString;
290#else
291 std::ostringstream ss;
292 ss << static_cast<signed>(this->direction());
293 ss << ", ";
294 ss << static_cast<unsigned>(this->distance());
295 ss << ", ";
296 switch (this->sightingType()) {
297 case BallSightingType:
298 {
299 ss << "BallSightingType";
300 break;
301 }
303 {
304 ss << "CornerHorizonSightingType";
305 break;
306 }
308 {
309 ss << "CornerLineSightingType";
310 break;
311 }
313 {
314 ss << "CrossLineSightingType";
315 break;
316 }
318 {
319 ss << "GenericGoalPostSightingType";
320 break;
321 }
323 {
324 ss << "GoalLandmarkSightingType";
325 break;
326 }
328 {
329 ss << "LeftGoalPostSightingType";
330 break;
331 }
333 {
334 ss << "LineHorizonSightingType";
335 break;
336 }
338 {
339 ss << "RightGoalPostSightingType";
340 break;
341 }
343 {
344 ss << "StraightLineSightingType";
345 break;
346 }
348 {
349 ss << "TIntersectionLineSightingType";
350 break;
351 }
352 }
353 return ss.str();
354#endif
355 }
356
357#ifdef USE_WB_LANDMARK_SIGHTING_C_CONVERSION
358 void from_string(const std::string &t_str) {
359 wb_landmark_sighting_from_string(this, t_str.c_str());
360#else
361 void from_string(const std::string &t_str) {
362 char * str_cstr = const_cast<char *>(t_str.c_str());
363 size_t temp_length = strlen(str_cstr);
364 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
365 if (length < 1 || length > LANDMARK_SIGHTING_DESC_BUFFER_SIZE) {
366 return;
367 }
368 char var_str_buffer[LANDMARK_SIGHTING_DESC_BUFFER_SIZE + 1];
369 char* var_str = &var_str_buffer[0];
370 char key_buffer[13];
371 char* key = &key_buffer[0];
372 int bracecount = 0;
373 int startVar = 0;
374 int index = 0;
375 int startKey = 0;
376 int endKey = -1;
377 int varIndex = 0;
378 if (index == 0 && str_cstr[0] == '{') {
379 index = 1;
380 }
381 startVar = index;
382 startKey = startVar;
383 do {
384 for (int i = index; i < length; i++) {
385 index = i + 1;
386 if (bracecount == 0 && str_cstr[i] == '=') {
387 endKey = i - 1;
388 startVar = index;
389 continue;
390 }
391 if (bracecount == 0 && isspace(str_cstr[i])) {
392 startVar = index;
393 if (endKey == -1) {
394 startKey = index;
395 }
396 continue;
397 }
398 if (bracecount == 0 && str_cstr[i] == ',') {
399 index = i - 1;
400 break;
401 }
402 if (str_cstr[i] == '{') {
403 bracecount++;
404 continue;
405 }
406 if (str_cstr[i] == '}') {
407 bracecount--;
408 if (bracecount < 0) {
409 index = i - 1;
410 break;
411 }
412 }
413 if (i == length - 1) {
414 index = i;
415 }
416 }
417 if (endKey >= startKey && endKey - startKey < length) {
418 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
419 key[(endKey - startKey) + 1] = 0;
420 } else {
421 key[0] = 0;
422 }
423 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
424 var_str[(index - startVar) + 1] = 0;
425 bracecount = 0;
426 index += 2;
427 startVar = index;
428 startKey = startVar;
429 endKey = -1;
430 if (strlen(key) > 0) {
431 if (0 == strcmp("direction", key)) {
432 varIndex = 0;
433 } else if (0 == strcmp("distance", key)) {
434 varIndex = 1;
435 } else if (0 == strcmp("sightingType", key)) {
436 varIndex = 2;
437 } else {
438 varIndex = -1;
439 }
440 }
441 switch (varIndex) {
442 case -1: { break; }
443 case 0:
444 {
445 this->set_direction(static_cast<int16_t>(atoi(var_str)));
446 break;
447 }
448 case 1:
449 {
450 this->set_distance(static_cast<uint16_t>(atoi(var_str)));
451 break;
452 }
453 case 2:
454 {
455 if (strcmp("BallSightingType", var_str) == 0) {
456#pragma clang diagnostic push
457#pragma clang diagnostic ignored "-Wbad-function-cast"
459#pragma clang diagnostic pop
460 } else if (strcmp("CornerHorizonSightingType", var_str) == 0) {
461#pragma clang diagnostic push
462#pragma clang diagnostic ignored "-Wbad-function-cast"
464#pragma clang diagnostic pop
465 } else if (strcmp("CornerLineSightingType", var_str) == 0) {
466#pragma clang diagnostic push
467#pragma clang diagnostic ignored "-Wbad-function-cast"
469#pragma clang diagnostic pop
470 } else if (strcmp("CrossLineSightingType", var_str) == 0) {
471#pragma clang diagnostic push
472#pragma clang diagnostic ignored "-Wbad-function-cast"
474#pragma clang diagnostic pop
475 } else if (strcmp("GenericGoalPostSightingType", var_str) == 0) {
476#pragma clang diagnostic push
477#pragma clang diagnostic ignored "-Wbad-function-cast"
479#pragma clang diagnostic pop
480 } else if (strcmp("GoalLandmarkSightingType", var_str) == 0) {
481#pragma clang diagnostic push
482#pragma clang diagnostic ignored "-Wbad-function-cast"
484#pragma clang diagnostic pop
485 } else if (strcmp("LeftGoalPostSightingType", var_str) == 0) {
486#pragma clang diagnostic push
487#pragma clang diagnostic ignored "-Wbad-function-cast"
489#pragma clang diagnostic pop
490 } else if (strcmp("LineHorizonSightingType", var_str) == 0) {
491#pragma clang diagnostic push
492#pragma clang diagnostic ignored "-Wbad-function-cast"
494#pragma clang diagnostic pop
495 } else if (strcmp("RightGoalPostSightingType", var_str) == 0) {
496#pragma clang diagnostic push
497#pragma clang diagnostic ignored "-Wbad-function-cast"
499#pragma clang diagnostic pop
500 } else if (strcmp("StraightLineSightingType", var_str) == 0) {
501#pragma clang diagnostic push
502#pragma clang diagnostic ignored "-Wbad-function-cast"
504#pragma clang diagnostic pop
505 } else if (strcmp("TIntersectionLineSightingType", var_str) == 0) {
506#pragma clang diagnostic push
507#pragma clang diagnostic ignored "-Wbad-function-cast"
509#pragma clang diagnostic pop
510 } else {
511#pragma clang diagnostic push
512#pragma clang diagnostic ignored "-Wbad-function-cast"
513 this->set_sightingType(static_cast<enum LandmarkSightingType>(atoi(var_str)));
514#pragma clang diagnostic pop
515 }
516 break;
517 }
518 }
519 if (varIndex >= 0) {
520 varIndex++;
521 }
522 } while(index < length);
523#endif
524 }
525#endif
526 };
527
528}
529
530#endif
Provides a C++ wrapper around wb_landmark_sighting.
LandmarkSighting & operator=(const LandmarkSighting &t_other)
Copy Assignment Operator.
void set_direction(const int16_t &t_newValue)
void set_sightingType(const enum LandmarkSightingType &t_newValue)
void from_string(const std::string &t_str)
const int16_t & direction() const
bool operator==(const LandmarkSighting &t_other) const
const uint16_t & distance() const
LandmarkSighting(const std::string &t_str)
String Constructor.
LandmarkSighting(int16_t t_direction=0, uint16_t t_distance=0, enum LandmarkSightingType t_sightingType=static_cast< enum LandmarkSightingType >(0))
Create a new LandmarkSighting.
enum LandmarkSightingType & sightingType()
void set_distance(const uint16_t &t_newValue)
LandmarkSighting(const struct wb_landmark_sighting &t_other)
Copy Constructor.
LandmarkSighting(const LandmarkSighting &t_other)
Copy Constructor.
bool operator!=(const LandmarkSighting &t_other) const
enum LandmarkSightingType & sightingType() const
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
int16_t direction
degrees, relative to the center of the nao torso.
uint16_t distance
CM distance to the center point of the sighting.
enum LandmarkSightingType sightingType
The type of sighting.
const char * wb_landmark_sighting_description(const struct wb_landmark_sighting *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_landmark_sighting_to_string(const struct wb_landmark_sighting *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_landmark_sighting * wb_landmark_sighting_from_string(struct wb_landmark_sighting *self, const char *str)
Convert from a string.
#define LANDMARK_SIGHTING_DESC_BUFFER_SIZE
#define LANDMARK_SIGHTING_TO_STRING_BUFFER_SIZE
LandmarkSightingType
@ GenericGoalPostSightingType
@ StraightLineSightingType
@ BallSightingType
@ CornerLineSightingType
@ LeftGoalPostSightingType
@ GoalLandmarkSightingType
@ TIntersectionLineSightingType
@ LineHorizonSightingType
@ CrossLineSightingType
@ CornerHorizonSightingType
@ RightGoalPostSightingType