gusimplewhiteboard
VisionDetectionLines.hpp
Go to the documentation of this file.
1/*
2 * file VisionDetectionLines.hpp
3 *
4 * This file was generated by classgenerator from vision_detection_lines.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_VisionDetectionLines_h
61#define guWhiteboard_VisionDetectionLines_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_VisionDetectionLines_DEFINED
73#define guWhiteboard_VisionDetectionLines_DEFINED
74
75#undef VisionDetectionLines_DEFINED
76#define VisionDetectionLines_DEFINED
77
79
80namespace guWhiteboard {
81
86
87 private:
88
92 void init(uint64_t t_frameNumber = 0, const struct wb_vision_detection_line_array t_lines[2] = NULLPTR, uint16_t t_res_width = 0, uint16_t t_res_height = 0) {
93 set_frameNumber(t_frameNumber);
94 if (t_lines != NULLPTR) {
96 } else {
99 }
100 set_res_width(t_res_width);
101 set_res_height(t_res_height);
102 }
103
104 public:
105
109 VisionDetectionLines(uint64_t t_frameNumber = 0, const struct wb_vision_detection_line_array t_lines[2] = NULLPTR, uint16_t t_res_width = 0, uint16_t t_res_height = 0) {
110 this->init(t_frameNumber, t_lines, t_res_width, t_res_height);
111 }
112
117 this->init(t_other.frameNumber(), t_other.lines(), t_other.res_width(), t_other.res_height());
118 }
119
124 this->init(t_other.frameNumber, t_other.lines, t_other.res_width, t_other.res_height);
125 }
126
131 this->init(t_other.frameNumber(), t_other.lines(), t_other.res_width(), t_other.res_height());
132 return *this;
133 }
134
139 this->init(t_other.frameNumber, t_other.lines, t_other.res_width, t_other.res_height);
140 return *this;
141 }
142
143 bool operator ==(const VisionDetectionLines &t_other) const
144 {
145 if (!(frameNumber() == t_other.frameNumber()
146 && res_width() == t_other.res_width()
147 && res_height() == t_other.res_height()))
148 {
149 return false;
150 }
151 for (int lines_0_index = 0; lines_0_index < 2; lines_0_index++)
152 {
153 if (!(VisionDetectionLineArray(lines(lines_0_index)) == VisionDetectionLineArray(t_other.lines(lines_0_index)))) return false;
154 }
155 return true;
156 }
157
158 bool operator !=(const VisionDetectionLines &t_other) const
159 {
160 return !(*this == t_other);
161 }
162
163 bool operator ==(const wb_vision_detection_lines &t_other) const
164 {
165 return *this == VisionDetectionLines(t_other);
166 }
167
168 bool operator !=(const wb_vision_detection_lines &t_other) const
169 {
170 return !(*this == t_other);
171 }
172
173 uint64_t & frameNumber()
174 {
176 }
177
178 const uint64_t & frameNumber() const
179 {
181 }
182
183 void set_frameNumber(const uint64_t &t_newValue)
184 {
186 }
187
189 {
190 return static_cast<const VisionDetectionLineArray *>(&(wb_vision_detection_lines::lines[0]));
191 }
192
193 size_t lines_size() const
194 {
196 }
197
199 {
200 return const_cast<VisionDetectionLineArray &>(static_cast<const VisionDetectionLineArray &>(wb_vision_detection_lines::lines[t_i]));
201 }
202
203 const VisionDetectionLineArray & lines(int t_i) const
204 {
205 return static_cast<const VisionDetectionLineArray &>(wb_vision_detection_lines::lines[t_i]);
206 }
207
208 void set_lines(const VisionDetectionLineArray *t_newValue)
209 {
211 }
212
213 void set_lines(const VisionDetectionLineArray &t_newValue, int t_i)
214 {
216 }
217
218 uint16_t & res_width()
219 {
221 }
222
223 const uint16_t & res_width() const
224 {
226 }
227
228 void set_res_width(const uint16_t &t_newValue)
229 {
231 }
232
233 uint16_t & res_height()
234 {
236 }
237
238 const uint16_t & res_height() const
239 {
241 }
242
243 void set_res_height(const uint16_t &t_newValue)
244 {
246 }
247
248#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
252 VisionDetectionLines(const std::string &t_str) {
253 this->init();
254 this->from_string(t_str);
255 }
256
257 std::string description() {
258#ifdef USE_WB_VISION_DETECTION_LINES_C_CONVERSION
260 wb_vision_detection_lines_description(this, buffer, sizeof(buffer));
261 std::string descr = buffer;
262 return descr;
263#else
264 std::ostringstream ss;
265 ss << "frameNumber=" << this->frameNumber();
266 ss << ", ";
267 bool lines_first = true;
268 ss << "lines={";
269 for (int i = 0; i < VISION_DETECTION_LINES_LINES_ARRAY_SIZE; i++) {
270 ss << (lines_first ? "" : ", ") << "{" << VisionDetectionLineArray(this->lines(i)).description() << "}";
271 lines_first = false;
272 }
273 ss << "}";
274 ss << ", ";
275 ss << "res_width=" << static_cast<unsigned>(this->res_width());
276 ss << ", ";
277 ss << "res_height=" << static_cast<unsigned>(this->res_height());
278 return ss.str();
279#endif
280 }
281
282 std::string to_string() {
283#ifdef USE_WB_VISION_DETECTION_LINES_C_CONVERSION
285 wb_vision_detection_lines_to_string(this, buffer, sizeof(buffer));
286 std::string toString = buffer;
287 return toString;
288#else
289 std::ostringstream ss;
290 ss << this->frameNumber();
291 ss << ", ";
292 bool lines_first = true;
293 ss << "{";
294 for (int i = 0; i < VISION_DETECTION_LINES_LINES_ARRAY_SIZE; i++) {
295 ss << (lines_first ? "" : ", ") << "{" << VisionDetectionLineArray(this->lines(i)).to_string() << "}";
296 lines_first = false;
297 }
298 ss << "}";
299 ss << ", ";
300 ss << static_cast<unsigned>(this->res_width());
301 ss << ", ";
302 ss << static_cast<unsigned>(this->res_height());
303 return ss.str();
304#endif
305 }
306
307#ifdef USE_WB_VISION_DETECTION_LINES_C_CONVERSION
308 void from_string(const std::string &t_str) {
309 wb_vision_detection_lines_from_string(this, t_str.c_str());
310#else
311 void from_string(const std::string &t_str) {
312 char * str_cstr = const_cast<char *>(t_str.c_str());
313 size_t temp_length = strlen(str_cstr);
314 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
315 if (length < 1 || length > VISION_DETECTION_LINES_DESC_BUFFER_SIZE) {
316 return;
317 }
318 char var_str_buffer[VISION_DETECTION_LINES_DESC_BUFFER_SIZE + 1];
319 char* var_str = &var_str_buffer[0];
320 char key_buffer[12];
321 char* key = &key_buffer[0];
322 int bracecount = 0;
323 int lastBrace = -1;
324 int startVar = 0;
325 int index = 0;
326 int startKey = 0;
327 int endKey = -1;
328 int varIndex = 0;
329 if (index == 0 && str_cstr[0] == '{') {
330 index = 1;
331 }
332 startVar = index;
333 startKey = startVar;
334 do {
335 for (int i = index; i < length; i++) {
336 index = i + 1;
337 if (bracecount == 0 && str_cstr[i] == '=') {
338 endKey = i - 1;
339 startVar = index;
340 continue;
341 }
342 if (bracecount == 0 && isspace(str_cstr[i])) {
343 startVar = index;
344 if (endKey == -1) {
345 startKey = index;
346 }
347 continue;
348 }
349 if (bracecount == 0 && str_cstr[i] == ',') {
350 index = i - 1;
351 break;
352 }
353 if (str_cstr[i] == '{') {
354 bracecount++;
355 if (bracecount == 1) {
356 lastBrace = i;
357 }
358 continue;
359 }
360 if (str_cstr[i] == '}') {
361 bracecount--;
362 if (bracecount < 0) {
363 index = i - 1;
364 break;
365 }
366 }
367 if (i == length - 1) {
368 index = i;
369 }
370 }
371 if (endKey >= startKey && endKey - startKey < length) {
372 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
373 key[(endKey - startKey) + 1] = 0;
374 } else {
375 key[0] = 0;
376 }
377 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
378 var_str[(index - startVar) + 1] = 0;
379 bracecount = 0;
380 index += 2;
381 startVar = index;
382 startKey = startVar;
383 endKey = -1;
384 if (strlen(key) > 0) {
385 if (0 == strcmp("frameNumber", key)) {
386 varIndex = 0;
387 } else if (0 == strcmp("lines", key)) {
388 varIndex = 1;
389 } else if (0 == strcmp("res_width", key)) {
390 varIndex = 2;
391 } else if (0 == strcmp("res_height", key)) {
392 varIndex = 3;
393 } else {
394 varIndex = -1;
395 }
396 }
397 switch (varIndex) {
398 case -1: { break; }
399 case 0:
400 {
401#ifdef __APPLE__
402 this->set_frameNumber(static_cast<uint64_t>(atoll(var_str)));
403#else
404 this->set_frameNumber(static_cast<uint64_t>(atol(var_str)));
405#endif
406 break;
407 }
408 case 1:
409 {
410 int restartIndex = index;
411 index = lastBrace + 1;
412 startVar = index;
413 startKey = startVar;
414 endKey = -1;
415 bracecount = 0;
416 for (int lines_0_index = 0; lines_0_index < VISION_DETECTION_LINES_LINES_ARRAY_SIZE; lines_0_index++) {
417 for (int i = index; i < length; i++) {
418 index = i + 1;
419 if (bracecount == 0 && str_cstr[i] == '=') {
420 endKey = i - 1;
421 startVar = index;
422 continue;
423 }
424 if (bracecount == 0 && isspace(str_cstr[i])) {
425 startVar = index;
426 if (endKey == -1) {
427 startKey = index;
428 }
429 continue;
430 }
431 if (bracecount == 0 && str_cstr[i] == ',') {
432 index = i - 1;
433 break;
434 }
435 if (str_cstr[i] == '{') {
436 bracecount++;
437 continue;
438 }
439 if (str_cstr[i] == '}') {
440 bracecount--;
441 if (bracecount < 0) {
442 index = i - 1;
443 break;
444 }
445 }
446 if (i == length - 1) {
447 index = i;
448 }
449 }
450 if (endKey >= startKey && endKey - startKey < length) {
451 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
452 key[(endKey - startKey) + 1] = 0;
453 } else {
454 key[0] = 0;
455 }
456 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
457 var_str[(index - startVar) + 1] = 0;
458 bracecount = 0;
459 index += 2;
460 startVar = index;
461 startKey = startVar;
462 endKey = -1;
464 lines_0_temp.from_string(var_str);
465 struct wb_vision_detection_line_array lines_0 = lines_0_temp;
466 this->set_lines(lines_0, lines_0_index);
467 }
468 index = restartIndex;
469 break;
470 }
471 case 2:
472 {
473 this->set_res_width(static_cast<uint16_t>(atoi(var_str)));
474 break;
475 }
476 case 3:
477 {
478 this->set_res_height(static_cast<uint16_t>(atoi(var_str)));
479 break;
480 }
481 }
482 if (varIndex >= 0) {
483 varIndex++;
484 }
485 } while(index < length);
486#endif
487 }
488#endif
489 };
490
491}
492
493#endif
Provides a C++ wrapper around wb_vision_detection_line_array.
Provides a C++ wrapper around wb_vision_detection_lines.
VisionDetectionLineArray & lines(int t_i)
void set_lines(const VisionDetectionLineArray *t_newValue)
VisionDetectionLines(const std::string &t_str)
String Constructor.
void set_res_width(const uint16_t &t_newValue)
VisionDetectionLines(const struct wb_vision_detection_lines &t_other)
Copy Constructor.
void set_res_height(const uint16_t &t_newValue)
void from_string(const std::string &t_str)
VisionDetectionLines(uint64_t t_frameNumber=0, const struct wb_vision_detection_line_array t_lines[2]=NULLPTR, uint16_t t_res_width=0, uint16_t t_res_height=0)
Create a new VisionDetectionLines.
bool operator==(const VisionDetectionLines &t_other) const
VisionDetectionLines & operator=(const VisionDetectionLines &t_other)
Copy Assignment Operator.
VisionDetectionLines(const VisionDetectionLines &t_other)
Copy Constructor.
const VisionDetectionLineArray & lines(int t_i) const
bool operator!=(const VisionDetectionLines &t_other) const
void set_frameNumber(const uint64_t &t_newValue)
const VisionDetectionLineArray * lines() const
void set_lines(const VisionDetectionLineArray &t_newValue, int t_i)
/file APM_Interface.h
Results for the Line Ray Tracer (guvision).
Results for the Line Ray Tracer (guvision).
uint16_t res_width
The resolution width.
uint16_t res_height
The resolution height.
struct wb_vision_detection_line_array lines[2]
Lines reported for each camera.
uint64_t frameNumber
The frame number that these lines were seen in.
const char * wb_vision_detection_lines_to_string(const struct wb_vision_detection_lines *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_vision_detection_lines * wb_vision_detection_lines_from_string(struct wb_vision_detection_lines *self, const char *str)
Convert from a string.
const char * wb_vision_detection_lines_description(const struct wb_vision_detection_lines *self, char *descString, size_t bufferSize)
Convert to a description string.
#define VISION_DETECTION_LINES_DESC_BUFFER_SIZE
#define VISION_DETECTION_LINES_TO_STRING_BUFFER_SIZE
#define VISION_DETECTION_LINES_LINES_ARRAY_SIZE
WHITEBOARD_POSTER_STRING_CONVERSION.