25 #include <interface/field_iterator.h>
26 #include <interface/interface.h>
28 #include <core/exceptions/software.h>
29 #include <core/exceptions/system.h>
53 __value_string = NULL;
65 __interface = interface;
67 __value_string = NULL;
76 __infol = fit.__infol;
77 if ( fit.__value_string ) {
78 __value_string = strdup(fit.__value_string);
80 __value_string = NULL;
88 if ( __value_string ) free(__value_string);
98 if ( __infol != NULL ) {
99 __infol = __infol->
next;
100 if ( __value_string ) free(__value_string);
101 __value_string = NULL;
128 for (
unsigned int j = 0; j < i; ++j) {
142 for (
unsigned int j = 0; j < i; ++j) {
156 return (__infol == fi.__infol);
167 return ! (*
this == fi);
177 if ( __infol == NULL ) {
180 return __infol->
value;
192 __interface = fi.__interface;
193 __infol = fi.__infol;
205 if ( __infol == NULL ) {
208 return __infol->
type;
219 if ( __infol == NULL ) {
222 switch (__infol->
type) {
237 default:
return "unknown";
249 if ( __infol == NULL ) {
252 return __infol->
name;
263 if ( __infol == NULL ) {
266 return __infol->
value;
277 if ( __infol == NULL ) {
291 if ( __infol == NULL ) {
294 if ( __value_string == NULL ) {
296 __infol->
length, 1, (
unsigned int)0xFFFFFFFF);
298 char *tmp1 = strdup(
"");
302 for (
size_t i = 0; i < __infol->
length; ++i) {
304 switch (__infol->
type) {
306 rv = asprintf(&tmp2,
"%s%s", tmp1, (((
bool *)__infol->
value)[i]) ?
"true" :
"false");
309 rv = asprintf(&tmp2,
"%s%i", tmp1, ((int8_t *)__infol->
value)[i]);
312 rv = asprintf(&tmp2,
"%s%i", tmp1, ((int16_t *)__infol->
value)[i]);
315 rv = asprintf(&tmp2,
"%s%i", tmp1, ((int32_t *)__infol->
value)[i]);
318 #if (defined(__WORDSIZE) && __WORDSIZE == 64) || (defined(LONG_BIT) && LONG_BIT == 64)
319 rv = asprintf(&tmp2,
"%s%li", tmp1, ((int64_t *)__infol->
value)[i]);
321 rv = asprintf(&tmp2,
"%s%lli", tmp1, ((int64_t *)__infol->
value)[i]);
325 rv = asprintf(&tmp2,
"%s%u", tmp1, ((uint8_t *)__infol->
value)[i]);
328 rv = asprintf(&tmp2,
"%s%u", tmp1, ((uint16_t *)__infol->
value)[i]);
331 rv = asprintf(&tmp2,
"%s%u", tmp1, ((uint32_t *)__infol->
value)[i]);
334 #if (defined(__WORDSIZE) && __WORDSIZE == 64) || (defined(LONG_BIT) && LONG_BIT == 64)
335 rv = asprintf(&tmp2,
"%s%lu", tmp1, ((uint64_t *)__infol->
value)[i]);
337 rv = asprintf(&tmp2,
"%s%llu", tmp1, ((uint64_t *)__infol->
value)[i]);
341 rv = asprintf(&tmp2,
"%s%f", tmp1, ((
float *)__infol->
value)[i]);
344 rv = asprintf(&tmp2,
"%s%f", tmp1, ((
double *)__infol->
value)[i]);
347 rv = asprintf(&tmp2,
"%s%u", tmp1, ((uint8_t *)__infol->
value)[i]);
358 throw OutOfMemoryException(
"InterfaceFieldIterator::get_value_string(): asprintf() failed (1)");
363 if ( (__infol->
length > 1) && (i < __infol->length - 1) ) {
364 if (asprintf(&tmp2,
"%s, ", tmp1) == -1) {
365 throw OutOfMemoryException(
"InterfaceFieldIterator::get_value_string(): asprintf() failed (2)");
372 __value_string = tmp1;
375 if ( __infol->
length > 1 ) {
376 if (asprintf(&__value_string,
"%s", (
const char *)__infol->
value) == -1) {
377 throw OutOfMemoryException(
"InterfaceFieldIterator::get_value_string(): asprintf() failed (3)");
380 if (asprintf(&__value_string,
"%c", *((
const char *)__infol->
value)) == -1) {
381 throw OutOfMemoryException(
"InterfaceFieldIterator::get_value_string(): asprintf() failed (4)");
386 return __value_string;
401 if ( __infol == NULL ) {
405 }
else if (index >= __infol->
length) {
408 return ((
bool *)__infol->
value)[index];
423 if ( __infol == NULL ) {
427 }
else if (index >= __infol->
length) {
430 return ((int8_t *)__infol->
value)[index];
445 if ( __infol == NULL ) {
449 }
else if (index >= __infol->
length) {
452 return ((uint8_t *)__infol->
value)[index];
466 if ( __infol == NULL ) {
470 }
else if (index >= __infol->
length) {
473 return ((int16_t *)__infol->
value)[index];
488 if ( __infol == NULL ) {
492 }
else if (index >= __infol->
length) {
495 return ((uint16_t *)__infol->
value)[index];
509 if ( __infol == NULL ) {
513 }
else if (index >= __infol->
length) {
516 return ((int32_t *)__infol->
value)[index];
531 if ( __infol == NULL ) {
535 }
else if (index >= __infol->
length) {
538 return ((uint32_t *)__infol->
value)[index];
552 if ( __infol == NULL ) {
556 }
else if (index >= __infol->
length) {
559 return ((int64_t *)__infol->
value)[index];
574 if ( __infol == NULL ) {
578 }
else if (index >= __infol->
length) {
581 return ((uint64_t *)__infol->
value)[index];
596 if ( __infol == NULL ) {
600 }
else if (index >= __infol->
length) {
603 return ((
float *)__infol->
value)[index];
618 if ( __infol == NULL ) {
622 }
else if (index >= __infol->
length) {
625 return ((
double *)__infol->
value)[index];
640 if ( __infol == NULL ) {
644 }
else if (index >= __infol->
length) {
647 return ((uint8_t *)__infol->
value)[index];
662 if ( __infol == NULL ) {
666 }
else if (index >= __infol->
length) {
669 return ((int32_t *)__infol->
value)[index];
682 if ( __infol == NULL ) {
686 }
else if (__infol->
length == 1) {
689 return (
bool *)__infol->
value;
703 if ( __infol == NULL ) {
708 return (int8_t *)__infol->
value;
722 if ( __infol == NULL ) {
727 return (uint8_t *)__infol->
value;
741 if ( __infol == NULL ) {
746 return (int16_t *)__infol->
value;
760 if ( __infol == NULL ) {
765 return (uint16_t *)__infol->
value;
779 if ( __infol == NULL ) {
784 return (int32_t *)__infol->
value;
798 if ( __infol == NULL ) {
803 return (uint32_t *)__infol->
value;
817 if ( __infol == NULL ) {
822 return (int64_t *)__infol->
value;
836 if ( __infol == NULL ) {
841 return (uint64_t *)__infol->
value;
855 if ( __infol == NULL ) {
860 return (
float *)__infol->
value;
874 if ( __infol == NULL ) {
879 return (
double *)__infol->
value;
893 if ( __infol == NULL ) {
898 return (uint8_t *)__infol->
value;
912 if ( __infol == NULL ) {
917 return (int32_t *)__infol->
value;
930 if ( __infol == NULL ) {
935 return (
const char *)__infol->
value;
950 if ( __infol == NULL ) {
954 }
else if (index >= __infol->
length) {
957 char* dst = (
char *) __infol->
value + index *
sizeof(
bool);
958 memcpy((
void *) dst, &v,
sizeof(
bool));
973 if ( __infol == NULL ) {
977 }
else if (index >= __infol->
length) {
980 char* dst = (
char *) __infol->
value + index *
sizeof(int8_t);
981 memcpy((
void *) dst, &v,
sizeof(int8_t));
996 if ( __infol == NULL ) {
1000 }
else if (index >= __infol->
length) {
1003 char* dst = (
char *) __infol->
value + index *
sizeof(uint8_t);
1004 memcpy((
void *) dst, &v,
sizeof(uint8_t));
1019 if ( __infol == NULL ) {
1023 }
else if (index >= __infol->
length) {
1026 char* dst = (
char *) __infol->
value + index *
sizeof(int16_t);
1027 memcpy((
void *) dst, &v,
sizeof(int16_t));
1042 if ( __infol == NULL ) {
1046 }
else if (index >= __infol->
length) {
1049 char* dst = (
char *) __infol->
value + index *
sizeof(uint16_t);
1050 memcpy((
void *) dst, &v,
sizeof(uint16_t));
1065 if ( __infol == NULL ) {
1069 }
else if (index >= __infol->
length) {
1072 char* dst = (
char *) __infol->
value + index *
sizeof(int32_t);
1073 memcpy((
void *) dst, &v,
sizeof(int32_t));
1088 if ( __infol == NULL ) {
1092 }
else if (index >= __infol->
length) {
1095 char* dst = (
char *) __infol->
value + index *
sizeof(uint32_t);
1096 memcpy((
void *) dst, &v,
sizeof(uint32_t));
1111 if ( __infol == NULL ) {
1115 }
else if (index >= __infol->
length) {
1118 char* dst = (
char *) __infol->
value + index *
sizeof(int64_t);
1119 memcpy((
void *) dst, &v,
sizeof(int64_t));
1134 if ( __infol == NULL ) {
1138 }
else if (index >= __infol->
length) {
1141 char* dst = (
char *) __infol->
value + index *
sizeof(uint64_t);
1142 memcpy((
void *) dst, &v,
sizeof(uint64_t));
1157 if ( __infol == NULL ) {
1161 }
else if (index >= __infol->
length) {
1164 char* dst = (
char *) __infol->
value + index *
sizeof(
float);
1165 memcpy((
void *) dst, &v,
sizeof(
float));
1180 if ( __infol == NULL ) {
1184 }
else if (index >= __infol->
length) {
1187 char* dst = (
char *) __infol->
value + index *
sizeof(
double);
1188 memcpy((
void *) dst, &v,
sizeof(
double));
1203 if ( __infol == NULL ) {
1207 }
else if (index >= __infol->
length) {
1210 char* dst = (
char *) __infol->
value + index *
sizeof(uint8_t);
1211 memcpy((
void *) dst, &v,
sizeof(uint8_t));
1225 if ( __infol == NULL ) {
1229 }
else if (__infol->
length == 1) {
1232 memcpy(__infol->
value, v, __infol->
length *
sizeof(
bool));
1246 if ( __infol == NULL ) {
1250 }
else if (__infol->
length == 1) {
1253 memcpy(__infol->
value, v, __infol->
length *
sizeof(int8_t));
1267 if ( __infol == NULL ) {
1271 }
else if (__infol->
length == 1) {
1274 memcpy(__infol->
value, v, __infol->
length *
sizeof(uint8_t));
1288 if ( __infol == NULL ) {
1292 }
else if (__infol->
length == 1) {
1295 memcpy(__infol->
value, v, __infol->
length *
sizeof(int16_t));
1309 if ( __infol == NULL ) {
1313 }
else if (__infol->
length == 1) {
1316 memcpy(__infol->
value, v, __infol->
length *
sizeof(uint16_t));
1330 if ( __infol == NULL ) {
1334 }
else if (__infol->
length == 1) {
1337 memcpy(__infol->
value, v, __infol->
length *
sizeof(int32_t));
1351 if ( __infol == NULL ) {
1355 }
else if (__infol->
length == 1) {
1358 memcpy(__infol->
value, v, __infol->
length *
sizeof(uint32_t));
1372 if ( __infol == NULL ) {
1376 }
else if (__infol->
length == 1) {
1379 memcpy(__infol->
value, v, __infol->
length *
sizeof(int64_t));
1393 if ( __infol == NULL ) {
1397 }
else if (__infol->
length == 1) {
1400 memcpy(__infol->
value, v, __infol->
length *
sizeof(uint64_t));
1414 if ( __infol == NULL ) {
1418 }
else if (__infol->
length == 1) {
1421 memcpy(__infol->
value, v, __infol->
length *
sizeof(
float));
1434 if ( __infol == NULL ) {
1438 }
else if (__infol->
length == 1) {
1441 memcpy(__infol->
value, v, __infol->
length *
sizeof(
double));
1455 if ( __infol == NULL ) {
1459 }
else if (__infol->
length == 1) {
1462 memcpy(__infol->
value, v, __infol->
length *
sizeof(uint8_t));
1475 if ( __infol == NULL ) {
1480 strncpy((
char *) __infol->
value, v, __infol->
length);
Interface field iterator.
void set_int64(int64_t i, unsigned int index=0)
Set value of current field as integer.
const char * get_value_string()
Get value of current field as string.
const char * get_string() const
Get value of current field as string.
int32_t * get_int32s() const
Get value of current field as integer array.
void set_int64s(int64_t *i)
Set value of current field as integer array.
float get_float(unsigned int index=0) const
Get value of current field as float.
void set_bytes(uint8_t *b)
Set value of current field as byte array.
void set_float(float f, unsigned int index=0)
Set value of current field as float.
void set_uint64s(uint64_t *i)
Set value of current field as unsigned integer array.
bool operator==(const InterfaceFieldIterator &fit) const
Check iterators for equality.
int32_t * get_enums() const
Get value of current enum field as integer array.
virtual const char * enum_tostring(const char *enumtype, int val) const =0
Convert arbitrary enum value to string.
void set_bool(bool b, unsigned int index=0)
Set value of current field as bool.
void set_bools(bool *b)
Set value of current field as bool array.
void set_int16(int16_t i, unsigned int index=0)
Set value of current field as integer.
InterfaceFieldIterator & operator=(const InterfaceFieldIterator &fit)
Make this instance point to the same segment as fi.
Interface field info list.
Fawkes library namespace.
const char * name
Name of this field.
InterfaceFieldIterator & operator+(unsigned int i)
Advance by i steps.
8 bit unsigned integer field
void set_uint16(uint16_t i, unsigned int index=0)
Set value of current field as unsigned integer.
const void * operator*() const
Get FieldHeader.
interface_fieldtype_t get_type() const
Get type of current field.
uint64_t get_uint64(unsigned int index=0) const
Get value of current field as unsigned integer.
16 bit unsigned integer field
void set_int8(int8_t i, unsigned int index=0)
Set value of current field as integer.
interface_fieldinfo_t * next
next field, NULL if last
uint8_t * get_uint8s() const
Get value of current field as unsigned integer array.
~InterfaceFieldIterator()
Destructor.
InterfaceFieldIterator()
Constructor.
void set_uint8(uint8_t i, unsigned int index=0)
Set value of current field as unsigned integer.
byte field, alias for uint8
A NULL pointer was supplied where not allowed.
uint8_t get_uint8(unsigned int index=0) const
Get value of current field as unsigned integer.
Base class for all Fawkes BlackBoard interfaces.
bool operator!=(const InterfaceFieldIterator &fit) const
Check iterators for inequality.
void set_int32(int32_t i, unsigned int index=0)
Set value of current field as integer.
double * get_doubles() const
Get value of current field as double array.
int16_t * get_int16s() const
Get value of current field as integer array.
void * value
Current value of this field.
uint32_t * get_uint32s() const
Get value of current field as unsigned integer array.
void set_doubles(double *f)
Set value of current field as double array.
void set_double(double f, unsigned int index=0)
Set value of current field as double.
int8_t get_int8(unsigned int index=0) const
Get value of current field as integer.
int8_t * get_int8s() const
Get value of current field as integer array.
uint64_t * get_uint64s() const
Get value of current field as unsigned integer array.
bool * get_bools() const
Get value of current field as bool array.
void set_byte(uint8_t b, unsigned int index=0)
Set value of current field as byte.
InterfaceFieldIterator & operator++()
Prefix increment.
uint8_t get_byte(unsigned int index=0) const
Get value of current field as byte.
float * get_floats() const
Get value of current field as float array.
bool get_bool(unsigned int index=0) const
Get value of current field as bool.
interface_fieldtype_t type
type of this field
InterfaceFieldIterator & operator+=(unsigned int i)
Advance by i steps.
void set_string(const char *s)
Set value of current field as string.
64 bit unsigned integer field
void set_uint16s(uint16_t *i)
Set value of current field as unsigned integer array.
size_t length
Length of field (array, string)
void set_uint32(uint32_t i, unsigned int index=0)
Set value of current field as unsigned integer.
double get_double(unsigned int index=0) const
Get value of current field as double.
const char * get_name() const
Get name of current field.
size_t get_length() const
Get length of current field.
void set_int32s(int32_t *i)
Set value of current field as integer array.
const void * get_value() const
Get value of current field.
const char * enumtype
text representation of enum type
uint16_t * get_uint16s() const
Get value of current field as unsigned integer array.
void set_int8s(int8_t *i)
Set value of current field as integer array.
void set_floats(float *f)
Set value of current field as float array.
void set_uint8s(uint8_t *i)
Set value of current field as unsigned integer array.
void set_int16s(int16_t *i)
Set value of current field as integer array.
void set_uint64(uint64_t i, unsigned int index=0)
Set value of current field as unsigned integer.
const char * get_typename() const
Get type of current field as string.
int16_t get_int16(unsigned int index=0) const
Get value of current field as integer.
void set_uint32s(uint32_t *i)
Set value of current field as unsigned integer array.
int32_t get_enum(unsigned int index=0) const
Get value of current enum field as integer.
interface_fieldtype_t
Interface field type.
uint32_t get_uint32(unsigned int index=0) const
Get value of current field as unsigned integer.
int32_t get_int32(unsigned int index=0) const
Get value of current field as integer.
32 bit unsigned integer field
int64_t get_int64(unsigned int index=0) const
Get value of current field as integer.
field with interface specific enum type
System ran out of memory and desired operation could not be fulfilled.
int64_t * get_int64s() const
Get value of current field as integer array.
uint16_t get_uint16(unsigned int index=0) const
Get value of current field as unsigned integer.
uint8_t * get_bytes() const
Get value of current field as byte array.