gusimplewhiteboard
VisionDetectionFeature.hpp
Go to the documentation of this file.
1/*
2 * file VisionDetectionFeature.hpp
3 *
4 * This file was generated by classgenerator from vision_detection_feature.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_VisionDetectionFeature_h
61#define guWhiteboard_VisionDetectionFeature_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_VisionDetectionFeature_DEFINED
73#define guWhiteboard_VisionDetectionFeature_DEFINED
74
75#undef VisionDetectionFeature_DEFINED
76#define VisionDetectionFeature_DEFINED
77
78#include "PolarCoordinate.h"
79
80namespace guWhiteboard {
81
86
87 private:
88
92 void init(enum FeatureTypes t_featureType = NUMBER_OF_FEATURE_TYPES, struct wb_polar_coordinate t_coordinate = wb_polar_coordinate()) {
93 set_featureType(t_featureType);
94 set_coordinate(t_coordinate);
95 }
96
97 public:
98
103 this->init(t_featureType, t_coordinate);
104 }
105
110 this->init(t_other.featureType(), t_other.coordinate());
111 }
112
117 this->init(t_other.featureType, t_other.coordinate);
118 }
119
124 this->init(t_other.featureType(), t_other.coordinate());
125 return *this;
126 }
127
132 this->init(t_other.featureType, t_other.coordinate);
133 return *this;
134 }
135
136 bool operator ==(const VisionDetectionFeature &t_other) const
137 {
138 return featureType() == t_other.featureType()
140 }
141
142 bool operator !=(const VisionDetectionFeature &t_other) const
143 {
144 return !(*this == t_other);
145 }
146
147 bool operator ==(const wb_vision_detection_feature &t_other) const
148 {
149 return *this == VisionDetectionFeature(t_other);
150 }
151
152 bool operator !=(const wb_vision_detection_feature &t_other) const
153 {
154 return !(*this == t_other);
155 }
156
158 {
160 }
161
162 const enum FeatureTypes & featureType() const
163 {
165 }
166
167 void set_featureType(const enum FeatureTypes &t_newValue)
168 {
170 }
171
173 {
174 return const_cast<PolarCoordinate &>(static_cast<const PolarCoordinate &>(wb_vision_detection_feature::coordinate));
175 }
176
178 {
179 return static_cast<const PolarCoordinate &>(wb_vision_detection_feature::coordinate);
180 }
181
182 void set_coordinate(const PolarCoordinate &t_newValue)
183 {
185 }
186
187#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
191 VisionDetectionFeature(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_DETECTION_FEATURE_C_CONVERSION
199 wb_vision_detection_feature_description(this, buffer, sizeof(buffer));
200 std::string descr = buffer;
201 return descr;
202#else
203 std::ostringstream ss;
204 switch (this->featureType()) {
206 {
207 ss << "featureType=" << "FeatureTypeCircle";
208 break;
209 }
210 case FeatureTypeL:
211 {
212 ss << "featureType=" << "FeatureTypeL";
213 break;
214 }
215 case FeatureTypeT:
216 {
217 ss << "featureType=" << "FeatureTypeT";
218 break;
219 }
220 case FeatureTypeX:
221 {
222 ss << "featureType=" << "FeatureTypeX";
223 break;
224 }
226 {
227 ss << "featureType=" << "NUMBER_OF_FEATURE_TYPES";
228 break;
229 }
230 }
231 ss << ", ";
232 ss << "coordinate=" << "{" << PolarCoordinate(this->coordinate()).description() << "}";
233 return ss.str();
234#endif
235 }
236
237 std::string to_string() {
238#ifdef USE_WB_VISION_DETECTION_FEATURE_C_CONVERSION
240 wb_vision_detection_feature_to_string(this, buffer, sizeof(buffer));
241 std::string toString = buffer;
242 return toString;
243#else
244 std::ostringstream ss;
245 switch (this->featureType()) {
247 {
248 ss << "FeatureTypeCircle";
249 break;
250 }
251 case FeatureTypeL:
252 {
253 ss << "FeatureTypeL";
254 break;
255 }
256 case FeatureTypeT:
257 {
258 ss << "FeatureTypeT";
259 break;
260 }
261 case FeatureTypeX:
262 {
263 ss << "FeatureTypeX";
264 break;
265 }
267 {
268 ss << "NUMBER_OF_FEATURE_TYPES";
269 break;
270 }
271 }
272 ss << ", ";
273 ss << "{" << PolarCoordinate(this->coordinate()).to_string() << "}";
274 return ss.str();
275#endif
276 }
277
278#ifdef USE_WB_VISION_DETECTION_FEATURE_C_CONVERSION
279 void from_string(const std::string &t_str) {
280 wb_vision_detection_feature_from_string(this, t_str.c_str());
281#else
282 void from_string(const std::string &t_str) {
283 char * str_cstr = const_cast<char *>(t_str.c_str());
284 size_t temp_length = strlen(str_cstr);
285 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
286 if (length < 1 || length > VISION_DETECTION_FEATURE_DESC_BUFFER_SIZE) {
287 return;
288 }
289 char var_str_buffer[VISION_DETECTION_FEATURE_DESC_BUFFER_SIZE + 1];
290 char* var_str = &var_str_buffer[0];
291 char key_buffer[12];
292 char* key = &key_buffer[0];
293 int bracecount = 0;
294 int startVar = 0;
295 int index = 0;
296 int startKey = 0;
297 int endKey = -1;
298 int varIndex = 0;
299 if (index == 0 && str_cstr[0] == '{') {
300 index = 1;
301 }
302 startVar = index;
303 startKey = startVar;
304 do {
305 for (int i = index; i < length; i++) {
306 index = i + 1;
307 if (bracecount == 0 && str_cstr[i] == '=') {
308 endKey = i - 1;
309 startVar = index;
310 continue;
311 }
312 if (bracecount == 0 && isspace(str_cstr[i])) {
313 startVar = index;
314 if (endKey == -1) {
315 startKey = index;
316 }
317 continue;
318 }
319 if (bracecount == 0 && str_cstr[i] == ',') {
320 index = i - 1;
321 break;
322 }
323 if (str_cstr[i] == '{') {
324 bracecount++;
325 continue;
326 }
327 if (str_cstr[i] == '}') {
328 bracecount--;
329 if (bracecount < 0) {
330 index = i - 1;
331 break;
332 }
333 }
334 if (i == length - 1) {
335 index = i;
336 }
337 }
338 if (endKey >= startKey && endKey - startKey < length) {
339 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
340 key[(endKey - startKey) + 1] = 0;
341 } else {
342 key[0] = 0;
343 }
344 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
345 var_str[(index - startVar) + 1] = 0;
346 bracecount = 0;
347 index += 2;
348 startVar = index;
349 startKey = startVar;
350 endKey = -1;
351 if (strlen(key) > 0) {
352 if (0 == strcmp("featureType", key)) {
353 varIndex = 0;
354 } else if (0 == strcmp("coordinate", key)) {
355 varIndex = 1;
356 } else {
357 varIndex = -1;
358 }
359 }
360 switch (varIndex) {
361 case -1: { break; }
362 case 0:
363 {
364 if (strcmp("FeatureTypeCircle", var_str) == 0) {
365#pragma clang diagnostic push
366#pragma clang diagnostic ignored "-Wbad-function-cast"
368#pragma clang diagnostic pop
369 } else if (strcmp("FeatureTypeL", var_str) == 0) {
370#pragma clang diagnostic push
371#pragma clang diagnostic ignored "-Wbad-function-cast"
373#pragma clang diagnostic pop
374 } else if (strcmp("FeatureTypeT", var_str) == 0) {
375#pragma clang diagnostic push
376#pragma clang diagnostic ignored "-Wbad-function-cast"
378#pragma clang diagnostic pop
379 } else if (strcmp("FeatureTypeX", var_str) == 0) {
380#pragma clang diagnostic push
381#pragma clang diagnostic ignored "-Wbad-function-cast"
383#pragma clang diagnostic pop
384 } else if (strcmp("NUMBER_OF_FEATURE_TYPES", var_str) == 0) {
385#pragma clang diagnostic push
386#pragma clang diagnostic ignored "-Wbad-function-cast"
388#pragma clang diagnostic pop
389 } else {
390#pragma clang diagnostic push
391#pragma clang diagnostic ignored "-Wbad-function-cast"
392 this->set_featureType(static_cast<enum FeatureTypes>(atoi(var_str)));
393#pragma clang diagnostic pop
394 }
395 break;
396 }
397 case 1:
398 {
399 PolarCoordinate coordinate_temp = PolarCoordinate();
400 coordinate_temp.from_string(var_str);
401 this->set_coordinate(coordinate_temp);
402 break;
403 }
404 }
405 if (varIndex >= 0) {
406 varIndex++;
407 }
408 } while(index < length);
409#endif
410 }
411#endif
412 };
413
414}
415
416#endif
Provides a C++ wrapper around wb_polar_coordinate.
void from_string(const std::string &t_str)
Provides a C++ wrapper around wb_vision_detection_feature.
VisionDetectionFeature(const std::string &t_str)
String Constructor.
VisionDetectionFeature(const VisionDetectionFeature &t_other)
Copy Constructor.
const PolarCoordinate & coordinate() const
VisionDetectionFeature & operator=(const VisionDetectionFeature &t_other)
Copy Assignment Operator.
bool operator!=(const VisionDetectionFeature &t_other) const
void set_featureType(const enum FeatureTypes &t_newValue)
bool operator==(const VisionDetectionFeature &t_other) const
void from_string(const std::string &t_str)
VisionDetectionFeature(const struct wb_vision_detection_feature &t_other)
Copy Constructor.
void set_coordinate(const PolarCoordinate &t_newValue)
VisionDetectionFeature(enum FeatureTypes t_featureType=NUMBER_OF_FEATURE_TYPES, struct wb_polar_coordinate t_coordinate=wb_polar_coordinate())
Create a new VisionDetectionFeature.
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
WHITEBOARD_POSTER_STRING_CONVERSION.
struct wb_polar_coordinate coordinate
Where the feature is.
enum FeatureTypes featureType
Type of the Feature.
const char * wb_vision_detection_feature_to_string(const struct wb_vision_detection_feature *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_vision_detection_feature * wb_vision_detection_feature_from_string(struct wb_vision_detection_feature *self, const char *str)
Convert from a string.
const char * wb_vision_detection_feature_description(const struct wb_vision_detection_feature *self, char *descString, size_t bufferSize)
Convert to a description string.
#define VISION_DETECTION_FEATURE_TO_STRING_BUFFER_SIZE
#define VISION_DETECTION_FEATURE_DESC_BUFFER_SIZE
@ NUMBER_OF_FEATURE_TYPES