gusimplewhiteboard
Location.hpp
Go to the documentation of this file.
1/*
2 * file Location.hpp
3 *
4 * This file was generated by classgenerator from location.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_Location_h
61#define guWhiteboard_Location_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_location.h"
71
72#undef guWhiteboard_Location_DEFINED
73#define guWhiteboard_Location_DEFINED
74
75#undef Location_DEFINED
76#define Location_DEFINED
77
78#include <guunits/guunits.h>
79#include <gucoordinates/gucoordinates.h>
80
81#if __cplusplus >= 201703L
82#include <optional>
83#endif
84
85namespace guWhiteboard {
86
90 class Location: public wb_location {
91
92 private:
93
97 void init(int16_t t_direction = 0, uint16_t t_distance = 0, uint8_t t_confidence = 0, uint32_t t_distanceVariance = 0, uint32_t t_directionVariance = 0) {
98 set_direction(t_direction);
99 set_distance(t_distance);
100 set_confidence(t_confidence);
101 set_distanceVariance(t_distanceVariance);
102 set_directionVariance(t_directionVariance);
103 }
104
105 public:
106
110 Location(int16_t t_direction = 0, uint16_t t_distance = 0, uint8_t t_confidence = 0, uint32_t t_distanceVariance = 0, uint32_t t_directionVariance = 0) {
111 this->init(t_direction, t_distance, t_confidence, t_distanceVariance, t_directionVariance);
112 }
113
117 Location(const Location &t_other): wb_location() {
118 this->init(t_other.direction(), t_other.distance(), t_other.confidence(), t_other.distanceVariance(), t_other.directionVariance());
119 }
120
124 Location(const struct wb_location &t_other): wb_location() {
125 this->init(t_other.direction, t_other.distance, t_other.confidence, t_other.distanceVariance, t_other.directionVariance);
126 }
127
131 Location &operator = (const Location &t_other) {
132 this->init(t_other.direction(), t_other.distance(), t_other.confidence(), t_other.distanceVariance(), t_other.directionVariance());
133 return *this;
134 }
135
139 Location &operator = (const struct wb_location &t_other) {
140 this->init(t_other.direction, t_other.distance, t_other.confidence, t_other.distanceVariance, t_other.directionVariance);
141 return *this;
142 }
143
144 bool operator ==(const Location &t_other) const
145 {
146 return direction() == t_other.direction()
147 && distance() == t_other.distance()
148 && confidence() == t_other.confidence()
149 && distanceVariance() == t_other.distanceVariance()
150 && directionVariance() == t_other.directionVariance();
151 }
152
153 bool operator !=(const Location &t_other) const
154 {
155 return !(*this == t_other);
156 }
157
158 bool operator ==(const wb_location &t_other) const
159 {
160 return *this == Location(t_other);
161 }
162
163 bool operator !=(const wb_location &t_other) const
164 {
165 return !(*this == t_other);
166 }
167
168 int16_t & direction()
169 {
171 }
172
173 const int16_t & direction() const
174 {
176 }
177
178 void set_direction(const int16_t &t_newValue)
179 {
180 wb_location::direction = t_newValue;
181 }
182
183 uint16_t & distance()
184 {
186 }
187
188 const uint16_t & distance() const
189 {
191 }
192
193 void set_distance(const uint16_t &t_newValue)
194 {
195 wb_location::distance = t_newValue;
196 }
197
198 uint8_t & confidence()
199 {
201 }
202
203 const uint8_t & confidence() const
204 {
206 }
207
208 void set_confidence(const uint8_t &t_newValue)
209 {
210 wb_location::confidence = t_newValue;
211 }
212
213 uint32_t & distanceVariance()
214 {
216 }
217
218 const uint32_t & distanceVariance() const
219 {
221 }
222
223 void set_distanceVariance(const uint32_t &t_newValue)
224 {
226 }
227
228 uint32_t & directionVariance()
229 {
231 }
232
233 const uint32_t & directionVariance() const
234 {
236 }
237
238 void set_directionVariance(const uint32_t &t_newValue)
239 {
241 }
242
243#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
247 Location(const std::string &t_str) {
248 this->init();
249 this->from_string(t_str);
250 }
251
252 std::string description() {
253#ifdef USE_WB_LOCATION_C_CONVERSION
254 char buffer[LOCATION_DESC_BUFFER_SIZE];
255 wb_location_description(this, buffer, sizeof(buffer));
256 std::string descr = buffer;
257 return descr;
258#else
259 std::ostringstream ss;
260 ss << "direction=" << static_cast<signed>(this->direction());
261 ss << ", ";
262 ss << "distance=" << static_cast<unsigned>(this->distance());
263 ss << ", ";
264 ss << "confidence=" << static_cast<unsigned>(this->confidence());
265 ss << ", ";
266 ss << "distanceVariance=" << static_cast<unsigned>(this->distanceVariance());
267 ss << ", ";
268 ss << "directionVariance=" << static_cast<unsigned>(this->directionVariance());
269 return ss.str();
270#endif
271 }
272
273 std::string to_string() {
274#ifdef USE_WB_LOCATION_C_CONVERSION
276 wb_location_to_string(this, buffer, sizeof(buffer));
277 std::string toString = buffer;
278 return toString;
279#else
280 std::ostringstream ss;
281 ss << static_cast<signed>(this->direction());
282 ss << ", ";
283 ss << static_cast<unsigned>(this->distance());
284 ss << ", ";
285 ss << static_cast<unsigned>(this->confidence());
286 ss << ", ";
287 ss << static_cast<unsigned>(this->distanceVariance());
288 ss << ", ";
289 ss << static_cast<unsigned>(this->directionVariance());
290 return ss.str();
291#endif
292 }
293
294#ifdef USE_WB_LOCATION_C_CONVERSION
295 void from_string(const std::string &t_str) {
296 wb_location_from_string(this, t_str.c_str());
297#else
298 void from_string(const std::string &t_str) {
299 char * str_cstr = const_cast<char *>(t_str.c_str());
300 size_t temp_length = strlen(str_cstr);
301 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
302 if (length < 1 || length > LOCATION_DESC_BUFFER_SIZE) {
303 return;
304 }
305 char var_str_buffer[LOCATION_DESC_BUFFER_SIZE + 1];
306 char* var_str = &var_str_buffer[0];
307 char key_buffer[18];
308 char* key = &key_buffer[0];
309 int bracecount = 0;
310 int startVar = 0;
311 int index = 0;
312 int startKey = 0;
313 int endKey = -1;
314 int varIndex = 0;
315 if (index == 0 && str_cstr[0] == '{') {
316 index = 1;
317 }
318 startVar = index;
319 startKey = startVar;
320 do {
321 for (int i = index; i < length; i++) {
322 index = i + 1;
323 if (bracecount == 0 && str_cstr[i] == '=') {
324 endKey = i - 1;
325 startVar = index;
326 continue;
327 }
328 if (bracecount == 0 && isspace(str_cstr[i])) {
329 startVar = index;
330 if (endKey == -1) {
331 startKey = index;
332 }
333 continue;
334 }
335 if (bracecount == 0 && str_cstr[i] == ',') {
336 index = i - 1;
337 break;
338 }
339 if (str_cstr[i] == '{') {
340 bracecount++;
341 continue;
342 }
343 if (str_cstr[i] == '}') {
344 bracecount--;
345 if (bracecount < 0) {
346 index = i - 1;
347 break;
348 }
349 }
350 if (i == length - 1) {
351 index = i;
352 }
353 }
354 if (endKey >= startKey && endKey - startKey < length) {
355 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
356 key[(endKey - startKey) + 1] = 0;
357 } else {
358 key[0] = 0;
359 }
360 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
361 var_str[(index - startVar) + 1] = 0;
362 bracecount = 0;
363 index += 2;
364 startVar = index;
365 startKey = startVar;
366 endKey = -1;
367 if (strlen(key) > 0) {
368 if (0 == strcmp("direction", key)) {
369 varIndex = 0;
370 } else if (0 == strcmp("distance", key)) {
371 varIndex = 1;
372 } else if (0 == strcmp("confidence", key)) {
373 varIndex = 2;
374 } else if (0 == strcmp("distanceVariance", key)) {
375 varIndex = 3;
376 } else if (0 == strcmp("directionVariance", key)) {
377 varIndex = 4;
378 } else {
379 varIndex = -1;
380 }
381 }
382 switch (varIndex) {
383 case -1: { break; }
384 case 0:
385 {
386 this->set_direction(static_cast<int16_t>(atoi(var_str)));
387 break;
388 }
389 case 1:
390 {
391 this->set_distance(static_cast<uint16_t>(atoi(var_str)));
392 break;
393 }
394 case 2:
395 {
396 this->set_confidence(static_cast<uint8_t>(atoi(var_str)));
397 break;
398 }
399 case 3:
400 {
401 this->set_distanceVariance(static_cast<uint32_t>(atoi(var_str)));
402 break;
403 }
404 case 4:
405 {
406 this->set_directionVariance(static_cast<uint32_t>(atoi(var_str)));
407 break;
408 }
409 }
410 if (varIndex >= 0) {
411 varIndex++;
412 }
413 } while(index < length);
414#endif
415 }
416#endif
417
427 Location(const GU::RelativeCoordinate &t_other)
428 {
429 this->init(
430 deg_d_to_i16(t_other.direction()),
431 cm_u_to_u16(mm_u_to_cm_u(t_other.distance()))
432 );
433 }
434
446 Location(const GU::RelativeCoordinate &t_other, const uint8_t t_confidence)
447 {
448 this->init(
449 deg_d_to_i16(t_other.direction()),
450 cm_u_to_u16(mm_u_to_cm_u(t_other.distance())),
451 t_confidence
452 );
453 }
454
467 Location(const GU::RelativeCoordinate &t_other, const uint8_t t_confidence, const uint32_t t_distanceVariance, uint32_t t_directionVariance)
468 {
469 this->init(
470 deg_d_to_i16(t_other.direction()),
471 cm_u_to_u16(mm_u_to_cm_u(t_other.distance())),
472 t_confidence,
473 t_distanceVariance,
474 t_directionVariance
475 );
476 }
477
483 GU::RelativeCoordinate relativeCoordinate() const
484 {
485 return GU::RelativeCoordinate(wb_location_to_rr_coord(*this));
486 }
487
501 GU::OptionalRelativeCoordinate optionalRelativeCoordinate(const uint8_t minimumConfidence) const
502 {
503 return GU::OptionalRelativeCoordinate(wb_location_to_opt_rr_coord(*this, minimumConfidence));
504 }
505
506#if __cplusplus >= 201703L
520 std::optional<GU::RelativeCoordinate> relativeCoordinate(const uint8_t minimumConfidence) const
521 {
522 if (confidence() < minimumConfidence) return std::nullopt;
523 return std::optional<GU::RelativeCoordinate>(relativeCoordinate());
524 }
525#endif
526 };
527
528}
529
530#endif
Provides a C++ wrapper around wb_location.
Definition: Location.hpp:90
Location(const struct wb_location &t_other)
Copy Constructor.
Definition: Location.hpp:124
const uint32_t & distanceVariance() const
Definition: Location.hpp:218
std::optional< GU::RelativeCoordinate > relativeCoordinate(const uint8_t minimumConfidence) const
Convert this location to a GU::RelativeCoordinate only if the confidence of the location is greater t...
Definition: Location.hpp:520
int16_t & direction()
Definition: Location.hpp:168
void set_distanceVariance(const uint32_t &t_newValue)
Definition: Location.hpp:223
Location & operator=(const Location &t_other)
Copy Assignment Operator.
Definition: Location.hpp:131
std::string description()
Definition: Location.hpp:252
uint32_t & distanceVariance()
Definition: Location.hpp:213
Location(const GU::RelativeCoordinate &t_other, const uint8_t t_confidence)
Create a new Location by converting the values from a GU::RelativeCoordinate.
Definition: Location.hpp:446
const uint16_t & distance() const
Definition: Location.hpp:188
Location(int16_t t_direction=0, uint16_t t_distance=0, uint8_t t_confidence=0, uint32_t t_distanceVariance=0, uint32_t t_directionVariance=0)
Create a new Location.
Definition: Location.hpp:110
void set_distance(const uint16_t &t_newValue)
Definition: Location.hpp:193
uint8_t & confidence()
Definition: Location.hpp:198
const int16_t & direction() const
Definition: Location.hpp:173
bool operator==(const Location &t_other) const
Definition: Location.hpp:144
void set_directionVariance(const uint32_t &t_newValue)
Definition: Location.hpp:238
const uint8_t & confidence() const
Definition: Location.hpp:203
std::string to_string()
Definition: Location.hpp:273
uint16_t & distance()
Definition: Location.hpp:183
const uint32_t & directionVariance() const
Definition: Location.hpp:233
GU::RelativeCoordinate relativeCoordinate() const
Convert this location to a GU::RelativeCoordinate.
Definition: Location.hpp:483
void set_confidence(const uint8_t &t_newValue)
Definition: Location.hpp:208
bool operator!=(const Location &t_other) const
Definition: Location.hpp:153
void from_string(const std::string &t_str)
Definition: Location.hpp:298
Location(const GU::RelativeCoordinate &t_other)
WHITEBOARD_POSTER_STRING_CONVERSION.
Definition: Location.hpp:427
Location(const std::string &t_str)
String Constructor.
Definition: Location.hpp:247
uint32_t & directionVariance()
Definition: Location.hpp:228
void set_direction(const int16_t &t_newValue)
Definition: Location.hpp:178
Location(const Location &t_other)
Copy Constructor.
Definition: Location.hpp:117
GU::OptionalRelativeCoordinate optionalRelativeCoordinate(const uint8_t minimumConfidence) const
Convert this location to a GU::RelativeCoordinate only if the confidence of the location is greater t...
Definition: Location.hpp:501
Location(const GU::RelativeCoordinate &t_other, const uint8_t t_confidence, const uint32_t t_distanceVariance, uint32_t t_directionVariance)
Create a new Location by converting the values from a GU::RelativeCoordinate.
Definition: Location.hpp:467
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
Definition: wb_location.h:109
uint32_t distanceVariance
The variance of the distance.
Definition: wb_location.h:129
uint32_t directionVariance
The variance of the direction.
Definition: wb_location.h:134
int16_t direction
degrees, relative to the center of the nao torso.
Definition: wb_location.h:114
uint8_t confidence
The type of sighting.
Definition: wb_location.h:124
uint16_t distance
CM distance to the center point of the sighting.
Definition: wb_location.h:119
const char * wb_location_description(const struct wb_location *self, char *descString, size_t bufferSize)
Convert to a description string.
Definition: wb_location.c:125
const char * wb_location_to_string(const struct wb_location *self, char *toString, size_t bufferSize)
Convert to a string.
Definition: wb_location.c:173
struct gu_optional_relative_coordinate wb_location_to_opt_rr_coord(const struct wb_location location, const uint8_t confidence)
Converts a wb_location to a gu_optional_relative_coordinate.
Definition: wb_location.c:532
struct wb_location * wb_location_from_string(struct wb_location *self, const char *str)
Convert from a string.
Definition: wb_location.c:221
struct gu_relative_coordinate wb_location_to_rr_coord(const struct wb_location location)
Converts a wb_location to a gu_relative_coordinate.
Definition: wb_location.c:523
#define LOCATION_TO_STRING_BUFFER_SIZE
Definition: wb_location.h:98
#define LOCATION_DESC_BUFFER_SIZE
Definition: wb_location.h:97