gusimplewhiteboard
VisionFieldFeature.hpp
Go to the documentation of this file.
1/*
2 * file VisionFieldFeature.hpp
3 *
4 * This file was generated by classgenerator from vision_field_feature.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Eugene Gilmore. 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 Eugene Gilmore.
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_VisionFieldFeature_h
61#define guWhiteboard_VisionFieldFeature_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_VisionFieldFeature_DEFINED
73#define guWhiteboard_VisionFieldFeature_DEFINED
74
75#undef VisionFieldFeature_DEFINED
76#define VisionFieldFeature_DEFINED
77
78#include "PixelCoordinate.h"
79
80#include <guunits/guunits.h>
81#include <gucoordinates/gucoordinates.h>
82
83namespace guWhiteboard {
84
89
90 private:
91
95 void init(struct wb_pixel_coordinate t_coordinate = wb_pixel_coordinate(), uint8_t t_camera = 1) {
96 set_coordinate(t_coordinate);
97 set_camera(t_camera);
98 }
99
100 public:
101
105 VisionFieldFeature(struct wb_pixel_coordinate t_coordinate = wb_pixel_coordinate(), uint8_t t_camera = 1) {
106 this->init(t_coordinate, t_camera);
107 }
108
113 this->init(t_other.coordinate(), t_other.camera());
114 }
115
120 this->init(t_other.coordinate, t_other.camera);
121 }
122
127 this->init(t_other.coordinate(), t_other.camera());
128 return *this;
129 }
130
135 this->init(t_other.coordinate, t_other.camera);
136 return *this;
137 }
138
139 bool operator ==(const VisionFieldFeature &t_other) const
140 {
142 && camera() == t_other.camera();
143 }
144
145 bool operator !=(const VisionFieldFeature &t_other) const
146 {
147 return !(*this == t_other);
148 }
149
150 bool operator ==(const wb_vision_field_feature &t_other) const
151 {
152 return *this == VisionFieldFeature(t_other);
153 }
154
155 bool operator !=(const wb_vision_field_feature &t_other) const
156 {
157 return !(*this == t_other);
158 }
159
161 {
162 return const_cast<PixelCoordinate &>(static_cast<const PixelCoordinate &>(wb_vision_field_feature::coordinate));
163 }
164
166 {
167 return static_cast<const PixelCoordinate &>(wb_vision_field_feature::coordinate);
168 }
169
170 void set_coordinate(const PixelCoordinate &t_newValue)
171 {
173 }
174
175 uint8_t & camera()
176 {
178 }
179
180 const uint8_t & camera() const
181 {
183 }
184
185 void set_camera(const uint8_t &t_newValue)
186 {
188 }
189
190#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
194 VisionFieldFeature(const std::string &t_str) {
195 this->init();
196 this->from_string(t_str);
197 }
198
199 std::string description() {
200#ifdef USE_WB_VISION_FIELD_FEATURE_C_CONVERSION
202 wb_vision_field_feature_description(this, buffer, sizeof(buffer));
203 std::string descr = buffer;
204 return descr;
205#else
206 std::ostringstream ss;
207 ss << "coordinate=" << "{" << PixelCoordinate(this->coordinate()).description() << "}";
208 ss << ", ";
209 ss << "camera=" << static_cast<unsigned>(this->camera());
210 return ss.str();
211#endif
212 }
213
214 std::string to_string() {
215#ifdef USE_WB_VISION_FIELD_FEATURE_C_CONVERSION
217 wb_vision_field_feature_to_string(this, buffer, sizeof(buffer));
218 std::string toString = buffer;
219 return toString;
220#else
221 std::ostringstream ss;
222 ss << "{" << PixelCoordinate(this->coordinate()).to_string() << "}";
223 ss << ", ";
224 ss << static_cast<unsigned>(this->camera());
225 return ss.str();
226#endif
227 }
228
229#ifdef USE_WB_VISION_FIELD_FEATURE_C_CONVERSION
230 void from_string(const std::string &t_str) {
231 wb_vision_field_feature_from_string(this, t_str.c_str());
232#else
233 void from_string(const std::string &t_str) {
234 char * str_cstr = const_cast<char *>(t_str.c_str());
235 size_t temp_length = strlen(str_cstr);
236 int length = (temp_length <= INT_MAX) ? static_cast<int>(static_cast<ssize_t>(temp_length)) : -1;
237 if (length < 1 || length > VISION_FIELD_FEATURE_DESC_BUFFER_SIZE) {
238 return;
239 }
240 char var_str_buffer[VISION_FIELD_FEATURE_DESC_BUFFER_SIZE + 1];
241 char* var_str = &var_str_buffer[0];
242 char key_buffer[11];
243 char* key = &key_buffer[0];
244 int bracecount = 0;
245 int startVar = 0;
246 int index = 0;
247 int startKey = 0;
248 int endKey = -1;
249 int varIndex = 0;
250 if (index == 0 && str_cstr[0] == '{') {
251 index = 1;
252 }
253 startVar = index;
254 startKey = startVar;
255 do {
256 for (int i = index; i < length; i++) {
257 index = i + 1;
258 if (bracecount == 0 && str_cstr[i] == '=') {
259 endKey = i - 1;
260 startVar = index;
261 continue;
262 }
263 if (bracecount == 0 && isspace(str_cstr[i])) {
264 startVar = index;
265 if (endKey == -1) {
266 startKey = index;
267 }
268 continue;
269 }
270 if (bracecount == 0 && str_cstr[i] == ',') {
271 index = i - 1;
272 break;
273 }
274 if (str_cstr[i] == '{') {
275 bracecount++;
276 continue;
277 }
278 if (str_cstr[i] == '}') {
279 bracecount--;
280 if (bracecount < 0) {
281 index = i - 1;
282 break;
283 }
284 }
285 if (i == length - 1) {
286 index = i;
287 }
288 }
289 if (endKey >= startKey && endKey - startKey < length) {
290 strncpy(key, str_cstr + startKey, static_cast<size_t>((endKey - startKey) + 1));
291 key[(endKey - startKey) + 1] = 0;
292 } else {
293 key[0] = 0;
294 }
295 strncpy(var_str, str_cstr + startVar, static_cast<size_t>((index - startVar) + 1));
296 var_str[(index - startVar) + 1] = 0;
297 bracecount = 0;
298 index += 2;
299 startVar = index;
300 startKey = startVar;
301 endKey = -1;
302 if (strlen(key) > 0) {
303 if (0 == strcmp("coordinate", key)) {
304 varIndex = 0;
305 } else if (0 == strcmp("camera", key)) {
306 varIndex = 1;
307 } else {
308 varIndex = -1;
309 }
310 }
311 switch (varIndex) {
312 case -1: { break; }
313 case 0:
314 {
315 PixelCoordinate coordinate_temp = PixelCoordinate();
316 coordinate_temp.from_string(var_str);
317 this->set_coordinate(coordinate_temp);
318 break;
319 }
320 case 1:
321 {
322 this->set_camera(static_cast<uint8_t>(atoi(var_str)));
323 break;
324 }
325 }
326 if (varIndex >= 0) {
327 varIndex++;
328 }
329 } while(index < length);
330#endif
331 }
332#endif
333
334 GU::PixelCoordinate coordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
335 {
336 return PixelCoordinate(coordinate()).pixelCoordinate(resWidth, resHeight);
337 }
338 };
339
340}
341
342#endif
Provides a C++ wrapper around wb_pixel_coordinate.
void from_string(const std::string &t_str)
GU::PixelCoordinate pixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
Provides a C++ wrapper around wb_vision_field_feature.
const PixelCoordinate & coordinate() const
GU::PixelCoordinate coordinatePixelCoordinate(const uint16_t resWidth, const uint16_t resHeight)
WHITEBOARD_POSTER_STRING_CONVERSION.
void from_string(const std::string &t_str)
VisionFieldFeature(const struct wb_vision_field_feature &t_other)
Copy Constructor.
bool operator==(const VisionFieldFeature &t_other) const
VisionFieldFeature(const VisionFieldFeature &t_other)
Copy Constructor.
VisionFieldFeature(const std::string &t_str)
String Constructor.
VisionFieldFeature(struct wb_pixel_coordinate t_coordinate=wb_pixel_coordinate(), uint8_t t_camera=1)
Create a new VisionFieldFeature.
bool operator!=(const VisionFieldFeature &t_other) const
VisionFieldFeature & operator=(const VisionFieldFeature &t_other)
Copy Assignment Operator.
void set_coordinate(const PixelCoordinate &t_newValue)
void set_camera(const uint8_t &t_newValue)
/file APM_Interface.h
WHITEBOARD_POSTER_STRING_CONVERSION.
WHITEBOARD_POSTER_STRING_CONVERSION.
struct wb_pixel_coordinate coordinate
The pixel coordinate.
uint8_t camera
camera it was seen on
const char * wb_vision_field_feature_to_string(const struct wb_vision_field_feature *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_vision_field_feature_description(const struct wb_vision_field_feature *self, char *descString, size_t bufferSize)
Convert to a description string.
struct wb_vision_field_feature * wb_vision_field_feature_from_string(struct wb_vision_field_feature *self, const char *str)
Convert from a string.
#define VISION_FIELD_FEATURE_TO_STRING_BUFFER_SIZE
#define VISION_FIELD_FEATURE_DESC_BUFFER_SIZE