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 __interface = fit.__interface;
77 __infol = fit.__infol;
78 if ( fit.__value_string ) {
79 __value_string = strdup(fit.__value_string);
81 __value_string = NULL;
89 if ( __value_string ) free(__value_string);
99 if ( __infol != NULL ) {
100 __infol = __infol->
next;
101 if ( __value_string ) free(__value_string);
102 __value_string = NULL;
129 for (
unsigned int j = 0; j < i; ++j) {
143 for (
unsigned int j = 0; j < i; ++j) {
157 return (__infol == fi.__infol);
168 return ! (*
this == fi);
178 if ( __infol == NULL ) {
181 return __infol->
value;
193 __interface = fi.__interface;
194 __infol = fi.__infol;
206 if ( __infol == NULL ) {
209 return __infol->
type;
220 if ( __infol == NULL ) {
223 switch (__infol->
type) {
238 default:
return "unknown";
250 if ( __infol == NULL ) {
264 if ( __infol == NULL ) {
267 return __infol->
name;
278 if ( __infol == NULL ) {
281 return __infol->
value;
292 if ( __infol == NULL ) {
308 if ( __infol == NULL ) {
311 if ( __value_string == NULL ) {
313 __infol->
length, 1, (
unsigned int)0xFFFFFFFF);
315 char *tmp1 = strdup(
"");
319 for (
size_t i = 0; i < __infol->
length; ++i) {
321 switch (__infol->
type) {
323 rv = asprintf(&tmp2,
"%s%s", tmp1, (((
bool *)__infol->
value)[i]) ?
"true" :
"false");
326 rv = asprintf(&tmp2,
"%s%i", tmp1, ((int8_t *)__infol->
value)[i]);
329 rv = asprintf(&tmp2,
"%s%i", tmp1, ((int16_t *)__infol->
value)[i]);
332 rv = asprintf(&tmp2,
"%s%i", tmp1, ((int32_t *)__infol->
value)[i]);
335 #if (defined(__WORDSIZE) && __WORDSIZE == 64) || (defined(LONG_BIT) && LONG_BIT == 64) || defined(__x86_64__) 336 rv = asprintf(&tmp2,
"%s%li", tmp1, ((int64_t *)__infol->
value)[i]);
338 rv = asprintf(&tmp2,
"%s%lli", tmp1, ((int64_t *)__infol->
value)[i]);
342 rv = asprintf(&tmp2,
"%s%u", tmp1, ((uint8_t *)__infol->
value)[i]);
345 rv = asprintf(&tmp2,
"%s%u", tmp1, ((uint16_t *)__infol->
value)[i]);
348 rv = asprintf(&tmp2,
"%s%u", tmp1, ((uint32_t *)__infol->
value)[i]);
351 #if (defined(__WORDSIZE) && __WORDSIZE == 64) || (defined(LONG_BIT) && LONG_BIT == 64) || defined(__x86_64__) 352 rv = asprintf(&tmp2,
"%s%lu", tmp1, ((uint64_t *)__infol->
value)[i]);
354 rv = asprintf(&tmp2,
"%s%llu", tmp1, ((uint64_t *)__infol->
value)[i]);
358 rv = asprintf(&tmp2,
"%s%f", tmp1, ((
float *)__infol->
value)[i]);
361 rv = asprintf(&tmp2,
"%s%f", tmp1, ((
double *)__infol->
value)[i]);
364 rv = asprintf(&tmp2,
"%s%u", tmp1, ((uint8_t *)__infol->
value)[i]);
375 throw OutOfMemoryException(
"InterfaceFieldIterator::get_value_string(): asprintf() failed (1)");
380 if ( (__infol->
length > 1) && (i < __infol->length - 1) ) {
381 if (asprintf(&tmp2,
"%s%s", tmp1, array_sep) == -1) {
382 throw OutOfMemoryException(
"InterfaceFieldIterator::get_value_string(): asprintf() failed (2)");
389 __value_string = tmp1;
392 if ( __infol->
length > 1 ) {
393 if (asprintf(&__value_string,
"%s", (
const char *)__infol->
value) == -1) {
394 throw OutOfMemoryException(
"InterfaceFieldIterator::get_value_string(): asprintf() failed (3)");
397 if (asprintf(&__value_string,
"%c", *((
const char *)__infol->
value)) == -1) {
398 throw OutOfMemoryException(
"InterfaceFieldIterator::get_value_string(): asprintf() failed (4)");
403 return __value_string;
418 if ( __infol == NULL ) {
422 }
else if (index >= __infol->
length) {
425 return ((
bool *)__infol->
value)[index];
440 if ( __infol == NULL ) {
444 }
else if (index >= __infol->
length) {
447 return ((int8_t *)__infol->
value)[index];
462 if ( __infol == NULL ) {
466 }
else if (index >= __infol->
length) {
469 return ((uint8_t *)__infol->
value)[index];
483 if ( __infol == NULL ) {
487 }
else if (index >= __infol->
length) {
490 return ((int16_t *)__infol->
value)[index];
505 if ( __infol == NULL ) {
509 }
else if (index >= __infol->
length) {
512 return ((uint16_t *)__infol->
value)[index];
526 if ( __infol == NULL ) {
530 }
else if (index >= __infol->
length) {
533 return ((int32_t *)__infol->
value)[index];
548 if ( __infol == NULL ) {
552 }
else if (index >= __infol->
length) {
555 return ((uint32_t *)__infol->
value)[index];
569 if ( __infol == NULL ) {
573 }
else if (index >= __infol->
length) {
576 return ((int64_t *)__infol->
value)[index];
591 if ( __infol == NULL ) {
595 }
else if (index >= __infol->
length) {
598 return ((uint64_t *)__infol->
value)[index];
613 if ( __infol == NULL ) {
617 }
else if (index >= __infol->
length) {
620 return ((
float *)__infol->
value)[index];
635 if ( __infol == NULL ) {
639 }
else if (index >= __infol->
length) {
642 return ((
double *)__infol->
value)[index];
657 if ( __infol == NULL ) {
661 }
else if (index >= __infol->
length) {
664 return ((uint8_t *)__infol->
value)[index];
679 if ( __infol == NULL ) {
683 }
else if (index >= __infol->
length) {
686 return ((int32_t *)__infol->
value)[index];
703 if ( __infol == NULL ) {
707 }
else if (index >= __infol->
length) {
710 int32_t int_val = ((int32_t *)__infol->
value)[index];
711 interface_enum_map_t::const_iterator ev = __infol->
enum_map->find(int_val);
712 if (ev == __infol->
enum_map->end()) {
715 return ev->second.c_str();
728 if ( __infol == NULL ) {
732 }
else if (__infol->
length == 1) {
735 return (
bool *)__infol->
value;
749 if ( __infol == NULL ) {
754 return (int8_t *)__infol->
value;
768 if ( __infol == NULL ) {
773 return (uint8_t *)__infol->
value;
787 if ( __infol == NULL ) {
792 return (int16_t *)__infol->
value;
806 if ( __infol == NULL ) {
811 return (uint16_t *)__infol->
value;
825 if ( __infol == NULL ) {
830 return (int32_t *)__infol->
value;
844 if ( __infol == NULL ) {
849 return (uint32_t *)__infol->
value;
863 if ( __infol == NULL ) {
868 return (int64_t *)__infol->
value;
882 if ( __infol == NULL ) {
887 return (uint64_t *)__infol->
value;
901 if ( __infol == NULL ) {
906 return (
float *)__infol->
value;
920 if ( __infol == NULL ) {
925 return (
double *)__infol->
value;
939 if ( __infol == NULL ) {
944 return (uint8_t *)__infol->
value;
958 if ( __infol == NULL ) {
963 return (int32_t *)__infol->
value;
976 if ( __infol == NULL ) {
981 return (
const char *)__infol->
value;
996 if ( __infol == NULL ) {
1000 }
else if (index >= __infol->
length) {
1003 char* dst = (
char *) __infol->
value + index *
sizeof(
bool);
1004 memcpy((
void *) dst, &v,
sizeof(
bool));
1020 if ( __infol == NULL ) {
1024 }
else if (index >= __infol->
length) {
1027 char* dst = (
char *) __infol->
value + index *
sizeof(int8_t);
1028 memcpy((
void *) dst, &v,
sizeof(int8_t));
1044 if ( __infol == NULL ) {
1048 }
else if (index >= __infol->
length) {
1051 char* dst = (
char *) __infol->
value + index *
sizeof(uint8_t);
1052 memcpy((
void *) dst, &v,
sizeof(uint8_t));
1068 if ( __infol == NULL ) {
1072 }
else if (index >= __infol->
length) {
1075 char* dst = (
char *) __infol->
value + index *
sizeof(int16_t);
1076 memcpy((
void *) dst, &v,
sizeof(int16_t));
1092 if ( __infol == NULL ) {
1096 }
else if (index >= __infol->
length) {
1099 char* dst = (
char *) __infol->
value + index *
sizeof(uint16_t);
1100 memcpy((
void *) dst, &v,
sizeof(uint16_t));
1116 if ( __infol == NULL ) {
1120 }
else if (index >= __infol->
length) {
1123 char* dst = (
char *) __infol->
value + index *
sizeof(int32_t);
1124 memcpy((
void *) dst, &v,
sizeof(int32_t));
1140 if ( __infol == NULL ) {
1144 }
else if (index >= __infol->
length) {
1147 char* dst = (
char *) __infol->
value + index *
sizeof(uint32_t);
1148 memcpy((
void *) dst, &v,
sizeof(uint32_t));
1164 if ( __infol == NULL ) {
1168 }
else if (index >= __infol->
length) {
1171 char* dst = (
char *) __infol->
value + index *
sizeof(int64_t);
1172 memcpy((
void *) dst, &v,
sizeof(int64_t));
1188 if ( __infol == NULL ) {
1192 }
else if (index >= __infol->
length) {
1195 char* dst = (
char *) __infol->
value + index *
sizeof(uint64_t);
1196 memcpy((
void *) dst, &v,
sizeof(uint64_t));
1212 if ( __infol == NULL ) {
1216 }
else if (index >= __infol->
length) {
1219 char* dst = (
char *) __infol->
value + index *
sizeof(
float);
1220 memcpy((
void *) dst, &v,
sizeof(
float));
1236 if ( __infol == NULL ) {
1240 }
else if (index >= __infol->
length) {
1243 char* dst = (
char *) __infol->
value + index *
sizeof(
double);
1244 memcpy((
void *) dst, &v,
sizeof(
double));
1260 if ( __infol == NULL ) {
1264 }
else if (index >= __infol->
length) {
1267 char* dst = (
char *) __infol->
value + index *
sizeof(uint8_t);
1268 memcpy((
void *) dst, &v,
sizeof(uint8_t));
1283 if ( __infol == NULL ) {
1287 }
else if (index >= __infol->
length) {
1290 interface_enum_map_t::const_iterator ev = __infol->
enum_map->find(e);
1291 if (ev == __infol->
enum_map->end()) {
1294 char* dst = (
char *) __infol->
value + index *
sizeof(int32_t);
1295 memcpy((
void *) dst, &e,
sizeof(int32_t));
1311 if ( __infol == NULL ) {
1315 }
else if (index >= __infol->
length) {
1318 interface_enum_map_t::const_iterator ev;
1319 for (ev = __infol->
enum_map->begin(); ev != __infol->
enum_map->end(); ++ev) {
1320 if (ev->second == e) {
1321 char* dst = (
char *) __infol->
value + index *
sizeof(int32_t);
1322 memcpy((
void *) dst, &ev->first,
sizeof(int32_t));
1342 if ( __infol == NULL ) {
1346 }
else if (__infol->
length == 1) {
1349 memcpy(__infol->
value, v, __infol->
length *
sizeof(
bool));
1364 if ( __infol == NULL ) {
1368 }
else if (__infol->
length == 1) {
1371 memcpy(__infol->
value, v, __infol->
length *
sizeof(int8_t));
1386 if ( __infol == NULL ) {
1390 }
else if (__infol->
length == 1) {
1393 memcpy(__infol->
value, v, __infol->
length *
sizeof(uint8_t));
1408 if ( __infol == NULL ) {
1412 }
else if (__infol->
length == 1) {
1415 memcpy(__infol->
value, v, __infol->
length *
sizeof(int16_t));
1430 if ( __infol == NULL ) {
1434 }
else if (__infol->
length == 1) {
1437 memcpy(__infol->
value, v, __infol->
length *
sizeof(uint16_t));
1452 if ( __infol == NULL ) {
1456 }
else if (__infol->
length == 1) {
1459 memcpy(__infol->
value, v, __infol->
length *
sizeof(int32_t));
1474 if ( __infol == NULL ) {
1478 }
else if (__infol->
length == 1) {
1481 memcpy(__infol->
value, v, __infol->
length *
sizeof(uint32_t));
1496 if ( __infol == NULL ) {
1500 }
else if (__infol->
length == 1) {
1503 memcpy(__infol->
value, v, __infol->
length *
sizeof(int64_t));
1518 if ( __infol == NULL ) {
1522 }
else if (__infol->
length == 1) {
1525 memcpy(__infol->
value, v, __infol->
length *
sizeof(uint64_t));
1540 if ( __infol == NULL ) {
1544 }
else if (__infol->
length == 1) {
1547 memcpy(__infol->
value, v, __infol->
length *
sizeof(
float));
1561 if ( __infol == NULL ) {
1565 }
else if (__infol->
length == 1) {
1568 memcpy(__infol->
value, v, __infol->
length *
sizeof(
double));
1583 if ( __infol == NULL ) {
1587 }
else if (__infol->
length == 1) {
1590 memcpy(__infol->
value, v, __infol->
length *
sizeof(uint8_t));
1604 if ( __infol == NULL ) {
1609 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.
void set_int64s(int64_t *i)
Set value of current field as integer array.
uint8_t * get_bytes() const
Get value of current field as byte array.
uint16_t get_uint16(unsigned int index=0) const
Get value of current field as unsigned integer.
void set_bytes(uint8_t *b)
Set value of current field as byte array.
int32_t * get_enums() const
Get value of current enum field as integer 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.
int32_t get_enum(unsigned int index=0) const
Get value of current enum field as integer.
const char * get_typename() const
Get type of current field as string.
double get_double(unsigned int index=0) const
Get value of current field as double.
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.
uint16_t * get_uint16s() const
Get value of current field as unsigned integer array.
Fawkes library namespace.
bool get_bool(unsigned int index=0) const
Get value of current field as bool.
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.
float * get_floats() const
Get value of current field as float array.
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
interface_fieldtype_t get_type() const
Get type of current field.
~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.
const char * get_value_string(const char *array_sep=", ")
Get value of current field as string.
float get_float(unsigned int index=0) const
Get value of current field as float.
Base class for all Fawkes BlackBoard interfaces.
uint8_t get_byte(unsigned int index=0) const
Get value of current field as byte.
void set_int32(int32_t i, unsigned int index=0)
Set value of current field as integer.
void * value
Current value of this field.
int16_t get_int16(unsigned int index=0) const
Get value of current field as integer.
bool operator==(const InterfaceFieldIterator &fit) const
Check iterators for equality.
void set_doubles(double *f)
Set value of current field as double array.
const interface_enum_map_t * enum_map
Map of possible enum values.
void set_double(double f, unsigned int index=0)
Set value of current field as double.
int64_t * get_int64s() const
Get value of current field as integer array.
uint8_t * get_uint8s() const
Get value of current field as unsigned integer array.
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.
const char * get_name() const
Get name of current field.
void set_byte(uint8_t b, unsigned int index=0)
Set value of current field as byte.
const void * operator*() const
Get FieldHeader.
InterfaceFieldIterator & operator++()
Prefix increment.
uint8_t get_uint8(unsigned int index=0) const
Get value of current field as unsigned integer.
interface_fieldtype_t type
type of this field
double * get_doubles() const
Get value of current field as double array.
InterfaceFieldIterator & operator+=(unsigned int i)
Advance by i steps.
void set_string(const char *s)
Set value of current field as string.
uint64_t get_uint64(unsigned int index=0) const
Get value of current field as unsigned integer.
64 bit unsigned integer field
void set_uint16s(uint16_t *i)
Set value of current field as unsigned integer array.
const char * get_enum_string(unsigned int index=0) const
Get value of current enum field as string.
const char * get_string() const
Get value of current field as string.
size_t length
Length of field (array, string)
uint64_t * get_uint64s() const
Get value of current field as unsigned integer array.
void set_uint32(uint32_t i, unsigned int index=0)
Set value of current field as unsigned integer.
uint32_t get_uint32(unsigned int index=0) const
Get value of current field as unsigned integer.
bool * get_bools() const
Get value of current field as bool array.
size_t get_length() const
Get length of current field.
bool is_enum() const
Check if field is an enum.
void set_enum(int32_t e, unsigned int index=0)
Set value of current field as enum (from an integer).
virtual const char * enum_tostring(const char *enumtype, int val) const =0
Convert arbitrary enum value to string.
uint32_t * get_uint32s() const
Get value of current field as unsigned integer array.
void set_int32s(int32_t *i)
Set value of current field as integer array.
const char * enumtype
text representation of enum type
void set_int8s(int8_t *i)
Set value of current field as integer array.
void set_enum_string(const char *e, unsigned int index=0)
Set value of current field as enum (from an integer).
int32_t * get_int32s() const
Get 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.
bool operator!=(const InterfaceFieldIterator &fit) const
Check iterators for inequality.
Expected parameter is missing.
void set_uint32s(uint32_t *i)
Set value of current field as unsigned integer array.
int32_t get_int32(unsigned int index=0) const
Get value of current field as integer.
int16_t * get_int16s() const
Get value of current field as integer array.
interface_fieldtype_t
Interface field type.
const void * get_value() const
Get value of current field.
32 bit unsigned integer field
field with interface specific enum type
System ran out of memory and desired operation could not be fulfilled.
void mark_data_changed()
Mark data as changed.
int64_t get_int64(unsigned int index=0) const
Get value of current field as integer.