gusimplewhiteboard
VisionLine.hpp
Go to the documentation of this file.
1/*
2 * file VisionLine.hpp
3 *
4 * This file was generated by classgenerator from vision_line.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_VisionLine_h
61#define guWhiteboard_VisionLine_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_line.h"
71
72#undef guWhiteboard_VisionLine_DEFINED
73#define guWhiteboard_VisionLine_DEFINED
74
75#undef VisionLine_DEFINED
76#define VisionLine_DEFINED
77
78#include "PixelCoordinateLine.h"
79
80namespace guWhiteboard {
81
85 class VisionLine: public wb_vision_line {
86
87 private:
88
92 void init(struct wb_pixel_coordinate_line t_lineEdgeTop = wb_pixel_coordinate_line(), struct wb_pixel_coordinate_line t_lineEdgeBottom = wb_pixel_coordinate_line()) {
93 set_lineEdgeTop(t_lineEdgeTop);
94 set_lineEdgeBottom(t_lineEdgeBottom);
95 }
96
97 public:
98
103 this->init(t_lineEdgeTop, t_lineEdgeBottom);
104 }
105
110 this->init(t_other.lineEdgeTop(), t_other.lineEdgeBottom());
111 }
112
116 VisionLine(const struct wb_vision_line &t_other): wb_vision_line() {
117 this->init(t_other.lineEdgeTop, t_other.lineEdgeBottom);
118 }
119
124 this->init(t_other.lineEdgeTop(), t_other.lineEdgeBottom());
125 return *this;
126 }
127
131 VisionLine &operator = (const struct wb_vision_line &t_other) {
132 this->init(t_other.lineEdgeTop, t_other.lineEdgeBottom);
133 return *this;
134 }
135
136 bool operator ==(const VisionLine &t_other) const
137 {
140 }
141
142 bool operator !=(const VisionLine &t_other) const
143 {
144 return !(*this == t_other);
145 }
146
147 bool operator ==(const wb_vision_line &t_other) const
148 {
149 return *this == VisionLine(t_other);
150 }
151
152 bool operator !=(const wb_vision_line &t_other) const
153 {
154 return !(*this == t_other);
155 }
156
158 {
159 return const_cast<PixelCoordinateLine &>(static_cast<const PixelCoordinateLine &>(wb_vision_line::lineEdgeTop));
160 }
161
163 {
164 return static_cast<const PixelCoordinateLine &>(wb_vision_line::lineEdgeTop);
165 }
166
167 void set_lineEdgeTop(const PixelCoordinateLine &t_newValue)
168 {
169 wb_vision_line::lineEdgeTop = static_cast<wb_pixel_coordinate_line>(t_newValue);
170 }
171
173 {
174 return const_cast<PixelCoordinateLine &>(static_cast<const PixelCoordinateLine &>(wb_vision_line::lineEdgeBottom));
175 }
176
178 {
179 return static_cast<const PixelCoordinateLine &>(wb_vision_line::lineEdgeBottom);
180 }
181
183 {
185 }
186
187#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
191 VisionLine(const std::string &t_str) {
192 this->init();
193 this->from_string(t_str);
194 }
195
196 std::string description() {
197#ifdef USE_WB_VISION_LINE_C_CONVERSION
198 char buffer[VISION_LINE_DESC_BUFFER_SIZE];
199 wb_vision_line_description(this, buffer, sizeof(buffer));
200 std::string descr = buffer;
201 return descr;
202#else
203 std::ostringstream ss;
204 ss << "lineEdgeTop=" << "{" << PixelCoordinateLine(this->lineEdgeTop()).description() << "}";
205 ss << ", ";
206 ss << "lineEdgeBottom=" << "{" << PixelCoordinateLine(this->lineEdgeBottom()).description() << "}";
207 return ss.str();
208#endif
209 }
210
211 std::string to_string() {
212#ifdef USE_WB_VISION_LINE_C_CONVERSION
214 wb_vision_line_to_string(this, buffer, sizeof(buffer));
215 std::string toString = buffer;
216 return toString;
217#else
218 std::ostringstream ss;
219 ss << "{" << PixelCoordinateLine(this->lineEdgeTop()).to_string() << "}";
220 ss << ", ";
221 ss << "{" << PixelCoordinateLine(this->lineEdgeBottom()).to_string() << "}";
222 return ss.str();
223#endif
224 }
225
226#ifdef USE_WB_VISION_LINE_C_CONVERSION
227 void from_string(const std::string &t_str) {
228 wb_vision_line_from_string(this, t_str.c_str());
229#else
230 void from_string(const std::string &t_str) {
231 char * str_cstr = const_cast<char *>(t_str.c_str());
232 size_t temp_length = strlen(str_cstr);
233 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
234 if (length < 1 || length > VISION_LINE_DESC_BUFFER_SIZE) {
235 return;
236 }
237 char var_str_buffer[VISION_LINE_DESC_BUFFER_SIZE + 1];
238 char* var_str = &var_str_buffer[0];
239 char key_buffer[15];
240 char* key = &key_buffer[0];
241 int bracecount = 0;
242 int startVar = 0;
243 int index = 0;
244 int startKey = 0;
245 int endKey = -1;
246 int varIndex = 0;
247 if (index == 0 && str_cstr[0] == '{') {
248 index = 1;
249 }
250 startVar = index;
251 startKey = startVar;
252 do {
253 for (int i = index; i < length; i++) {
254 index = i + 1;
255 if (bracecount == 0 && str_cstr[i] == '=') {
256 endKey = i - 1;
257 startVar = index;
258 continue;
259 }
260 if (bracecount == 0 && isspace(str_cstr[i])) {
261 startVar = index;
262 if (endKey == -1) {
263 startKey = index;
264 }
265 continue;
266 }
267 if (bracecount == 0 && str_cstr[i] == ',') {
268 index = i - 1;
269 break;
270 }
271 if (str_cstr[i] == '{') {
272 bracecount++;
273 continue;
274 }
275 if (str_cstr[i] == '}') {
276 bracecount--;
277 if (bracecount < 0) {
278 index = i - 1;
279 break;
280 }
281 }
282 if (i == length - 1) {
283 index = i;
284 }
285 }
286 if (endKey >= startKey && endKey - startKey < length) {
287 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
288 key[(endKey - startKey) + 1] = 0;
289 } else {
290 key[0] = 0;
291 }
292 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
293 var_str[(index - startVar) + 1] = 0;
294 bracecount = 0;
295 index += 2;
296 startVar = index;
297 startKey = startVar;
298 endKey = -1;
299 if (strlen(key) > 0) {
300 if (0 == strcmp("lineEdgeTop", key)) {
301 varIndex = 0;
302 } else if (0 == strcmp("lineEdgeBottom", key)) {
303 varIndex = 1;
304 } else {
305 varIndex = -1;
306 }
307 }
308 switch (varIndex) {
309 case -1: { break; }
310 case 0:
311 {
312 PixelCoordinateLine lineEdgeTop_temp = PixelCoordinateLine();
313 lineEdgeTop_temp.from_string(var_str);
314 this->set_lineEdgeTop(lineEdgeTop_temp);
315 break;
316 }
317 case 1:
318 {
319 PixelCoordinateLine lineEdgeBottom_temp = PixelCoordinateLine();
320 lineEdgeBottom_temp.from_string(var_str);
321 this->set_lineEdgeBottom(lineEdgeBottom_temp);
322 break;
323 }
324 }
325 if (varIndex >= 0) {
326 varIndex++;
327 }
328 } while(index < length);
329#endif
330 }
331#endif
332 };
333
334}
335
336#endif
Provides a C++ wrapper around wb_pixel_coordinate_line.
void from_string(const std::string &t_str)
Provides a C++ wrapper around wb_vision_line.
Definition: VisionLine.hpp:85
const PixelCoordinateLine & lineEdgeTop() const
Definition: VisionLine.hpp:162
VisionLine & operator=(const VisionLine &t_other)
Copy Assignment Operator.
Definition: VisionLine.hpp:123
VisionLine(const struct wb_vision_line &t_other)
Copy Constructor.
Definition: VisionLine.hpp:116
void from_string(const std::string &t_str)
Definition: VisionLine.hpp:230
PixelCoordinateLine & lineEdgeBottom()
Definition: VisionLine.hpp:172
PixelCoordinateLine & lineEdgeTop()
Definition: VisionLine.hpp:157
void set_lineEdgeTop(const PixelCoordinateLine &t_newValue)
Definition: VisionLine.hpp:167
std::string description()
Definition: VisionLine.hpp:196
bool operator!=(const VisionLine &t_other) const
Definition: VisionLine.hpp:142
VisionLine(struct wb_pixel_coordinate_line t_lineEdgeTop=wb_pixel_coordinate_line(), struct wb_pixel_coordinate_line t_lineEdgeBottom=wb_pixel_coordinate_line())
Create a new VisionLine.
Definition: VisionLine.hpp:102
VisionLine(const VisionLine &t_other)
Copy Constructor.
Definition: VisionLine.hpp:109
VisionLine(const std::string &t_str)
String Constructor.
Definition: VisionLine.hpp:191
const PixelCoordinateLine & lineEdgeBottom() const
Definition: VisionLine.hpp:177
bool operator==(const VisionLine &t_other) const
Definition: VisionLine.hpp:136
void set_lineEdgeBottom(const PixelCoordinateLine &t_newValue)
Definition: VisionLine.hpp:182
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
WHITEBOARD_POSTER_STRING_CONVERSION.
struct wb_pixel_coordinate_line lineEdgeTop
line object representing the top edge of an SPL line.
struct wb_pixel_coordinate_line lineEdgeBottom
line object representing the bottom edge of an SPL line.
const char * wb_vision_line_description(const struct wb_vision_line *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_vision_line_to_string(const struct wb_vision_line *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_vision_line * wb_vision_line_from_string(struct wb_vision_line *self, const char *str)
Convert from a string.
#define VISION_LINE_DESC_BUFFER_SIZE
#define VISION_LINE_TO_STRING_BUFFER_SIZE