gusimplewhiteboard
VisionDetectionFeatureArray.hpp
Go to the documentation of this file.
1/*
2 * file VisionDetectionFeatureArray.hpp
3 *
4 * This file was generated by classgenerator from vision_detection_feature_array.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_VisionDetectionFeatureArray_h
61#define guWhiteboard_VisionDetectionFeatureArray_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_VisionDetectionFeatureArray_DEFINED
73#define guWhiteboard_VisionDetectionFeatureArray_DEFINED
74
75#undef VisionDetectionFeatureArray_DEFINED
76#define VisionDetectionFeatureArray_DEFINED
77
79
80namespace guWhiteboard {
81
86
87 private:
88
92 void init(uint8_t t_numFeatures = 0, const struct wb_vision_detection_feature t_features[7] = NULLPTR) {
93 set_numFeatures(t_numFeatures);
94 if (t_features != NULLPTR) {
96 } else {
99 }
100 }
101
102 public:
103
107 VisionDetectionFeatureArray(uint8_t t_numFeatures = 0, const struct wb_vision_detection_feature t_features[7] = NULLPTR) {
108 this->init(t_numFeatures, t_features);
109 }
110
115 this->init(t_other.numFeatures(), t_other.features());
116 }
117
122 this->init(t_other.numFeatures, t_other.features);
123 }
124
129 this->init(t_other.numFeatures(), t_other.features());
130 return *this;
131 }
132
137 this->init(t_other.numFeatures, t_other.features);
138 return *this;
139 }
140
141 bool operator ==(const VisionDetectionFeatureArray &t_other) const
142 {
143 if (!(numFeatures() == t_other.numFeatures()))
144 {
145 return false;
146 }
147 for (int features_0_index = 0; features_0_index < 7; features_0_index++)
148 {
149 if (!(VisionDetectionFeature(features(features_0_index)) == VisionDetectionFeature(t_other.features(features_0_index)))) return false;
150 }
151 return true;
152 }
153
154 bool operator !=(const VisionDetectionFeatureArray &t_other) const
155 {
156 return !(*this == t_other);
157 }
158
160 {
161 return *this == VisionDetectionFeatureArray(t_other);
162 }
163
165 {
166 return !(*this == t_other);
167 }
168
169 uint8_t & numFeatures()
170 {
172 }
173
174 const uint8_t & numFeatures() const
175 {
177 }
178
179 void set_numFeatures(const uint8_t &t_newValue)
180 {
182 }
183
185 {
187 }
188
189 size_t features_size() const
190 {
192 }
193
195 {
197 }
198
199 const VisionDetectionFeature & features(int t_i) const
200 {
202 }
203
204 void set_features(const VisionDetectionFeature *t_newValue)
205 {
207 }
208
209 void set_features(const VisionDetectionFeature &t_newValue, int t_i)
210 {
212 }
213
214#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
218 VisionDetectionFeatureArray(const std::string &t_str) {
219 this->init();
220 this->from_string(t_str);
221 }
222
223 std::string description() {
224#ifdef USE_WB_VISION_DETECTION_FEATURE_ARRAY_C_CONVERSION
226 wb_vision_detection_feature_array_description(this, buffer, sizeof(buffer));
227 std::string descr = buffer;
228 return descr;
229#else
230 std::ostringstream ss;
231 ss << "numFeatures=" << static_cast<unsigned>(this->numFeatures());
232 ss << ", ";
233 bool features_first = true;
234 ss << "features={";
236 ss << (features_first ? "" : ", ") << "{" << VisionDetectionFeature(this->features(i)).description() << "}";
237 features_first = false;
238 }
239 ss << "}";
240 return ss.str();
241#endif
242 }
243
244 std::string to_string() {
245#ifdef USE_WB_VISION_DETECTION_FEATURE_ARRAY_C_CONVERSION
247 wb_vision_detection_feature_array_to_string(this, buffer, sizeof(buffer));
248 std::string toString = buffer;
249 return toString;
250#else
251 std::ostringstream ss;
252 ss << static_cast<unsigned>(this->numFeatures());
253 ss << ", ";
254 bool features_first = true;
255 ss << "{";
257 ss << (features_first ? "" : ", ") << "{" << VisionDetectionFeature(this->features(i)).to_string() << "}";
258 features_first = false;
259 }
260 ss << "}";
261 return ss.str();
262#endif
263 }
264
265#ifdef USE_WB_VISION_DETECTION_FEATURE_ARRAY_C_CONVERSION
266 void from_string(const std::string &t_str) {
268#else
269 void from_string(const std::string &t_str) {
270 char * str_cstr = const_cast<char *>(t_str.c_str());
271 size_t temp_length = strlen(str_cstr);
272 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
273 if (length < 1 || length > VISION_DETECTION_FEATURE_ARRAY_DESC_BUFFER_SIZE) {
274 return;
275 }
277 char* var_str = &var_str_buffer[0];
278 char key_buffer[12];
279 char* key = &key_buffer[0];
280 int bracecount = 0;
281 int lastBrace = -1;
282 int startVar = 0;
283 int index = 0;
284 int startKey = 0;
285 int endKey = -1;
286 int varIndex = 0;
287 if (index == 0 && str_cstr[0] == '{') {
288 index = 1;
289 }
290 startVar = index;
291 startKey = startVar;
292 do {
293 for (int i = index; i < length; i++) {
294 index = i + 1;
295 if (bracecount == 0 && str_cstr[i] == '=') {
296 endKey = i - 1;
297 startVar = index;
298 continue;
299 }
300 if (bracecount == 0 && isspace(str_cstr[i])) {
301 startVar = index;
302 if (endKey == -1) {
303 startKey = index;
304 }
305 continue;
306 }
307 if (bracecount == 0 && str_cstr[i] == ',') {
308 index = i - 1;
309 break;
310 }
311 if (str_cstr[i] == '{') {
312 bracecount++;
313 if (bracecount == 1) {
314 lastBrace = i;
315 }
316 continue;
317 }
318 if (str_cstr[i] == '}') {
319 bracecount--;
320 if (bracecount < 0) {
321 index = i - 1;
322 break;
323 }
324 }
325 if (i == length - 1) {
326 index = i;
327 }
328 }
329 if (endKey >= startKey && endKey - startKey < length) {
330 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
331 key[(endKey - startKey) + 1] = 0;
332 } else {
333 key[0] = 0;
334 }
335 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
336 var_str[(index - startVar) + 1] = 0;
337 bracecount = 0;
338 index += 2;
339 startVar = index;
340 startKey = startVar;
341 endKey = -1;
342 if (strlen(key) > 0) {
343 if (0 == strcmp("numFeatures", key)) {
344 varIndex = 0;
345 } else if (0 == strcmp("features", key)) {
346 varIndex = 1;
347 } else {
348 varIndex = -1;
349 }
350 }
351 switch (varIndex) {
352 case -1: { break; }
353 case 0:
354 {
355 this->set_numFeatures(static_cast<uint8_t>(atoi(var_str)));
356 break;
357 }
358 case 1:
359 {
360 int restartIndex = index;
361 index = lastBrace + 1;
362 startVar = index;
363 startKey = startVar;
364 endKey = -1;
365 bracecount = 0;
366 for (int features_0_index = 0; features_0_index < VISION_DETECTION_FEATURE_ARRAY_FEATURES_ARRAY_SIZE; features_0_index++) {
367 for (int i = index; i < length; i++) {
368 index = i + 1;
369 if (bracecount == 0 && str_cstr[i] == '=') {
370 endKey = i - 1;
371 startVar = index;
372 continue;
373 }
374 if (bracecount == 0 && isspace(str_cstr[i])) {
375 startVar = index;
376 if (endKey == -1) {
377 startKey = index;
378 }
379 continue;
380 }
381 if (bracecount == 0 && str_cstr[i] == ',') {
382 index = i - 1;
383 break;
384 }
385 if (str_cstr[i] == '{') {
386 bracecount++;
387 continue;
388 }
389 if (str_cstr[i] == '}') {
390 bracecount--;
391 if (bracecount < 0) {
392 index = i - 1;
393 break;
394 }
395 }
396 if (i == length - 1) {
397 index = i;
398 }
399 }
400 if (endKey >= startKey && endKey - startKey < length) {
401 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
402 key[(endKey - startKey) + 1] = 0;
403 } else {
404 key[0] = 0;
405 }
406 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
407 var_str[(index - startVar) + 1] = 0;
408 bracecount = 0;
409 index += 2;
410 startVar = index;
411 startKey = startVar;
412 endKey = -1;
414 features_0_temp.from_string(var_str);
415 struct wb_vision_detection_feature features_0 = features_0_temp;
416 this->set_features(features_0, features_0_index);
417 }
418 index = restartIndex;
419 break;
420 }
421 }
422 if (varIndex >= 0) {
423 varIndex++;
424 }
425 } while(index < length);
426#endif
427 }
428#endif
429 };
430
431}
432
433#endif
Provides a C++ wrapper around wb_vision_detection_feature_array.
void set_features(const VisionDetectionFeature *t_newValue)
const VisionDetectionFeature & features(int t_i) const
VisionDetectionFeatureArray & operator=(const VisionDetectionFeatureArray &t_other)
Copy Assignment Operator.
VisionDetectionFeatureArray(const struct wb_vision_detection_feature_array &t_other)
Copy Constructor.
bool operator==(const VisionDetectionFeatureArray &t_other) const
void set_features(const VisionDetectionFeature &t_newValue, int t_i)
const VisionDetectionFeature * features() const
bool operator!=(const VisionDetectionFeatureArray &t_other) const
VisionDetectionFeatureArray(const std::string &t_str)
String Constructor.
VisionDetectionFeatureArray(const VisionDetectionFeatureArray &t_other)
Copy Constructor.
VisionDetectionFeatureArray(uint8_t t_numFeatures=0, const struct wb_vision_detection_feature t_features[7]=NULLPTR)
Create a new VisionDetectionFeatureArray.
Provides a C++ wrapper around wb_vision_detection_feature.
void from_string(const std::string &t_str)
/file APM_Interface.h
Results for the Feature Detector (guvision).
uint8_t numFeatures
The number of features reported on the camera.
struct wb_vision_detection_feature features[7]
Features reported from the camera.
WHITEBOARD_POSTER_STRING_CONVERSION.
const char * wb_vision_detection_feature_array_description(const struct wb_vision_detection_feature_array *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_vision_detection_feature_array_to_string(const struct wb_vision_detection_feature_array *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_vision_detection_feature_array * wb_vision_detection_feature_array_from_string(struct wb_vision_detection_feature_array *self, const char *str)
Convert from a string.
#define VISION_DETECTION_FEATURE_ARRAY_TO_STRING_BUFFER_SIZE
#define VISION_DETECTION_FEATURE_ARRAY_FEATURES_ARRAY_SIZE
WHITEBOARD_POSTER_STRING_CONVERSION.
#define VISION_DETECTION_FEATURE_ARRAY_DESC_BUFFER_SIZE