gusimplewhiteboard
VisionDetectionBall.hpp
Go to the documentation of this file.
1/*
2 * file VisionDetectionBall.hpp
3 *
4 * This file was generated by classgenerator from vision_detection_ball.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_VisionDetectionBall_h
61#define guWhiteboard_VisionDetectionBall_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_VisionDetectionBall_DEFINED
73#define guWhiteboard_VisionDetectionBall_DEFINED
74
75#undef VisionDetectionBall_DEFINED
76#define VisionDetectionBall_DEFINED
77
78#include "PixelCoordinate.h"
79
80#include <guunits/guunits.h>
81#include <gucoordinates/gucoordinates.h>
82
83namespace guWhiteboard {
84
89
90 private:
91
95 void init(enum BallOptions t_sightingType = NoBallDetected, struct wb_pixel_coordinate t_coordinate = wb_pixel_coordinate(), uint16_t t_verticalRadius = 0, uint16_t t_horizontalRadius = 0) {
96 set_sightingType(t_sightingType);
97 set_coordinate(t_coordinate);
98 set_verticalRadius(t_verticalRadius);
99 set_horizontalRadius(t_horizontalRadius);
100 }
101
102 public:
103
107 VisionDetectionBall(enum BallOptions t_sightingType = NoBallDetected, struct wb_pixel_coordinate t_coordinate = wb_pixel_coordinate(), uint16_t t_verticalRadius = 0, uint16_t t_horizontalRadius = 0) {
108 this->init(t_sightingType, t_coordinate, t_verticalRadius, t_horizontalRadius);
109 }
110
115 this->init(t_other.sightingType(), t_other.coordinate(), t_other.verticalRadius(), t_other.horizontalRadius());
116 }
117
122 this->init(t_other.sightingType, t_other.coordinate, t_other.verticalRadius, t_other.horizontalRadius);
123 }
124
129 this->init(t_other.sightingType(), t_other.coordinate(), t_other.verticalRadius(), t_other.horizontalRadius());
130 return *this;
131 }
132
137 this->init(t_other.sightingType, t_other.coordinate, t_other.verticalRadius, t_other.horizontalRadius);
138 return *this;
139 }
140
141 bool operator ==(const VisionDetectionBall &t_other) const
142 {
143 return sightingType() == t_other.sightingType()
145 && verticalRadius() == t_other.verticalRadius()
146 && horizontalRadius() == t_other.horizontalRadius();
147 }
148
149 bool operator !=(const VisionDetectionBall &t_other) const
150 {
151 return !(*this == t_other);
152 }
153
154 bool operator ==(const wb_vision_detection_ball &t_other) const
155 {
156 return *this == VisionDetectionBall(t_other);
157 }
158
159 bool operator !=(const wb_vision_detection_ball &t_other) const
160 {
161 return !(*this == t_other);
162 }
163
165 {
167 }
168
169 const enum BallOptions & sightingType() const
170 {
172 }
173
174 void set_sightingType(const enum BallOptions &t_newValue)
175 {
177 }
178
180 {
181 return const_cast<PixelCoordinate &>(static_cast<const PixelCoordinate &>(wb_vision_detection_ball::coordinate));
182 }
183
185 {
186 return static_cast<const PixelCoordinate &>(wb_vision_detection_ball::coordinate);
187 }
188
189 void set_coordinate(const PixelCoordinate &t_newValue)
190 {
192 }
193
194 uint16_t & verticalRadius()
195 {
197 }
198
199 const uint16_t & verticalRadius() const
200 {
202 }
203
204 void set_verticalRadius(const uint16_t &t_newValue)
205 {
207 }
208
209 uint16_t & horizontalRadius()
210 {
212 }
213
214 const uint16_t & horizontalRadius() const
215 {
217 }
218
219 void set_horizontalRadius(const uint16_t &t_newValue)
220 {
222 }
223
224#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
228 VisionDetectionBall(const std::string &t_str) {
229 this->init();
230 this->from_string(t_str);
231 }
232
233 std::string description() {
234#ifdef USE_WB_VISION_DETECTION_BALL_C_CONVERSION
236 wb_vision_detection_ball_description(this, buffer, sizeof(buffer));
237 std::string descr = buffer;
238 return descr;
239#else
240 std::ostringstream ss;
241 switch (this->sightingType()) {
242 case BallDetected:
243 {
244 ss << "sightingType=" << "BallDetected";
245 break;
246 }
247 case NoBallDetected:
248 {
249 ss << "sightingType=" << "NoBallDetected";
250 break;
251 }
252 }
253 ss << ", ";
254 ss << "coordinate=" << "{" << PixelCoordinate(this->coordinate()).description() << "}";
255 ss << ", ";
256 ss << "verticalRadius=" << static_cast<unsigned>(this->verticalRadius());
257 ss << ", ";
258 ss << "horizontalRadius=" << static_cast<unsigned>(this->horizontalRadius());
259 return ss.str();
260#endif
261 }
262
263 std::string to_string() {
264#ifdef USE_WB_VISION_DETECTION_BALL_C_CONVERSION
266 wb_vision_detection_ball_to_string(this, buffer, sizeof(buffer));
267 std::string toString = buffer;
268 return toString;
269#else
270 std::ostringstream ss;
271 switch (this->sightingType()) {
272 case BallDetected:
273 {
274 ss << "BallDetected";
275 break;
276 }
277 case NoBallDetected:
278 {
279 ss << "NoBallDetected";
280 break;
281 }
282 }
283 ss << ", ";
284 ss << "{" << PixelCoordinate(this->coordinate()).to_string() << "}";
285 ss << ", ";
286 ss << static_cast<unsigned>(this->verticalRadius());
287 ss << ", ";
288 ss << static_cast<unsigned>(this->horizontalRadius());
289 return ss.str();
290#endif
291 }
292
293#ifdef USE_WB_VISION_DETECTION_BALL_C_CONVERSION
294 void from_string(const std::string &t_str) {
295 wb_vision_detection_ball_from_string(this, t_str.c_str());
296#else
297 void from_string(const std::string &t_str) {
298 char * str_cstr = const_cast<char *>(t_str.c_str());
299 size_t temp_length = strlen(str_cstr);
300 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
301 if (length < 1 || length > VISION_DETECTION_BALL_DESC_BUFFER_SIZE) {
302 return;
303 }
304 char var_str_buffer[VISION_DETECTION_BALL_DESC_BUFFER_SIZE + 1];
305 char* var_str = &var_str_buffer[0];
306 char key_buffer[17];
307 char* key = &key_buffer[0];
308 int bracecount = 0;
309 int startVar = 0;
310 int index = 0;
311 int startKey = 0;
312 int endKey = -1;
313 int varIndex = 0;
314 if (index == 0 && str_cstr[0] == '{') {
315 index = 1;
316 }
317 startVar = index;
318 startKey = startVar;
319 do {
320 for (int i = index; i < length; i++) {
321 index = i + 1;
322 if (bracecount == 0 && str_cstr[i] == '=') {
323 endKey = i - 1;
324 startVar = index;
325 continue;
326 }
327 if (bracecount == 0 && isspace(str_cstr[i])) {
328 startVar = index;
329 if (endKey == -1) {
330 startKey = index;
331 }
332 continue;
333 }
334 if (bracecount == 0 && str_cstr[i] == ',') {
335 index = i - 1;
336 break;
337 }
338 if (str_cstr[i] == '{') {
339 bracecount++;
340 continue;
341 }
342 if (str_cstr[i] == '}') {
343 bracecount--;
344 if (bracecount < 0) {
345 index = i - 1;
346 break;
347 }
348 }
349 if (i == length - 1) {
350 index = i;
351 }
352 }
353 if (endKey >= startKey && endKey - startKey < length) {
354 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
355 key[(endKey - startKey) + 1] = 0;
356 } else {
357 key[0] = 0;
358 }
359 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
360 var_str[(index - startVar) + 1] = 0;
361 bracecount = 0;
362 index += 2;
363 startVar = index;
364 startKey = startVar;
365 endKey = -1;
366 if (strlen(key) > 0) {
367 if (0 == strcmp("sightingType", key)) {
368 varIndex = 0;
369 } else if (0 == strcmp("coordinate", key)) {
370 varIndex = 1;
371 } else if (0 == strcmp("verticalRadius", key)) {
372 varIndex = 2;
373 } else if (0 == strcmp("horizontalRadius", key)) {
374 varIndex = 3;
375 } else {
376 varIndex = -1;
377 }
378 }
379 switch (varIndex) {
380 case -1: { break; }
381 case 0:
382 {
383 if (strcmp("BallDetected", var_str) == 0) {
384#pragma clang diagnostic push
385#pragma clang diagnostic ignored "-Wbad-function-cast"
387#pragma clang diagnostic pop
388 } else if (strcmp("NoBallDetected", var_str) == 0) {
389#pragma clang diagnostic push
390#pragma clang diagnostic ignored "-Wbad-function-cast"
392#pragma clang diagnostic pop
393 } else {
394#pragma clang diagnostic push
395#pragma clang diagnostic ignored "-Wbad-function-cast"
396 this->set_sightingType(static_cast<enum BallOptions>(atoi(var_str)));
397#pragma clang diagnostic pop
398 }
399 break;
400 }
401 case 1:
402 {
403 PixelCoordinate coordinate_temp = PixelCoordinate();
404 coordinate_temp.from_string(var_str);
405 this->set_coordinate(coordinate_temp);
406 break;
407 }
408 case 2:
409 {
410 this->set_verticalRadius(static_cast<uint16_t>(atoi(var_str)));
411 break;
412 }
413 case 3:
414 {
415 this->set_horizontalRadius(static_cast<uint16_t>(atoi(var_str)));
416 break;
417 }
418 }
419 if (varIndex >= 0) {
420 varIndex++;
421 }
422 } while(index < length);
423#endif
424 }
425#endif
426
427 GU::PixelCoordinate coordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
428 {
429 return PixelCoordinate(coordinate()).pixelCoordinate(resWidth, resHeight);
430 }
431 };
432
433}
434
435#endif
Provides a C++ wrapper around wb_pixel_coordinate.
void from_string(const std::string &t_str)
GU::PixelCoordinate pixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
Provides a C++ wrapper around wb_vision_detection_ball.
const uint16_t & verticalRadius() const
void set_coordinate(const PixelCoordinate &t_newValue)
GU::PixelCoordinate coordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
WHITEBOARD_POSTER_STRING_CONVERSION.
VisionDetectionBall(const VisionDetectionBall &t_other)
Copy Constructor.
void set_verticalRadius(const uint16_t &t_newValue)
const uint16_t & horizontalRadius() const
void from_string(const std::string &t_str)
void set_sightingType(const enum BallOptions &t_newValue)
VisionDetectionBall(enum BallOptions t_sightingType=NoBallDetected, struct wb_pixel_coordinate t_coordinate=wb_pixel_coordinate(), uint16_t t_verticalRadius=0, uint16_t t_horizontalRadius=0)
Create a new VisionDetectionBall.
bool operator==(const VisionDetectionBall &t_other) const
const PixelCoordinate & coordinate() const
VisionDetectionBall(const struct wb_vision_detection_ball &t_other)
Copy Constructor.
void set_horizontalRadius(const uint16_t &t_newValue)
VisionDetectionBall(const std::string &t_str)
String Constructor.
VisionDetectionBall & operator=(const VisionDetectionBall &t_other)
Copy Assignment Operator.
bool operator!=(const VisionDetectionBall &t_other) const
enum BallOptions & sightingType() const
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
WHITEBOARD_POSTER_STRING_CONVERSION.
struct wb_pixel_coordinate coordinate
The pixel coordinate.
uint16_t verticalRadius
The vertical radius in pixels.
enum BallOptions sightingType
Ball detection details.
uint16_t horizontalRadius
The horizontal radius in pixels.
struct wb_vision_detection_ball * wb_vision_detection_ball_from_string(struct wb_vision_detection_ball *self, const char *str)
Convert from a string.
const char * wb_vision_detection_ball_to_string(const struct wb_vision_detection_ball *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_vision_detection_ball_description(const struct wb_vision_detection_ball *self, char *descString, size_t bufferSize)
Convert to a description string.
@ BallDetected
Ball Found.
@ NoBallDetected
No Ball Found.
#define VISION_DETECTION_BALL_DESC_BUFFER_SIZE
#define VISION_DETECTION_BALL_TO_STRING_BUFFER_SIZE