gusimplewhiteboard
VisionLines.hpp
Go to the documentation of this file.
1/*
2 * file VisionLines.hpp
3 *
4 * This file was generated by classgenerator from vision_lines.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Eugene Gilmore. 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 Eugene Gilmore.
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_VisionLines_h
61#define guWhiteboard_VisionLines_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>
70#include "wb_vision_lines.h"
71
72#undef guWhiteboard_VisionLines_DEFINED
73#define guWhiteboard_VisionLines_DEFINED
74
75#undef VisionLines_DEFINED
76#define VisionLines_DEFINED
77
78#include "VisionLine.h"
79
80namespace guWhiteboard {
81
86
87 private:
88
92 void init(const struct wb_vision_line t_lines[7] = NULLPTR, uint8_t t_numLines = 0, uint64_t t_frameNumber = 0, uint16_t t_res_width = 0, uint16_t t_res_height = 0) {
93 if (t_lines != NULLPTR) {
94 std::memcpy(wb_vision_lines::lines, t_lines, VISION_LINES_LINES_ARRAY_SIZE * sizeof (struct wb_vision_line));
95 } else {
97 std::memcpy(wb_vision_lines::lines, lines_temp, VISION_LINES_LINES_ARRAY_SIZE * sizeof (struct wb_vision_line));
98 }
99 set_numLines(t_numLines);
100 set_frameNumber(t_frameNumber);
101 set_res_width(t_res_width);
102 set_res_height(t_res_height);
103 }
104
105 public:
106
110 VisionLines(const struct wb_vision_line t_lines[7] = NULLPTR, uint8_t t_numLines = 0, uint64_t t_frameNumber = 0, uint16_t t_res_width = 0, uint16_t t_res_height = 0) {
111 this->init(t_lines, t_numLines, t_frameNumber, t_res_width, t_res_height);
112 }
113
118 this->init(t_other.lines(), t_other.numLines(), t_other.frameNumber(), t_other.res_width(), t_other.res_height());
119 }
120
124 VisionLines(const struct wb_vision_lines &t_other): wb_vision_lines() {
125 this->init(t_other.lines, t_other.numLines, t_other.frameNumber, t_other.res_width, t_other.res_height);
126 }
127
132 this->init(t_other.lines(), t_other.numLines(), t_other.frameNumber(), t_other.res_width(), t_other.res_height());
133 return *this;
134 }
135
139 VisionLines &operator = (const struct wb_vision_lines &t_other) {
140 this->init(t_other.lines, t_other.numLines, t_other.frameNumber, t_other.res_width, t_other.res_height);
141 return *this;
142 }
143
144 bool operator ==(const VisionLines &t_other) const
145 {
146 if (!(numLines() == t_other.numLines()
147 && frameNumber() == t_other.frameNumber()
148 && res_width() == t_other.res_width()
149 && res_height() == t_other.res_height()))
150 {
151 return false;
152 }
153 for (int lines_0_index = 0; lines_0_index < 7; lines_0_index++)
154 {
155 if (!(VisionLine(lines(lines_0_index)) == VisionLine(t_other.lines(lines_0_index)))) return false;
156 }
157 return true;
158 }
159
160 bool operator !=(const VisionLines &t_other) const
161 {
162 return !(*this == t_other);
163 }
164
165 bool operator ==(const wb_vision_lines &t_other) const
166 {
167 return *this == VisionLines(t_other);
168 }
169
170 bool operator !=(const wb_vision_lines &t_other) const
171 {
172 return !(*this == t_other);
173 }
174
175 const VisionLine * lines() const
176 {
177 return static_cast<const VisionLine *>(&(wb_vision_lines::lines[0]));
178 }
179
180 size_t lines_size() const
181 {
183 }
184
185 VisionLine & lines(int t_i)
186 {
187 return const_cast<VisionLine &>(static_cast<const VisionLine &>(wb_vision_lines::lines[t_i]));
188 }
189
190 const VisionLine & lines(int t_i) const
191 {
192 return static_cast<const VisionLine &>(wb_vision_lines::lines[t_i]);
193 }
194
195 void set_lines(const VisionLine *t_newValue)
196 {
197 memcpy(wb_vision_lines::lines, static_cast<const struct wb_vision_line *>(t_newValue), VISION_LINES_LINES_ARRAY_SIZE * (sizeof (struct wb_vision_line)));
198 }
199
200 void set_lines(const VisionLine &t_newValue, int t_i)
201 {
202 wb_vision_lines::lines[t_i] = static_cast<wb_vision_line>(t_newValue);
203 }
204
205 uint8_t & numLines()
206 {
208 }
209
210 const uint8_t & numLines() const
211 {
213 }
214
215 void set_numLines(const uint8_t &t_newValue)
216 {
217 wb_vision_lines::numLines = t_newValue;
218 }
219
220 uint64_t & frameNumber()
221 {
223 }
224
225 const uint64_t & frameNumber() const
226 {
228 }
229
230 void set_frameNumber(const uint64_t &t_newValue)
231 {
232 wb_vision_lines::frameNumber = t_newValue;
233 }
234
235 uint16_t & res_width()
236 {
238 }
239
240 const uint16_t & res_width() const
241 {
243 }
244
245 void set_res_width(const uint16_t &t_newValue)
246 {
247 wb_vision_lines::res_width = t_newValue;
248 }
249
250 uint16_t & res_height()
251 {
253 }
254
255 const uint16_t & res_height() const
256 {
258 }
259
260 void set_res_height(const uint16_t &t_newValue)
261 {
262 wb_vision_lines::res_height = t_newValue;
263 }
264
265#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
269 VisionLines(const std::string &t_str) {
270 this->init();
271 this->from_string(t_str);
272 }
273
274 std::string description() {
275#ifdef USE_WB_VISION_LINES_C_CONVERSION
277 wb_vision_lines_description(this, buffer, sizeof(buffer));
278 std::string descr = buffer;
279 return descr;
280#else
281 std::ostringstream ss;
282 bool lines_first = true;
283 ss << "lines={";
284 for (int i = 0; i < VISION_LINES_LINES_ARRAY_SIZE; i++) {
285 ss << (lines_first ? "" : ", ") << "{" << VisionLine(this->lines(i)).description() << "}";
286 lines_first = false;
287 }
288 ss << "}";
289 ss << ", ";
290 ss << "numLines=" << static_cast<unsigned>(this->numLines());
291 ss << ", ";
292 ss << "frameNumber=" << this->frameNumber();
293 ss << ", ";
294 ss << "res_width=" << static_cast<unsigned>(this->res_width());
295 ss << ", ";
296 ss << "res_height=" << static_cast<unsigned>(this->res_height());
297 return ss.str();
298#endif
299 }
300
301 std::string to_string() {
302#ifdef USE_WB_VISION_LINES_C_CONVERSION
304 wb_vision_lines_to_string(this, buffer, sizeof(buffer));
305 std::string toString = buffer;
306 return toString;
307#else
308 std::ostringstream ss;
309 bool lines_first = true;
310 ss << "{";
311 for (int i = 0; i < VISION_LINES_LINES_ARRAY_SIZE; i++) {
312 ss << (lines_first ? "" : ", ") << "{" << VisionLine(this->lines(i)).to_string() << "}";
313 lines_first = false;
314 }
315 ss << "}";
316 ss << ", ";
317 ss << static_cast<unsigned>(this->numLines());
318 ss << ", ";
319 ss << this->frameNumber();
320 ss << ", ";
321 ss << static_cast<unsigned>(this->res_width());
322 ss << ", ";
323 ss << static_cast<unsigned>(this->res_height());
324 return ss.str();
325#endif
326 }
327
328#ifdef USE_WB_VISION_LINES_C_CONVERSION
329 void from_string(const std::string &t_str) {
330 wb_vision_lines_from_string(this, t_str.c_str());
331#else
332 void from_string(const std::string &t_str) {
333 char * str_cstr = const_cast<char *>(t_str.c_str());
334 size_t temp_length = strlen(str_cstr);
335 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
336 if (length < 1 || length > VISION_LINES_DESC_BUFFER_SIZE) {
337 return;
338 }
339 char var_str_buffer[VISION_LINES_DESC_BUFFER_SIZE + 1];
340 char* var_str = &var_str_buffer[0];
341 char key_buffer[12];
342 char* key = &key_buffer[0];
343 int bracecount = 0;
344 int lastBrace = -1;
345 int startVar = 0;
346 int index = 0;
347 int startKey = 0;
348 int endKey = -1;
349 int varIndex = 0;
350 if (index == 0 && str_cstr[0] == '{') {
351 index = 1;
352 }
353 startVar = index;
354 startKey = startVar;
355 do {
356 for (int i = index; i < length; i++) {
357 index = i + 1;
358 if (bracecount == 0 && str_cstr[i] == '=') {
359 endKey = i - 1;
360 startVar = index;
361 continue;
362 }
363 if (bracecount == 0 && isspace(str_cstr[i])) {
364 startVar = index;
365 if (endKey == -1) {
366 startKey = index;
367 }
368 continue;
369 }
370 if (bracecount == 0 && str_cstr[i] == ',') {
371 index = i - 1;
372 break;
373 }
374 if (str_cstr[i] == '{') {
375 bracecount++;
376 if (bracecount == 1) {
377 lastBrace = i;
378 }
379 continue;
380 }
381 if (str_cstr[i] == '}') {
382 bracecount--;
383 if (bracecount < 0) {
384 index = i - 1;
385 break;
386 }
387 }
388 if (i == length - 1) {
389 index = i;
390 }
391 }
392 if (endKey >= startKey && endKey - startKey < length) {
393 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
394 key[(endKey - startKey) + 1] = 0;
395 } else {
396 key[0] = 0;
397 }
398 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
399 var_str[(index - startVar) + 1] = 0;
400 bracecount = 0;
401 index += 2;
402 startVar = index;
403 startKey = startVar;
404 endKey = -1;
405 if (strlen(key) > 0) {
406 if (0 == strcmp("lines", key)) {
407 varIndex = 0;
408 } else if (0 == strcmp("numLines", key)) {
409 varIndex = 1;
410 } else if (0 == strcmp("frameNumber", key)) {
411 varIndex = 2;
412 } else if (0 == strcmp("res_width", key)) {
413 varIndex = 3;
414 } else if (0 == strcmp("res_height", key)) {
415 varIndex = 4;
416 } else {
417 varIndex = -1;
418 }
419 }
420 switch (varIndex) {
421 case -1: { break; }
422 case 0:
423 {
424 int restartIndex = index;
425 index = lastBrace + 1;
426 startVar = index;
427 startKey = startVar;
428 endKey = -1;
429 bracecount = 0;
430 for (int lines_0_index = 0; lines_0_index < VISION_LINES_LINES_ARRAY_SIZE; lines_0_index++) {
431 for (int i = index; i < length; i++) {
432 index = i + 1;
433 if (bracecount == 0 && str_cstr[i] == '=') {
434 endKey = i - 1;
435 startVar = index;
436 continue;
437 }
438 if (bracecount == 0 && isspace(str_cstr[i])) {
439 startVar = index;
440 if (endKey == -1) {
441 startKey = index;
442 }
443 continue;
444 }
445 if (bracecount == 0 && str_cstr[i] == ',') {
446 index = i - 1;
447 break;
448 }
449 if (str_cstr[i] == '{') {
450 bracecount++;
451 continue;
452 }
453 if (str_cstr[i] == '}') {
454 bracecount--;
455 if (bracecount < 0) {
456 index = i - 1;
457 break;
458 }
459 }
460 if (i == length - 1) {
461 index = i;
462 }
463 }
464 if (endKey >= startKey && endKey - startKey < length) {
465 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
466 key[(endKey - startKey) + 1] = 0;
467 } else {
468 key[0] = 0;
469 }
470 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
471 var_str[(index - startVar) + 1] = 0;
472 bracecount = 0;
473 index += 2;
474 startVar = index;
475 startKey = startVar;
476 endKey = -1;
477 VisionLine lines_0_temp = VisionLine();
478 lines_0_temp.from_string(var_str);
479 struct wb_vision_line lines_0 = lines_0_temp;
480 this->set_lines(lines_0, lines_0_index);
481 }
482 index = restartIndex;
483 break;
484 }
485 case 1:
486 {
487 this->set_numLines(static_cast<uint8_t>(atoi(var_str)));
488 break;
489 }
490 case 2:
491 {
492#ifdef __APPLE__
493 this->set_frameNumber(static_cast<uint64_t>(atoll(var_str)));
494#else
495 this->set_frameNumber(static_cast<uint64_t>(atol(var_str)));
496#endif
497 break;
498 }
499 case 3:
500 {
501 this->set_res_width(static_cast<uint16_t>(atoi(var_str)));
502 break;
503 }
504 case 4:
505 {
506 this->set_res_height(static_cast<uint16_t>(atoi(var_str)));
507 break;
508 }
509 }
510 if (varIndex >= 0) {
511 varIndex++;
512 }
513 } while(index < length);
514#endif
515 }
516#endif
517 };
518
519}
520
521#endif
Provides a C++ wrapper around wb_vision_line.
Definition: VisionLine.hpp:85
void from_string(const std::string &t_str)
Definition: VisionLine.hpp:230
Provides a C++ wrapper around wb_vision_lines.
Definition: VisionLines.hpp:85
void set_lines(const VisionLine *t_newValue)
const uint16_t & res_height() const
const uint16_t & res_width() const
void set_frameNumber(const uint64_t &t_newValue)
const VisionLine & lines(int t_i) const
const uint64_t & frameNumber() const
VisionLines(const struct wb_vision_lines &t_other)
Copy Constructor.
void set_res_height(const uint16_t &t_newValue)
bool operator!=(const VisionLines &t_other) const
VisionLine & lines(int t_i)
void set_numLines(const uint8_t &t_newValue)
const VisionLine * lines() const
void set_lines(const VisionLine &t_newValue, int t_i)
VisionLines(const VisionLines &t_other)
Copy Constructor.
VisionLines(const struct wb_vision_line t_lines[7]=NULLPTR, uint8_t t_numLines=0, uint64_t t_frameNumber=0, uint16_t t_res_width=0, uint16_t t_res_height=0)
Create a new VisionLines.
VisionLines & operator=(const VisionLines &t_other)
Copy Assignment Operator.
VisionLines(const std::string &t_str)
String Constructor.
bool operator==(const VisionLines &t_other) const
void from_string(const std::string &t_str)
void set_res_width(const uint16_t &t_newValue)
const uint8_t & numLines() const
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
Class use to represent lines detected by vision for a single camera and posted to the whiteboard.
uint8_t numLines
The number of lines reported on the camera.
uint16_t res_width
The resolution width.
uint64_t frameNumber
The frame number that these lines were seen in.
struct wb_vision_line lines[7]
Lines reported from the camera.
uint16_t res_height
The resolution height.
const char * wb_vision_lines_description(const struct wb_vision_lines *self, char *descString, size_t bufferSize)
Convert to a description string.
struct wb_vision_lines * wb_vision_lines_from_string(struct wb_vision_lines *self, const char *str)
Convert from a string.
const char * wb_vision_lines_to_string(const struct wb_vision_lines *self, char *toString, size_t bufferSize)
Convert to a string.
#define VISION_LINES_TO_STRING_BUFFER_SIZE
#define VISION_LINES_DESC_BUFFER_SIZE
#define VISION_LINES_LINES_ARRAY_SIZE
WHITEBOARD_POSTER_STRING_CONVERSION.