gusimplewhiteboard
wb_filtered_arrayonedimobjects.c
Go to the documentation of this file.
1/*
2 * file wb_filtered_arrayonedimobjects.c
3 *
4 * This file was generated by classgenerator from Filtered_ArrayOneDimObjects.txt.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Vlad Estivill-Castro. 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 Vlad Estivill-Castro.
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 WHITEBOARD_POSTER_STRING_CONVERSION
61#define WHITEBOARD_POSTER_STRING_CONVERSION
62#endif // WHITEBOARD_POSTER_STRING_CONVERSION
63
65#include <stdio.h>
66#include <string.h>
67#include <stdlib.h>
68#include <ctype.h>
69#include <limits.h>
70
71/* Network byte order functions */
72#pragma clang diagnostic push
73#pragma clang diagnostic ignored "-Wunused-macros"
74#if defined(__linux)
75# include <endian.h>
76# include <byteswap.h>
77#elif defined(__APPLE__)
78# include <machine/endian.h> //Needed for __BYTE_ORDER
79# include <architecture/byte_order.h> //Needed for byte swap functions
80# define bswap_16(x) NXSwapShort(x)
81# define bswap_32(x) NXSwapInt(x)
82# define bswap_64(x) NXSwapLongLong(x)
83#elif defined(ESP8266)
84# define bswap_16(x) __builtin_bswap16(x)
85# define bswap_32(x) __builtin_bswap32(x)
86# define bswap_64(x) __builtin_bswap64(x)
87#else
88 //Manually define swap macros?
89#endif
90
91#if (!defined(__BYTE_ORDER) && !defined(__LITTLE_ENDIAN)) || (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN)
92# if !defined(htonll) && !defined(ntohll)
93# define htonll(x) bswap_64(x)
94# define ntohll(x) bswap_64(x)
95# endif
96# if !defined(htonl) && !defined(ntohl)
97# define htonl(x) bswap_32(x)
98# define ntohl(x) bswap_32(x)
99# endif
100# if !defined(htons) && !defined(ntohs)
101# define htons(x) bswap_16(x)
102# define ntohs(x) bswap_16(x)
103# endif
104#else
105# if !defined(htonll) && !defined(ntohll)
106# define htonll(x) (x)
107# define ntohll(x) (x)
108# endif
109# if !defined(htonl) && !defined(ntohl)
110# define htonl(x) (x)
111# define ntohl(x) (x)
112# endif
113# if !defined(htons) && !defined(ntohs)
114# define htons(x) (x)
115# define ntohs(x) (x)
116# endif
117#endif
118#pragma clang diagnostic pop
119
120
121
125const char* wb_filtered_arrayonedimobjects_description(const struct wb_filtered_arrayonedimobjects* self, char* descString, size_t bufferSize)
126{
127#pragma clang diagnostic push
128#pragma clang diagnostic ignored "-Wunused-variable"
129 size_t len = 0;
130 if (len >= bufferSize) {
131 return descString;
132 }
133 len = gu_strlcat(descString, "objects={", bufferSize);
134 for (int objects_index = 0; objects_index < FILTERED_ARRAYONEDIMOBJECTS_OBJECTS_ARRAY_SIZE; objects_index++) {
135 if (len >= bufferSize) {
136 return descString;
137 }
138 if (objects_index > 0) {
139 len = gu_strlcat(descString, ", ", bufferSize);
140 }
141 len = gu_strlcat(descString, "{", bufferSize);
142 if (len >= bufferSize) {
143 return descString;
144 }
145 char objects_1_buffer[FILTERED_VISION_OBJECT_DESC_BUFFER_SIZE];
146 char* objects_1_p = objects_1_buffer;
147 const char* objects_1_description = wb_filtered_vision_object_description(&self->objects[objects_index], objects_1_p, FILTERED_VISION_OBJECT_DESC_BUFFER_SIZE);
148 len = gu_strlcat(descString, objects_1_p, bufferSize);
149 if (len >= bufferSize) {
150 return descString;
151 }
152 len = gu_strlcat(descString, "}", bufferSize);
153 }
154 if (len >= bufferSize) {
155 return descString;
156 }
157 len = gu_strlcat(descString, "}", bufferSize);
158 return descString;
159#pragma clang diagnostic pop
160}
161
165const char* wb_filtered_arrayonedimobjects_to_string(const struct wb_filtered_arrayonedimobjects* self, char* toString, size_t bufferSize)
166{
167#pragma clang diagnostic push
168#pragma clang diagnostic ignored "-Wunused-variable"
169 size_t len = 0;
170 if (len >= bufferSize) {
171 return toString;
172 }
173 len = gu_strlcat(toString, "{", bufferSize);
174 for (int objects_index = 0; objects_index < FILTERED_ARRAYONEDIMOBJECTS_OBJECTS_ARRAY_SIZE; objects_index++) {
175 if (len >= bufferSize) {
176 return toString;
177 }
178 if (objects_index > 0) {
179 len = gu_strlcat(toString, ", ", bufferSize);
180 }
181 len = gu_strlcat(toString, "{", bufferSize);
182 if (len >= bufferSize) {
183 return toString;
184 }
186 char* objects_1_p = objects_1_buffer;
187 const char* objects_1_to_string = wb_filtered_vision_object_to_string(&self->objects[objects_index], objects_1_p, FILTERED_VISION_OBJECT_TO_STRING_BUFFER_SIZE);
188 len = gu_strlcat(toString, objects_1_p, bufferSize);
189 if (len >= bufferSize) {
190 return toString;
191 }
192 len = gu_strlcat(toString, "}", bufferSize);
193 }
194 if (len >= bufferSize) {
195 return toString;
196 }
197 len = gu_strlcat(toString, "}", bufferSize);
198 return toString;
199#pragma clang diagnostic pop
200}
201
206{
207 size_t temp_length = strlen(str);
208 int length = (temp_length <= INT_MAX) ? ((int)((ssize_t)temp_length)) : -1;
209 if (length < 1 || length > FILTERED_ARRAYONEDIMOBJECTS_DESC_BUFFER_SIZE) {
210 return self;
211 }
212 char var_str_buffer[FILTERED_ARRAYONEDIMOBJECTS_DESC_BUFFER_SIZE + 1];
213 char* var_str = &var_str_buffer[0];
214 char key_buffer[8];
215 char* key = &key_buffer[0];
216 int bracecount = 0;
217 int lastBrace = -1;
218 int startVar = 0;
219 int index = 0;
220 int startKey = 0;
221 int endKey = -1;
222 int varIndex = 0;
223 if (index == 0 && str[0] == '{') {
224 index = 1;
225 }
226 startVar = index;
227 startKey = startVar;
228 do {
229 for (int i = index; i < length; i++) {
230 index = i + 1;
231 if (bracecount == 0 && str[i] == '=') {
232 endKey = i - 1;
233 startVar = index;
234 continue;
235 }
236 if (bracecount == 0 && isspace(str[i])) {
237 startVar = index;
238 if (endKey == -1) {
239 startKey = index;
240 }
241 continue;
242 }
243 if (bracecount == 0 && str[i] == ',') {
244 index = i - 1;
245 break;
246 }
247 if (str[i] == '{') {
248 bracecount++;
249 if (bracecount == 1) {
250 lastBrace = i;
251 }
252 continue;
253 }
254 if (str[i] == '}') {
255 bracecount--;
256 if (bracecount < 0) {
257 index = i - 1;
258 break;
259 }
260 }
261 if (i == length - 1) {
262 index = i;
263 }
264 }
265 if (endKey >= startKey && endKey - startKey < length) {
266 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
267 key[(endKey - startKey) + 1] = 0;
268 } else {
269 key[0] = 0;
270 }
271 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
272 var_str[(index - startVar) + 1] = 0;
273 bracecount = 0;
274 index += 2;
275 startVar = index;
276 startKey = startVar;
277 endKey = -1;
278 if (strlen(key) > 0) {
279 if (0 == strcmp("objects", key)) {
280 varIndex = 0;
281 } else {
282 varIndex = -1;
283 }
284 }
285 switch (varIndex) {
286 case -1: { break; }
287 case 0:
288 {
289 int restartIndex = index;
290 index = lastBrace + 1;
291 startVar = index;
292 startKey = startVar;
293 endKey = -1;
294 bracecount = 0;
295 for (int objects_0_index = 0; objects_0_index < FILTERED_ARRAYONEDIMOBJECTS_OBJECTS_ARRAY_SIZE; objects_0_index++) {
296 for (int i = index; i < length; i++) {
297 index = i + 1;
298 if (bracecount == 0 && str[i] == '=') {
299 endKey = i - 1;
300 startVar = index;
301 continue;
302 }
303 if (bracecount == 0 && isspace(str[i])) {
304 startVar = index;
305 if (endKey == -1) {
306 startKey = index;
307 }
308 continue;
309 }
310 if (bracecount == 0 && str[i] == ',') {
311 index = i - 1;
312 break;
313 }
314 if (str[i] == '{') {
315 bracecount++;
316 continue;
317 }
318 if (str[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 + startKey, ((size_t)(endKey - startKey) + 1));
331 key[(endKey - startKey) + 1] = 0;
332 } else {
333 key[0] = 0;
334 }
335 strncpy(var_str, str + startVar, ((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 struct wb_filtered_vision_object objects_0 = {};
343 wb_filtered_vision_object_from_string(&objects_0, var_str);
344 self->objects[objects_0_index] = objects_0;
345 }
346 index = restartIndex;
347 break;
348 }
349 }
350 if (varIndex >= 0) {
351 varIndex++;
352 }
353 } while(index < length);
354 return self;
355}
356
357/*#ifdef WHITEBOARD_SERIALISATION*/
358
363{
364 uint16_t bit_offset = 0;
365 //Class generator does not support array network compression.
366 //Copying into the buffer, uncompressed
367 do { //limit declaration scope
368 uint32_t len = 4;
369 uint32_t bytes = len * sizeof(struct wb_filtered_vision_object);
370 const char *buf = (const char *)&self->objects[0];
371 uint32_t c;
372 int8_t b;
373 for (c = 0; c < bytes; c++) {
374 for (b = 7; b >= 0; b--) {
375 do {
376 uint16_t byte = bit_offset / 8;
377 uint16_t bit = 7 - (bit_offset % 8);
378 unsigned long newbit = !!((buf[c] >> b) & 1U);
379 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
380 bit_offset = bit_offset + 1;
381 } while(false);
382 }
383 }
384 } while(false);
385 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
386 (void)self;
387 (void)dst;
388 return bit_offset;
389}
390
395{
396 uint16_t bit_offset = 0;
397 //Class generator does not support array network compression.
398 //Copying into the buffer, uncompressed
399 do { //limit declaration scope
400 uint32_t len = 4;
401 uint32_t bytes = len * sizeof(struct wb_filtered_vision_object);
402 char *buf = (char *)malloc(bytes);
403 uint32_t c;
404 int8_t b;
405 for (c = 0; c < bytes; c++) {
406 for (b = 7; b >= 0; b--) {
407 do {
408 uint16_t byte = bit_offset / 8;
409 uint16_t bit = 7 - (bit_offset % 8);
410 char dataByte = src[byte];
411 unsigned char bitValue = (dataByte >> bit) & 1U;
412 buf[c] ^= (-bitValue ^ buf[c]) & (1UL << b);
413 bit_offset = bit_offset + 1;
414 } while(false);
415 }
416 }
417 memcpy(&dst->objects[0], &buf[0], bytes);
418 free(buf);
419 } while(false);
420 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
421 (void)src;
422 (void)dst;
423 return bit_offset;
424}
425
426/*#endif // WHITEBOARD_SERIALISATION*/
The class of landmarks filtered regarding goal sightings.
struct wb_filtered_vision_object objects[4]
the array containing various filtered parts of the goals reported by vision FVO_NUM_OBJECTS =4
WHITEBOARD_POSTER_STRING_CONVERSION.
size_t wb_filtered_arrayonedimobjects_from_network_serialised(const char *src, struct wb_filtered_arrayonedimobjects *dst)
Convert from a compressed, serialised, network byte order byte stream.
size_t wb_filtered_arrayonedimobjects_to_network_serialised(const struct wb_filtered_arrayonedimobjects *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
const char * wb_filtered_arrayonedimobjects_description(const struct wb_filtered_arrayonedimobjects *self, char *descString, size_t bufferSize)
Convert to a description string.
const char * wb_filtered_arrayonedimobjects_to_string(const struct wb_filtered_arrayonedimobjects *self, char *toString, size_t bufferSize)
Convert to a string.
struct wb_filtered_arrayonedimobjects * wb_filtered_arrayonedimobjects_from_string(struct wb_filtered_arrayonedimobjects *self, const char *str)
Convert from a string.
#define FILTERED_ARRAYONEDIMOBJECTS_DESC_BUFFER_SIZE
#define FILTERED_ARRAYONEDIMOBJECTS_OBJECTS_ARRAY_SIZE
WHITEBOARD_POSTER_STRING_CONVERSION.
const char * wb_filtered_vision_object_to_string(const struct wb_filtered_vision_object *self, char *toString, size_t bufferSize)
Convert to a string.
const char * wb_filtered_vision_object_description(const struct wb_filtered_vision_object *self, char *descString, size_t bufferSize)
Convert to a description string.
struct wb_filtered_vision_object * wb_filtered_vision_object_from_string(struct wb_filtered_vision_object *self, const char *str)
Convert from a string.
#define FILTERED_VISION_OBJECT_TO_STRING_BUFFER_SIZE
#define FILTERED_VISION_OBJECT_DESC_BUFFER_SIZE