gusimplewhiteboard
LineSighting.hpp
Go to the documentation of this file.
1/*
2 * file LineSighting.hpp
3 *
4 * This file was generated by classgenerator from line_sighting.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_LineSighting_h
61#define guWhiteboard_LineSighting_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_line_sighting.h"
71
72#undef guWhiteboard_LineSighting_DEFINED
73#define guWhiteboard_LineSighting_DEFINED
74
75#undef LineSighting_DEFINED
76#define LineSighting_DEFINED
77
78#include "PolarCoordinate.h"
79#include <SimpleShapes.h>
80
81namespace guWhiteboard {
82
87
88 private:
89
93 void init(struct wb_polar_coordinate t_leftPoint = wb_polar_coordinate(), struct wb_polar_coordinate t_rightPoint = wb_polar_coordinate(), enum LineSightingType t_sightingType = static_cast<enum LineSightingType>(0)) {
94 set_leftPoint(t_leftPoint);
95 set_rightPoint(t_rightPoint);
96 set_sightingType(t_sightingType);
97 }
98
99 public:
100
104 LineSighting(struct wb_polar_coordinate t_leftPoint = wb_polar_coordinate(), struct wb_polar_coordinate t_rightPoint = wb_polar_coordinate(), enum LineSightingType t_sightingType = static_cast<enum LineSightingType>(0)) {
105 this->init(t_leftPoint, t_rightPoint, t_sightingType);
106 }
107
112 this->init(t_other.leftPoint(), t_other.rightPoint(), t_other.sightingType());
113 }
114
119 this->init(t_other.leftPoint, t_other.rightPoint, t_other.sightingType);
120 }
121
126 this->init(t_other.leftPoint(), t_other.rightPoint(), t_other.sightingType());
127 return *this;
128 }
129
133 LineSighting &operator = (const struct wb_line_sighting &t_other) {
134 this->init(t_other.leftPoint, t_other.rightPoint, t_other.sightingType);
135 return *this;
136 }
137
138 bool operator ==(const LineSighting &t_other) const
139 {
140 return PolarCoordinate(leftPoint()) == PolarCoordinate(t_other.leftPoint())
142 && sightingType() == t_other.sightingType();
143 }
144
145 bool operator !=(const LineSighting &t_other) const
146 {
147 return !(*this == t_other);
148 }
149
150 bool operator ==(const wb_line_sighting &t_other) const
151 {
152 return *this == LineSighting(t_other);
153 }
154
155 bool operator !=(const wb_line_sighting &t_other) const
156 {
157 return !(*this == t_other);
158 }
159
161 {
162 return const_cast<PolarCoordinate &>(static_cast<const PolarCoordinate &>(wb_line_sighting::leftPoint));
163 }
164
166 {
167 return static_cast<const PolarCoordinate &>(wb_line_sighting::leftPoint);
168 }
169
170 void set_leftPoint(const PolarCoordinate &t_newValue)
171 {
172 wb_line_sighting::leftPoint = static_cast<wb_polar_coordinate>(t_newValue);
173 }
174
176 {
177 return const_cast<PolarCoordinate &>(static_cast<const PolarCoordinate &>(wb_line_sighting::rightPoint));
178 }
179
181 {
182 return static_cast<const PolarCoordinate &>(wb_line_sighting::rightPoint);
183 }
184
185 void set_rightPoint(const PolarCoordinate &t_newValue)
186 {
187 wb_line_sighting::rightPoint = static_cast<wb_polar_coordinate>(t_newValue);
188 }
189
191 {
193 }
194
195 const enum LineSightingType & sightingType() const
196 {
198 }
199
200 void set_sightingType(const enum LineSightingType &t_newValue)
201 {
203 }
204
205#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
209 LineSighting(const std::string &t_str) {
210 this->init();
211 this->from_string(t_str);
212 }
213
214 std::string description() {
215#ifdef USE_WB_LINE_SIGHTING_C_CONVERSION
217 wb_line_sighting_description(this, buffer, sizeof(buffer));
218 std::string descr = buffer;
219 return descr;
220#else
221 std::ostringstream ss;
222 ss << "leftPoint=" << "{" << PolarCoordinate(this->leftPoint()).description() << "}";
223 ss << ", ";
224 ss << "rightPoint=" << "{" << PolarCoordinate(this->rightPoint()).description() << "}";
225 ss << ", ";
226 switch (this->sightingType()) {
228 {
229 ss << "sightingType=" << "FieldLineSightingType";
230 break;
231 }
233 {
234 ss << "sightingType=" << "HorizonLineSightingType";
235 break;
236 }
237 }
238 return ss.str();
239#endif
240 }
241
242 std::string to_string() {
243#ifdef USE_WB_LINE_SIGHTING_C_CONVERSION
245 wb_line_sighting_to_string(this, buffer, sizeof(buffer));
246 std::string toString = buffer;
247 return toString;
248#else
249 std::ostringstream ss;
250 ss << "{" << PolarCoordinate(this->leftPoint()).to_string() << "}";
251 ss << ", ";
252 ss << "{" << PolarCoordinate(this->rightPoint()).to_string() << "}";
253 ss << ", ";
254 switch (this->sightingType()) {
256 {
257 ss << "FieldLineSightingType";
258 break;
259 }
261 {
262 ss << "HorizonLineSightingType";
263 break;
264 }
265 }
266 return ss.str();
267#endif
268 }
269
270#ifdef USE_WB_LINE_SIGHTING_C_CONVERSION
271 void from_string(const std::string &t_str) {
272 wb_line_sighting_from_string(this, t_str.c_str());
273#else
274 void from_string(const std::string &t_str) {
275 char * str_cstr = const_cast<char *>(t_str.c_str());
276 size_t temp_length = strlen(str_cstr);
277 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
278 if (length < 1 || length > LINE_SIGHTING_DESC_BUFFER_SIZE) {
279 return;
280 }
281 char var_str_buffer[LINE_SIGHTING_DESC_BUFFER_SIZE + 1];
282 char* var_str = &var_str_buffer[0];
283 char key_buffer[13];
284 char* key = &key_buffer[0];
285 int bracecount = 0;
286 int startVar = 0;
287 int index = 0;
288 int startKey = 0;
289 int endKey = -1;
290 int varIndex = 0;
291 if (index == 0 && str_cstr[0] == '{') {
292 index = 1;
293 }
294 startVar = index;
295 startKey = startVar;
296 do {
297 for (int i = index; i < length; i++) {
298 index = i + 1;
299 if (bracecount == 0 && str_cstr[i] == '=') {
300 endKey = i - 1;
301 startVar = index;
302 continue;
303 }
304 if (bracecount == 0 && isspace(str_cstr[i])) {
305 startVar = index;
306 if (endKey == -1) {
307 startKey = index;
308 }
309 continue;
310 }
311 if (bracecount == 0 && str_cstr[i] == ',') {
312 index = i - 1;
313 break;
314 }
315 if (str_cstr[i] == '{') {
316 bracecount++;
317 continue;
318 }
319 if (str_cstr[i] == '}') {
320 bracecount--;
321 if (bracecount < 0) {
322 index = i - 1;
323 break;
324 }
325 }
326 if (i == length - 1) {
327 index = i;
328 }
329 }
330 if (endKey >= startKey && endKey - startKey < length) {
331 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
332 key[(endKey - startKey) + 1] = 0;
333 } else {
334 key[0] = 0;
335 }
336 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
337 var_str[(index - startVar) + 1] = 0;
338 bracecount = 0;
339 index += 2;
340 startVar = index;
341 startKey = startVar;
342 endKey = -1;
343 if (strlen(key) > 0) {
344 if (0 == strcmp("leftPoint", key)) {
345 varIndex = 0;
346 } else if (0 == strcmp("rightPoint", key)) {
347 varIndex = 1;
348 } else if (0 == strcmp("sightingType", key)) {
349 varIndex = 2;
350 } else {
351 varIndex = -1;
352 }
353 }
354 switch (varIndex) {
355 case -1: { break; }
356 case 0:
357 {
358 PolarCoordinate leftPoint_temp = PolarCoordinate();
359 leftPoint_temp.from_string(var_str);
360 this->set_leftPoint(leftPoint_temp);
361 break;
362 }
363 case 1:
364 {
365 PolarCoordinate rightPoint_temp = PolarCoordinate();
366 rightPoint_temp.from_string(var_str);
367 this->set_rightPoint(rightPoint_temp);
368 break;
369 }
370 case 2:
371 {
372 if (strcmp("FieldLineSightingType", var_str) == 0) {
373#pragma clang diagnostic push
374#pragma clang diagnostic ignored "-Wbad-function-cast"
376#pragma clang diagnostic pop
377 } else if (strcmp("HorizonLineSightingType", var_str) == 0) {
378#pragma clang diagnostic push
379#pragma clang diagnostic ignored "-Wbad-function-cast"
381#pragma clang diagnostic pop
382 } else {
383#pragma clang diagnostic push
384#pragma clang diagnostic ignored "-Wbad-function-cast"
385 this->set_sightingType(static_cast<enum LineSightingType>(atoi(var_str)));
386#pragma clang diagnostic pop
387 }
388 break;
389 }
390 }
391 if (varIndex >= 0) {
392 varIndex++;
393 }
394 } while(index < length);
395#endif
396 }
397#endif
398
399 SimpleLine simpleLine() {
400 GUPoint<short> left = GUPoint<short>(short(leftPoint().distance()), short(leftPoint().direction()), true);
401 GUPoint<short> right = GUPoint<short>(short(rightPoint().distance()), short(rightPoint().direction()), true);
402 return SimpleLine(left, right);
403 }
404 };
405
406}
407
408#endif
Provides a C++ wrapper around wb_line_sighting.
PolarCoordinate & leftPoint()
LineSighting(struct wb_polar_coordinate t_leftPoint=wb_polar_coordinate(), struct wb_polar_coordinate t_rightPoint=wb_polar_coordinate(), enum LineSightingType t_sightingType=static_cast< enum LineSightingType >(0))
Create a new LineSighting.
void set_leftPoint(const PolarCoordinate &t_newValue)
LineSighting(const std::string &t_str)
String Constructor.
LineSighting(const LineSighting &t_other)
Copy Constructor.
bool operator!=(const LineSighting &t_other) const
SimpleLine simpleLine()
WHITEBOARD_POSTER_STRING_CONVERSION.
bool operator==(const LineSighting &t_other) const
enum LineSightingType & sightingType()
const PolarCoordinate & leftPoint() const
PolarCoordinate & rightPoint()
LineSighting(const struct wb_line_sighting &t_other)
Copy Constructor.
void set_sightingType(const enum LineSightingType &t_newValue)
enum LineSightingType & sightingType() const
const PolarCoordinate & rightPoint() const
void set_rightPoint(const PolarCoordinate &t_newValue)
LineSighting & operator=(const LineSighting &t_other)
Copy Assignment Operator.
void from_string(const std::string &t_str)
Provides a C++ wrapper around wb_polar_coordinate.
void from_string(const std::string &t_str)
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
enum LineSightingType sightingType
The type of sighting.
struct wb_polar_coordinate rightPoint
The right/top point of the line.
struct wb_polar_coordinate leftPoint
The left/bottom point of the line.
WHITEBOARD_POSTER_STRING_CONVERSION.
const char * wb_line_sighting_description(const struct wb_line_sighting *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_line_sighting_to_string(const struct wb_line_sighting *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_line_sighting * wb_line_sighting_from_string(struct wb_line_sighting *self, const char *str)
Convert from a string.
LineSightingType
@ HorizonLineSightingType
@ FieldLineSightingType
#define LINE_SIGHTING_DESC_BUFFER_SIZE
#define LINE_SIGHTING_TO_STRING_BUFFER_SIZE