gusimplewhiteboard
MachineFilteredLocalisationVision.hpp
Go to the documentation of this file.
1/*
2 * file MachineFilteredLocalisationVision.hpp
3 *
4 * This file was generated by classgenerator from machine_filtered_localisation_vision.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_MachineFilteredLocalisationVision_h
61#define guWhiteboard_MachineFilteredLocalisationVision_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_MachineFilteredLocalisationVision_DEFINED
73#define guWhiteboard_MachineFilteredLocalisationVision_DEFINED
74
75#undef MachineFilteredLocalisationVision_DEFINED
76#define MachineFilteredLocalisationVision_DEFINED
77
78#include "LandmarkSighting.h"
79
80namespace guWhiteboard {
81
86
87 private:
88
92 void init(uint8_t t_numberOfSightings = 0, const struct wb_landmark_sighting t_sightings[12] = NULLPTR) {
93 set_numberOfSightings(t_numberOfSightings);
94 if (t_sightings != NULLPTR) {
96 } else {
99 }
100 }
101
102 public:
103
107 MachineFilteredLocalisationVision(uint8_t t_numberOfSightings = 0, const struct wb_landmark_sighting t_sightings[12] = NULLPTR) {
108 this->init(t_numberOfSightings, t_sightings);
109 }
110
115 this->init(t_other.numberOfSightings(), t_other.sightings());
116 }
117
122 this->init(t_other.numberOfSightings, t_other.sightings);
123 }
124
129 this->init(t_other.numberOfSightings(), t_other.sightings());
130 return *this;
131 }
132
137 this->init(t_other.numberOfSightings, t_other.sightings);
138 return *this;
139 }
140
142 {
143 if (!(numberOfSightings() == t_other.numberOfSightings()))
144 {
145 return false;
146 }
147 for (int sightings_0_index = 0; sightings_0_index < 12; sightings_0_index++)
148 {
149 if (!(LandmarkSighting(sightings(sightings_0_index)) == LandmarkSighting(t_other.sightings(sightings_0_index)))) return false;
150 }
151 return true;
152 }
153
155 {
156 return !(*this == t_other);
157 }
158
160 {
161 return *this == MachineFilteredLocalisationVision(t_other);
162 }
163
165 {
166 return !(*this == t_other);
167 }
168
170 {
172 }
173
174 const uint8_t & numberOfSightings() const
175 {
177 }
178
179 void set_numberOfSightings(const uint8_t &t_newValue)
180 {
182 }
183
185 {
187 }
188
189 size_t sightings_size() const
190 {
192 }
193
195 {
196 return const_cast<LandmarkSighting &>(static_cast<const LandmarkSighting &>(wb_machine_filtered_localisation_vision::sightings[t_i]));
197 }
198
199 const LandmarkSighting & sightings(int t_i) const
200 {
202 }
203
204 void set_sightings(const LandmarkSighting *t_newValue)
205 {
207 }
208
209 void set_sightings(const LandmarkSighting &t_newValue, int t_i)
210 {
212 }
213
214#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
218 MachineFilteredLocalisationVision(const std::string &t_str) {
219 this->init();
220 this->from_string(t_str);
221 }
222
223 std::string description() {
224#ifdef USE_WB_MACHINE_FILTERED_LOCALISATION_VISION_C_CONVERSION
226 wb_machine_filtered_localisation_vision_description(this, buffer, sizeof(buffer));
227 std::string descr = buffer;
228 return descr;
229#else
230 std::ostringstream ss;
231 ss << "numberOfSightings=" << static_cast<unsigned>(this->numberOfSightings());
232 ss << ", ";
233 bool sightings_first = true;
234 ss << "sightings={";
236 ss << (sightings_first ? "" : ", ") << "{" << LandmarkSighting(this->sightings(i)).description() << "}";
237 sightings_first = false;
238 }
239 ss << "}";
240 return ss.str();
241#endif
242 }
243
244 std::string to_string() {
245#ifdef USE_WB_MACHINE_FILTERED_LOCALISATION_VISION_C_CONVERSION
247 wb_machine_filtered_localisation_vision_to_string(this, buffer, sizeof(buffer));
248 std::string toString = buffer;
249 return toString;
250#else
251 std::ostringstream ss;
252 ss << static_cast<unsigned>(this->numberOfSightings());
253 ss << ", ";
254 bool sightings_first = true;
255 ss << "{";
257 ss << (sightings_first ? "" : ", ") << "{" << LandmarkSighting(this->sightings(i)).to_string() << "}";
258 sightings_first = false;
259 }
260 ss << "}";
261 return ss.str();
262#endif
263 }
264
265#ifdef USE_WB_MACHINE_FILTERED_LOCALISATION_VISION_C_CONVERSION
266 void from_string(const std::string &t_str) {
268#else
269 void from_string(const std::string &t_str) {
270 char * str_cstr = const_cast<char *>(t_str.c_str());
271 size_t temp_length = strlen(str_cstr);
272 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
274 return;
275 }
277 char* var_str = &var_str_buffer[0];
278 char key_buffer[18];
279 char* key = &key_buffer[0];
280 int bracecount = 0;
281 int lastBrace = -1;
282 int startVar = 0;
283 int index = 0;
284 int startKey = 0;
285 int endKey = -1;
286 int varIndex = 0;
287 if (index == 0 && str_cstr[0] == '{') {
288 index = 1;
289 }
290 startVar = index;
291 startKey = startVar;
292 do {
293 for (int i = index; i < length; i++) {
294 index = i + 1;
295 if (bracecount == 0 && str_cstr[i] == '=') {
296 endKey = i - 1;
297 startVar = index;
298 continue;
299 }
300 if (bracecount == 0 && isspace(str_cstr[i])) {
301 startVar = index;
302 if (endKey == -1) {
303 startKey = index;
304 }
305 continue;
306 }
307 if (bracecount == 0 && str_cstr[i] == ',') {
308 index = i - 1;
309 break;
310 }
311 if (str_cstr[i] == '{') {
312 bracecount++;
313 if (bracecount == 1) {
314 lastBrace = i;
315 }
316 continue;
317 }
318 if (str_cstr[i] == '}') {
319 bracecount--;
320 if (bracecount < 0) {
321 index = i - 1;
322 break;
323 }
324 }
325 if (i == length - 1) {
326 index = i;
327 }
328 }
329 if (endKey >= startKey && endKey - startKey < length) {
330 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
331 key[(endKey - startKey) + 1] = 0;
332 } else {
333 key[0] = 0;
334 }
335 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
336 var_str[(index - startVar) + 1] = 0;
337 bracecount = 0;
338 index += 2;
339 startVar = index;
340 startKey = startVar;
341 endKey = -1;
342 if (strlen(key) > 0) {
343 if (0 == strcmp("numberOfSightings", key)) {
344 varIndex = 0;
345 } else if (0 == strcmp("sightings", key)) {
346 varIndex = 1;
347 } else {
348 varIndex = -1;
349 }
350 }
351 switch (varIndex) {
352 case -1: { break; }
353 case 0:
354 {
355 this->set_numberOfSightings(static_cast<uint8_t>(atoi(var_str)));
356 break;
357 }
358 case 1:
359 {
360 int restartIndex = index;
361 index = lastBrace + 1;
362 startVar = index;
363 startKey = startVar;
364 endKey = -1;
365 bracecount = 0;
366 for (int sightings_0_index = 0; sightings_0_index < MACHINE_FILTERED_LOCALISATION_VISION_SIGHTINGS_ARRAY_SIZE; sightings_0_index++) {
367 for (int i = index; i < length; i++) {
368 index = i + 1;
369 if (bracecount == 0 && str_cstr[i] == '=') {
370 endKey = i - 1;
371 startVar = index;
372 continue;
373 }
374 if (bracecount == 0 && isspace(str_cstr[i])) {
375 startVar = index;
376 if (endKey == -1) {
377 startKey = index;
378 }
379 continue;
380 }
381 if (bracecount == 0 && str_cstr[i] == ',') {
382 index = i - 1;
383 break;
384 }
385 if (str_cstr[i] == '{') {
386 bracecount++;
387 continue;
388 }
389 if (str_cstr[i] == '}') {
390 bracecount--;
391 if (bracecount < 0) {
392 index = i - 1;
393 break;
394 }
395 }
396 if (i == length - 1) {
397 index = i;
398 }
399 }
400 if (endKey >= startKey && endKey - startKey < length) {
401 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
402 key[(endKey - startKey) + 1] = 0;
403 } else {
404 key[0] = 0;
405 }
406 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
407 var_str[(index - startVar) + 1] = 0;
408 bracecount = 0;
409 index += 2;
410 startVar = index;
411 startKey = startVar;
412 endKey = -1;
413 LandmarkSighting sightings_0_temp = LandmarkSighting();
414 sightings_0_temp.from_string(var_str);
415 struct wb_landmark_sighting sightings_0 = sightings_0_temp;
416 this->set_sightings(sightings_0, sightings_0_index);
417 }
418 index = restartIndex;
419 break;
420 }
421 }
422 if (varIndex >= 0) {
423 varIndex++;
424 }
425 } while(index < length);
426#endif
427 }
428#endif
429
431 {
432 for (int i = 0; i < this->numberOfSightings(); i++) {
433 if (this->sightings(i).sightingType() == sightingType)
434 {
435 return i;
436 }
437 }
438 return -1;
439
440 }
441
442 int ball()
443 {
444 return this->firstSighting(BallSightingType);
445 }
446
448 {
450 }
451
453 {
455 }
456
459 }
460
461 int goal() {
463 }
464
466 {
468 }
469
471 {
473 }
474
476 {
477 return MAX(this->lineHorizon(), this->cornerHorizon());
478 }
479
480 int line()
481 {
483 }
484
486 {
488 }
489
490 int tLine()
491 {
493 }
494
496 {
498 }
499 };
500
501}
502
503#endif
Provides a C++ wrapper around wb_landmark_sighting.
void from_string(const std::string &t_str)
enum LandmarkSightingType & sightingType()
Provides a C++ wrapper around wb_machine_filtered_localisation_vision.
bool operator!=(const MachineFilteredLocalisationVision &t_other) const
MachineFilteredLocalisationVision(const std::string &t_str)
String Constructor.
MachineFilteredLocalisationVision(const struct wb_machine_filtered_localisation_vision &t_other)
Copy Constructor.
MachineFilteredLocalisationVision(const MachineFilteredLocalisationVision &t_other)
Copy Constructor.
int firstSighting(LandmarkSightingType sightingType)
WHITEBOARD_POSTER_STRING_CONVERSION.
bool operator==(const MachineFilteredLocalisationVision &t_other) const
MachineFilteredLocalisationVision & operator=(const MachineFilteredLocalisationVision &t_other)
Copy Assignment Operator.
void set_sightings(const LandmarkSighting &t_newValue, int t_i)
MachineFilteredLocalisationVision(uint8_t t_numberOfSightings=0, const struct wb_landmark_sighting t_sightings[12]=NULLPTR)
Create a new MachineFilteredLocalisationVision.
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
enum LandmarkSightingType sightingType
The type of sighting.
Results of the FSM (and sub machines) "SMFilterVision".
uint8_t numberOfSightings
The number of sightings in sightings.
struct wb_landmark_sighting sightings[12]
All sightings.
LandmarkSightingType
@ GenericGoalPostSightingType
@ StraightLineSightingType
@ BallSightingType
@ CornerLineSightingType
@ LeftGoalPostSightingType
@ GoalLandmarkSightingType
@ TIntersectionLineSightingType
@ LineHorizonSightingType
@ CrossLineSightingType
@ CornerHorizonSightingType
@ RightGoalPostSightingType
struct wb_machine_filtered_localisation_vision * wb_machine_filtered_localisation_vision_from_string(struct wb_machine_filtered_localisation_vision *self, const char *str)
Convert from a string.
const char * wb_machine_filtered_localisation_vision_to_string(const struct wb_machine_filtered_localisation_vision *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_machine_filtered_localisation_vision_description(const struct wb_machine_filtered_localisation_vision *self, char *descString, size_t bufferSize)
Convert to a description string.
#define MACHINE_FILTERED_LOCALISATION_VISION_DESC_BUFFER_SIZE
#define MACHINE_FILTERED_LOCALISATION_VISION_SIGHTINGS_ARRAY_SIZE
WHITEBOARD_POSTER_STRING_CONVERSION.
#define MACHINE_FILTERED_LOCALISATION_VISION_TO_STRING_BUFFER_SIZE