Fawkes API  Fawkes Development Version
field_iterator.cpp
1 
2 /***************************************************************************
3  * field_iterator.cpp - Iterate over field of an interface or a message
4  *
5  * Created: Fri Jul 17 21:28:58 2009
6  * Copyright 2006 Tim Niemueller [www.niemueller.de]
7  * 2009 Daniel Beck
8  *
9  ****************************************************************************/
10 
11 /* This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version. A runtime exception applies to
15  * this software (see LICENSE.GPL_WRE file mentioned below for details).
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Library General Public License for more details.
21  *
22  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
23  */
24 
25 #include <interface/field_iterator.h>
26 #include <interface/interface.h>
27 
28 #include <core/exceptions/software.h>
29 #include <core/exceptions/system.h>
30 
31 #include <cstdlib>
32 #include <cstring>
33 #include <cstdio>
34 
35 namespace fawkes {
36 
37 /** @class InterfaceFieldIterator <interface/interface.h>
38  * Interface field iterator.
39  * This iterator is part of the BlackBoard introspection API. It can be used to
40  * iterate over all available fields and values of an interface without actually
41  * knowing the specific type of the interface.
42  * @author Tim Niemueller
43  */
44 
45 
46 /** Constructor.
47  * Creates an invalid iterator.
48  */
50 {
51  __interface = NULL;
52  __infol = NULL;
53  __value_string = NULL;
54 }
55 
56 
57 /** Constructor.
58  * This creates an iterator pointing to the given entry of the info list.
59  * @param interface interface this field iterator is assigned to
60  * @param info_list pointer to info list entry to start from
61  */
63  const interface_fieldinfo_t *info_list)
64 {
65  __interface = interface;
66  __infol = info_list;
67  __value_string = NULL;
68 }
69 
70 
71 /** Copy constructor.
72  * @param fit iterator to copy
73  */
75 {
76  __interface = fit.__interface;
77  __infol = fit.__infol;
78  if ( fit.__value_string ) {
79  __value_string = strdup(fit.__value_string);
80  } else {
81  __value_string = NULL;
82  }
83 }
84 
85 
86 /** Destructor. */
88 {
89  if ( __value_string ) free(__value_string);
90 }
91 
92 
93 /** Prefix increment.
94  * @return reference to this instance
95  */
98 {
99  if ( __infol != NULL ) {
100  __infol = __infol->next;
101  if ( __value_string ) free(__value_string);
102  __value_string = NULL;
103  }
104 
105  return *this;
106 }
107 
108 
109 /** Postfix increment operator.
110  * @param inc ignored
111  * @return instance before advancing to the next shared memory segment
112  */
115 {
116  InterfaceFieldIterator rv(*this);
117  ++(*this);
118  return rv;
119 }
120 
121 
122 /** Advance by i steps.
123  * @param i number of (matching) segments to advance.
124  * @return reference to this after advancing
125  */
128 {
129  for (unsigned int j = 0; j < i; ++j) {
130  ++(*this);
131  }
132  return *this;
133 }
134 
135 
136 /** Advance by i steps.
137  * @param i number of (matching) segments to advance.
138  * @return reference to this after advancing
139  */
142 {
143  for (unsigned int j = 0; j < i; ++j) {
144  ++(*this);
145  }
146  return *this;
147 }
148 
149 
150 /** Check iterators for equality.
151  * @param fi iterator to compare to
152  * @return true if iterators point to the the same field, false otherwise
153  */
154 bool
156 {
157  return (__infol == fi.__infol);
158 }
159 
160 
161 /** Check iterators for inequality.
162  * @param fi iterator to compare to
163  * @return true if iteraters point to the different fields, false otherwise
164  */
165 bool
167 {
168  return ! (*this == fi);
169 }
170 
171 
172 /** Get FieldHeader.
173  * @return shared memory header
174  */
175 const void *
177 {
178  if ( __infol == NULL ) {
179  throw NullPointerException("Cannot get value of end element");
180  } else {
181  return __infol->value;
182  }
183 }
184 
185 
186 /** Make this instance point to the same segment as fi.
187  * @param fi field iterator to compare
188  * @return reference to this instance
189  */
192 {
193  __interface = fi.__interface;
194  __infol = fi.__infol;
195 
196  return *this;
197 }
198 
199 
200 /** Get type of current field.
201  * @return field type
202  */
205 {
206  if ( __infol == NULL ) {
207  throw NullPointerException("Cannot get type of end element");
208  } else {
209  return __infol->type;
210  }
211 }
212 
213 
214 /** Get type of current field as string.
215  * @return field type as string
216  */
217 const char *
219 {
220  if ( __infol == NULL ) {
221  throw NullPointerException("Cannot get type of end element");
222  } else {
223  switch (__infol->type) {
224  case IFT_BOOL: return "bool";
225  case IFT_INT8: return "int8";
226  case IFT_UINT8: return "uint8";
227  case IFT_INT16: return "int16";
228  case IFT_UINT16: return "uint16";
229  case IFT_INT32: return "int32";
230  case IFT_UINT32: return "uint32";
231  case IFT_INT64: return "int64";
232  case IFT_UINT64: return "uint64";
233  case IFT_FLOAT: return "float";
234  case IFT_DOUBLE: return "double";
235  case IFT_BYTE: return "byte";
236  case IFT_STRING: return "string";
237  case IFT_ENUM: return __infol->enumtype;
238  default: return "unknown";
239  }
240  }
241 }
242 
243 
244 /** Check if field is an enum.
245  * @return true if the value is an enum, false otherwise
246  */
247 bool
249 {
250  if ( __infol == NULL ) {
251  throw NullPointerException("Cannot get type of end element");
252  } else {
253  return __infol->type == IFT_ENUM;
254  }
255 }
256 
257 
258 /** Get name of current field.
259  * @return field name
260  */
261 const char *
263 {
264  if ( __infol == NULL ) {
265  throw NullPointerException("Cannot get name of end element");
266  } else {
267  return __infol->name;
268  }
269 }
270 
271 
272 /** Get value of current field.
273  * @return field value
274  */
275 const void *
277 {
278  if ( __infol == NULL ) {
279  throw NullPointerException("Cannot get value of end element");
280  } else {
281  return __infol->value;
282  }
283 }
284 
285 
286 /** Get length of current field.
287  * @return length of field
288  */
289 size_t
291 {
292  if ( __infol == NULL ) {
293  throw NullPointerException("Cannot get length of end element");
294  } else {
295  return __infol->length;
296  }
297 }
298 
299 
300 /** Get value of current field as string.
301  * @param array_sep in the case that the field is an array the given string is
302  * used to split the individual elements in the array string representation
303  * @return field value as string
304  */
305 const char *
307 {
308  if ( __infol == NULL ) {
309  throw NullPointerException("Cannot get value of end element");
310  } else {
311  if ( __value_string == NULL ) {
312  if ( __infol->length == 0 ) throw OutOfBoundsException("Field length out of bounds",
313  __infol->length, 1, (unsigned int)0xFFFFFFFF);
314 
315  char *tmp1 = strdup("");
316  char *tmp2;
317 
318  if ( __infol->type != IFT_STRING ) {
319  for (size_t i = 0; i < __infol->length; ++i) {
320  int rv = 0;
321  switch (__infol->type) {
322  case IFT_BOOL:
323  rv = asprintf(&tmp2, "%s%s", tmp1, (((bool *)__infol->value)[i]) ? "true" : "false");
324  break;
325  case IFT_INT8:
326  rv = asprintf(&tmp2, "%s%i", tmp1, ((int8_t *)__infol->value)[i]);
327  break;
328  case IFT_INT16:
329  rv = asprintf(&tmp2, "%s%i", tmp1, ((int16_t *)__infol->value)[i]);
330  break;
331  case IFT_INT32:
332  rv = asprintf(&tmp2, "%s%i", tmp1, ((int32_t *)__infol->value)[i]);
333  break;
334  case IFT_INT64:
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]);
337 #else
338  rv = asprintf(&tmp2, "%s%lli", tmp1, ((int64_t *)__infol->value)[i]);
339 #endif
340  break;
341  case IFT_UINT8:
342  rv = asprintf(&tmp2, "%s%u", tmp1, ((uint8_t *)__infol->value)[i]);
343  break;
344  case IFT_UINT16:
345  rv = asprintf(&tmp2, "%s%u", tmp1, ((uint16_t *)__infol->value)[i]);
346  break;
347  case IFT_UINT32:
348  rv = asprintf(&tmp2, "%s%u", tmp1, ((uint32_t *)__infol->value)[i]);
349  break;
350  case IFT_UINT64:
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]);
353 #else
354  rv = asprintf(&tmp2, "%s%llu", tmp1, ((uint64_t *)__infol->value)[i]);
355 #endif
356  break;
357  case IFT_FLOAT:
358  rv = asprintf(&tmp2, "%s%f", tmp1, ((float *)__infol->value)[i]);
359  break;
360  case IFT_DOUBLE:
361  rv = asprintf(&tmp2, "%s%f", tmp1, ((double *)__infol->value)[i]);
362  break;
363  case IFT_BYTE:
364  rv = asprintf(&tmp2, "%s%u", tmp1, ((uint8_t *)__infol->value)[i]);
365  break;
366  case IFT_STRING:
367  // cannot happen, caught with surrounding if statement
368 
369  case IFT_ENUM:
370  rv = asprintf(&tmp2, "%s%s", tmp1, __interface->enum_tostring(__infol->enumtype, ((int *)__infol->value)[i]));
371  break;
372  }
373 
374  if ( rv == -1 ) {
375  throw OutOfMemoryException("InterfaceFieldIterator::get_value_string(): asprintf() failed (1)");
376  }
377 
378  free(tmp1);
379  tmp1 = tmp2;
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)");
383  }
384  free(tmp1);
385  tmp1 = tmp2;
386  }
387  }
388 
389  __value_string = tmp1;
390  } else {
391  // it's a string, or a small number
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)");
395  }
396  } else {
397  if (asprintf(&__value_string, "%c", *((const char *)__infol->value)) == -1) {
398  throw OutOfMemoryException("InterfaceFieldIterator::get_value_string(): asprintf() failed (4)");
399  }
400  }
401  }
402  }
403  return __value_string;
404  }
405 }
406 
407 
408 /** Get value of current field as bool.
409  * @return field value
410  * @param index array index (only use if field is an array)
411  * @exception NullPointerException invalid iterator, possibly end iterator
412  * @exception TypeMismatchException thrown if field is not of type bool
413  * @exception OutOfBoundsException thrown if index is out of bounds
414  */
415 bool
416 InterfaceFieldIterator::get_bool(unsigned int index) const
417 {
418  if ( __infol == NULL ) {
419  throw NullPointerException("Cannot get value of end element");
420  } else if ( __infol->type != IFT_BOOL ) {
421  throw TypeMismatchException("Requested value is not of type bool");
422  } else if (index >= __infol->length) {
423  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
424  } else {
425  return ((bool *)__infol->value)[index];
426  }
427 }
428 
429 
430 /** Get value of current field as integer.
431  * @return field value
432  * @param index array index (only use if field is an array)
433  * @exception NullPointerException invalid iterator, possibly end iterator
434  * @exception TypeMismatchException thrown if field is not of type int
435  * @exception OutOfBoundsException thrown if index is out of bounds
436  */
437 int8_t
438 InterfaceFieldIterator::get_int8(unsigned int index) const
439 {
440  if ( __infol == NULL ) {
441  throw NullPointerException("Cannot get value of end element");
442  } else if ( __infol->type != IFT_INT8 ) {
443  throw TypeMismatchException("Requested value is not of type int");
444  } else if (index >= __infol->length) {
445  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
446  } else {
447  return ((int8_t *)__infol->value)[index];
448  }
449 }
450 
451 
452 /** Get value of current field as unsigned integer.
453  * @return field value
454  * @param index array index (only use if field is an array)
455  * @exception NullPointerException invalid iterator, possibly end iterator
456  * @exception TypeMismatchException thrown if field is not of type unsigned int
457  * @exception OutOfBoundsException thrown if index is out of bounds
458  */
459 uint8_t
460 InterfaceFieldIterator::get_uint8(unsigned int index) const
461 {
462  if ( __infol == NULL ) {
463  throw NullPointerException("Cannot get value of end element");
464  } else if ( __infol->type != IFT_UINT8 ) {
465  throw TypeMismatchException("Requested value is not of type unsigned int");
466  } else if (index >= __infol->length) {
467  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
468  } else {
469  return ((uint8_t *)__infol->value)[index];
470  }
471 }
472 
473 /** Get value of current field as integer.
474  * @return field value
475  * @param index array index (only use if field is an array)
476  * @exception NullPointerException invalid iterator, possibly end iterator
477  * @exception TypeMismatchException thrown if field is not of type int
478  * @exception OutOfBoundsException thrown if index is out of bounds
479  */
480 int16_t
481 InterfaceFieldIterator::get_int16(unsigned int index) const
482 {
483  if ( __infol == NULL ) {
484  throw NullPointerException("Cannot get value of end element");
485  } else if ( __infol->type != IFT_INT16 ) {
486  throw TypeMismatchException("Requested value is not of type int");
487  } else if (index >= __infol->length) {
488  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
489  } else {
490  return ((int16_t *)__infol->value)[index];
491  }
492 }
493 
494 
495 /** Get value of current field as unsigned integer.
496  * @return field value
497  * @param index array index (only use if field is an array)
498  * @exception NullPointerException invalid iterator, possibly end iterator
499  * @exception TypeMismatchException thrown if field is not of type unsigned int
500  * @exception OutOfBoundsException thrown if index is out of bounds
501  */
502 uint16_t
503 InterfaceFieldIterator::get_uint16(unsigned int index) const
504 {
505  if ( __infol == NULL ) {
506  throw NullPointerException("Cannot get value of end element");
507  } else if ( __infol->type != IFT_UINT16 ) {
508  throw TypeMismatchException("Requested value is not of type unsigned int");
509  } else if (index >= __infol->length) {
510  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
511  } else {
512  return ((uint16_t *)__infol->value)[index];
513  }
514 }
515 
516 /** Get value of current field as integer.
517  * @return field value
518  * @param index array index (only use if field is an array)
519  * @exception NullPointerException invalid iterator, possibly end iterator
520  * @exception TypeMismatchException thrown if field is not of type int
521  * @exception OutOfBoundsException thrown if index is out of bounds
522  */
523 int32_t
524 InterfaceFieldIterator::get_int32(unsigned int index) const
525 {
526  if ( __infol == NULL ) {
527  throw NullPointerException("Cannot get value of end element");
528  } else if ( __infol->type != IFT_INT32 ) {
529  throw TypeMismatchException("Requested value is not of type int");
530  } else if (index >= __infol->length) {
531  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
532  } else {
533  return ((int32_t *)__infol->value)[index];
534  }
535 }
536 
537 
538 /** Get value of current field as unsigned integer.
539  * @return field value
540  * @param index array index (only use if field is an array)
541  * @exception NullPointerException invalid iterator, possibly end iterator
542  * @exception TypeMismatchException thrown if field is not of type unsigned int
543  * @exception OutOfBoundsException thrown if index is out of bounds
544  */
545 uint32_t
546 InterfaceFieldIterator::get_uint32(unsigned int index) const
547 {
548  if ( __infol == NULL ) {
549  throw NullPointerException("Cannot get value of end element");
550  } else if ( __infol->type != IFT_UINT32 ) {
551  throw TypeMismatchException("Requested value is not of type unsigned int");
552  } else if (index >= __infol->length) {
553  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
554  } else {
555  return ((uint32_t *)__infol->value)[index];
556  }
557 }
558 
559 /** Get value of current field as integer.
560  * @return field value
561  * @param index array index (only use if field is an array)
562  * @exception NullPointerException invalid iterator, possibly end iterator
563  * @exception TypeMismatchException thrown if field is not of type int
564  * @exception OutOfBoundsException thrown if index is out of bounds
565  */
566 int64_t
567 InterfaceFieldIterator::get_int64(unsigned int index) const
568 {
569  if ( __infol == NULL ) {
570  throw NullPointerException("Cannot get value of end element");
571  } else if ( __infol->type != IFT_INT64 ) {
572  throw TypeMismatchException("Requested value is not of type int");
573  } else if (index >= __infol->length) {
574  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
575  } else {
576  return ((int64_t *)__infol->value)[index];
577  }
578 }
579 
580 
581 /** Get value of current field as unsigned integer.
582  * @return field value
583  * @param index array index (only use if field is an array)
584  * @exception NullPointerException invalid iterator, possibly end iterator
585  * @exception TypeMismatchException thrown if field is not of type unsigned int
586  * @exception OutOfBoundsException thrown if index is out of bounds
587  */
588 uint64_t
589 InterfaceFieldIterator::get_uint64(unsigned int index) const
590 {
591  if ( __infol == NULL ) {
592  throw NullPointerException("Cannot get value of end element");
593  } else if ( __infol->type != IFT_UINT64 ) {
594  throw TypeMismatchException("Requested value is not of type unsigned int");
595  } else if (index >= __infol->length) {
596  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
597  } else {
598  return ((uint64_t *)__infol->value)[index];
599  }
600 }
601 
602 
603 /** Get value of current field as float.
604  * @return field value
605  * @param index array index (only use if field is an array)
606  * @exception NullPointerException invalid iterator, possibly end iterator
607  * @exception TypeMismatchException thrown if field is not of type float
608  * @exception OutOfBoundsException thrown if index is out of bounds
609  */
610 float
611 InterfaceFieldIterator::get_float(unsigned int index) const
612 {
613  if ( __infol == NULL ) {
614  throw NullPointerException("Cannot get value of end element");
615  } else if ( __infol->type != IFT_FLOAT ) {
616  throw TypeMismatchException("Requested value is not of type float");
617  } else if (index >= __infol->length) {
618  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
619  } else {
620  return ((float *)__infol->value)[index];
621  }
622 }
623 
624 
625 /** Get value of current field as double.
626  * @return field value
627  * @param index array index (only use if field is an array)
628  * @exception NullPointerException invalid iterator, possibly end iterator
629  * @exception TypeMismatchException thrown if field is not of type float
630  * @exception OutOfBoundsException thrown if index is out of bounds
631  */
632 double
633 InterfaceFieldIterator::get_double(unsigned int index) const
634 {
635  if ( __infol == NULL ) {
636  throw NullPointerException("Cannot get value of end element");
637  } else if ( __infol->type != IFT_DOUBLE ) {
638  throw TypeMismatchException("Requested value is not of type double");
639  } else if (index >= __infol->length) {
640  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
641  } else {
642  return ((double *)__infol->value)[index];
643  }
644 }
645 
646 
647 /** Get value of current field as byte.
648  * @return field value
649  * @param index array index (only use if field is an array)
650  * @exception NullPointerException invalid iterator, possibly end iterator
651  * @exception TypeMismatchException thrown if field is not of type byte
652  * @exception OutOfBoundsException thrown if index is out of bounds
653  */
654 uint8_t
655 InterfaceFieldIterator::get_byte(unsigned int index) const
656 {
657  if ( __infol == NULL ) {
658  throw NullPointerException("Cannot get value of end element");
659  } else if ( __infol->type != IFT_BYTE ) {
660  throw TypeMismatchException("Requested value is not of type byte");
661  } else if (index >= __infol->length) {
662  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
663  } else {
664  return ((uint8_t *)__infol->value)[index];
665  }
666 }
667 
668 
669 /** Get value of current enum field as integer.
670  * @return field value
671  * @param index array index (only use if field is an array)
672  * @exception NullPointerException invalid iterator, possibly end iterator
673  * @exception TypeMismatchException thrown if field is not of type int
674  * @exception OutOfBoundsException thrown if index is out of bounds
675  */
676 int32_t
677 InterfaceFieldIterator::get_enum(unsigned int index) const
678 {
679  if ( __infol == NULL ) {
680  throw NullPointerException("Cannot get value of end element");
681  } else if ( __infol->type != IFT_ENUM ) {
682  throw TypeMismatchException("Requested value is not of type enum");
683  } else if (index >= __infol->length) {
684  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
685  } else {
686  return ((int32_t *)__infol->value)[index];
687  }
688 }
689 
690 
691 /** Get value of current enum field as string.
692  * @return field value as string
693  * @param index array index (only use if field is an array)
694  * @exception NullPointerException invalid iterator, possibly end iterator
695  * @exception TypeMismatchException thrown if field is not of type int
696  * @exception OutOfBoundsException thrown if index is out of bounds
697  * @exception IllegalArgumentException thrown if the value is set to an integer
698  * which is not represented by any of the canonical enum values
699  */
700 const char *
702 {
703  if ( __infol == NULL ) {
704  throw NullPointerException("Cannot get value of end element");
705  } else if ( __infol->type != IFT_ENUM ) {
706  throw TypeMismatchException("Requested value is not of type enum");
707  } else if (index >= __infol->length) {
708  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
709  } else {
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()) {
713  throw IllegalArgumentException("Integer value is not a canonical enum value");
714  }
715  return ev->second.c_str();
716  }
717 }
718 
719 /** Get value of current field as bool array.
720  * @return field value
721  * @exception NullPointerException invalid iterator, possibly end iterator
722  * @exception TypeMismatchException thrown if field is not of type bool or field
723  * is not an array (length is 1)
724  */
725 bool *
727 {
728  if ( __infol == NULL ) {
729  throw NullPointerException("Cannot get value of end element");
730  } else if ( __infol->type != IFT_BOOL ) {
731  throw TypeMismatchException("Requested value is not of type bool");
732  } else if (__infol->length == 1) {
733  throw TypeMismatchException("Field %s is not an array", __infol->name);
734  } else {
735  return (bool *)__infol->value;
736  }
737 }
738 
739 
740 /** Get value of current field as integer array.
741  * @return field value
742  * @exception NullPointerException invalid iterator, possibly end iterator
743  * @exception TypeMismatchException thrown if field is not of type int or field
744  * is not an array (length is 1)
745  */
746 int8_t *
748 {
749  if ( __infol == NULL ) {
750  throw NullPointerException("Cannot get value of end element");
751  } else if ( __infol->type != IFT_INT8 ) {
752  throw TypeMismatchException("Requested value is not of type int");
753  } else {
754  return (int8_t *)__infol->value;
755  }
756 }
757 
758 
759 /** Get value of current field as unsigned integer array.
760  * @return field value
761  * @exception NullPointerException invalid iterator, possibly end iterator
762  * @exception TypeMismatchException thrown if field is not of type unsigned int
763  * or field is not an array (length is 1)
764  */
765 uint8_t *
767 {
768  if ( __infol == NULL ) {
769  throw NullPointerException("Cannot get value of end element");
770  } else if ( __infol->type != IFT_UINT8 ) {
771  throw TypeMismatchException("Requested value is not of type unsigned int");
772  } else {
773  return (uint8_t *)__infol->value;
774  }
775 }
776 
777 
778 /** Get value of current field as integer array.
779  * @return field value
780  * @exception NullPointerException invalid iterator, possibly end iterator
781  * @exception TypeMismatchException thrown if field is not of type int or field
782  * is not an array (length is 1)
783  */
784 int16_t *
786 {
787  if ( __infol == NULL ) {
788  throw NullPointerException("Cannot get value of end element");
789  } else if ( __infol->type != IFT_INT16 ) {
790  throw TypeMismatchException("Requested value is not of type int");
791  } else {
792  return (int16_t *)__infol->value;
793  }
794 }
795 
796 
797 /** Get value of current field as unsigned integer array.
798  * @return field value
799  * @exception NullPointerException invalid iterator, possibly end iterator
800  * @exception TypeMismatchException thrown if field is not of type unsigned int
801  * or field is not an array (length is 1)
802  */
803 uint16_t *
805 {
806  if ( __infol == NULL ) {
807  throw NullPointerException("Cannot get value of end element");
808  } else if ( __infol->type != IFT_UINT16 ) {
809  throw TypeMismatchException("Requested value is not of type unsigned int");
810  } else {
811  return (uint16_t *)__infol->value;
812  }
813 }
814 
815 
816 /** Get value of current field as integer array.
817  * @return field value
818  * @exception NullPointerException invalid iterator, possibly end iterator
819  * @exception TypeMismatchException thrown if field is not of type int or field
820  * is not an array (length is 1)
821  */
822 int32_t *
824 {
825  if ( __infol == NULL ) {
826  throw NullPointerException("Cannot get value of end element");
827  } else if ( __infol->type != IFT_INT32 ) {
828  throw TypeMismatchException("Requested value is not of type int");
829  } else {
830  return (int32_t *)__infol->value;
831  }
832 }
833 
834 
835 /** Get value of current field as unsigned integer array.
836  * @return field value
837  * @exception NullPointerException invalid iterator, possibly end iterator
838  * @exception TypeMismatchException thrown if field is not of type unsigned int
839  * or field is not an array (length is 1)
840  */
841 uint32_t *
843 {
844  if ( __infol == NULL ) {
845  throw NullPointerException("Cannot get value of end element");
846  } else if ( __infol->type != IFT_UINT32 ) {
847  throw TypeMismatchException("Requested value is not of type unsigned int");
848  } else {
849  return (uint32_t *)__infol->value;
850  }
851 }
852 
853 
854 /** Get value of current field as integer array.
855  * @return field value
856  * @exception NullPointerException invalid iterator, possibly end iterator
857  * @exception TypeMismatchException thrown if field is not of type int or field
858  * is not an array (length is 1)
859  */
860 int64_t *
862 {
863  if ( __infol == NULL ) {
864  throw NullPointerException("Cannot get value of end element");
865  } else if ( __infol->type != IFT_INT64 ) {
866  throw TypeMismatchException("Requested value is not of type int");
867  } else {
868  return (int64_t *)__infol->value;
869  }
870 }
871 
872 
873 /** Get value of current field as unsigned integer array.
874  * @return field value
875  * @exception NullPointerException invalid iterator, possibly end iterator
876  * @exception TypeMismatchException thrown if field is not of type unsigned int
877  * or field is not an array (length is 1)
878  */
879 uint64_t *
881 {
882  if ( __infol == NULL ) {
883  throw NullPointerException("Cannot get value of end element");
884  } else if ( __infol->type != IFT_UINT64 ) {
885  throw TypeMismatchException("Requested value is not of type unsigned int");
886  } else {
887  return (uint64_t *)__infol->value;
888  }
889 }
890 
891 
892 /** Get value of current field as float array.
893  * @return field value
894  * @exception NullPointerException invalid iterator, possibly end iterator
895  * @exception TypeMismatchException thrown if field is not of type float or field
896  * is not an array (length is 1)
897  */
898 float *
900 {
901  if ( __infol == NULL ) {
902  throw NullPointerException("Cannot get value of end element");
903  } else if ( __infol->type != IFT_FLOAT ) {
904  throw TypeMismatchException("Requested value is not of type float");
905  } else {
906  return (float *)__infol->value;
907  }
908 }
909 
910 
911 /** Get value of current field as double array.
912  * @return field value
913  * @exception NullPointerException invalid iterator, possibly end iterator
914  * @exception TypeMismatchException thrown if field is not of type double or field
915  * is not an array (length is 1)
916  */
917 double *
919 {
920  if ( __infol == NULL ) {
921  throw NullPointerException("Cannot get value of end element");
922  } else if ( __infol->type != IFT_DOUBLE ) {
923  throw TypeMismatchException("Requested value is not of type double");
924  } else {
925  return (double *)__infol->value;
926  }
927 }
928 
929 
930 /** Get value of current field as byte array.
931  * @return field value
932  * @exception NullPointerException invalid iterator, possibly end iterator
933  * @exception TypeMismatchException thrown if field is not of type byte or field
934  * is not an array (length is 1)
935  */
936 uint8_t *
938 {
939  if ( __infol == NULL ) {
940  throw NullPointerException("Cannot get value of end element");
941  } else if ( __infol->type != IFT_BYTE ) {
942  throw TypeMismatchException("Requested value is not of type byte");
943  } else {
944  return (uint8_t *)__infol->value;
945  }
946 }
947 
948 
949 /** Get value of current enum field as integer array.
950  * @return field value
951  * @exception NullPointerException invalid iterator, possibly end iterator
952  * @exception TypeMismatchException thrown if field is not of type int or field
953  * is not an array (length is 1)
954  */
955 int32_t *
957 {
958  if ( __infol == NULL ) {
959  throw NullPointerException("Cannot get value of end element");
960  } else if ( __infol->type != IFT_ENUM ) {
961  throw TypeMismatchException("Requested value is not of type enum");
962  } else {
963  return (int32_t *)__infol->value;
964  }
965 }
966 
967 
968 /** Get value of current field as string.
969  * @return field value
970  * @exception NullPointerException invalid iterator, possibly end iterator
971  * @exception TypeMismatchException thrown if field is not of type string
972  */
973 const char *
975 {
976  if ( __infol == NULL ) {
977  throw NullPointerException("Cannot get value of end element");
978  } else if ( __infol->type != IFT_STRING ) {
979  throw TypeMismatchException("Requested value is not of type string");
980  } else {
981  return (const char *)__infol->value;
982  }
983 }
984 
985 
986 /** Set value of current field as bool.
987  * @param v the new value
988  * @param index array index (only use if field is an array)
989  * @exception NullPointerException invalid iterator, possibly end iterator
990  * @exception TypeMismatchException thrown if field is not of type bool
991  * @exception OutOfBoundsException thrown if index is out of bounds
992  */
993 void
994 InterfaceFieldIterator::set_bool(bool v, unsigned int index)
995 {
996  if ( __infol == NULL ) {
997  throw NullPointerException("Cannot set value of end element");
998  } else if ( __infol->type != IFT_BOOL ) {
999  throw TypeMismatchException("Field to be written is not of type bool");
1000  } else if (index >= __infol->length) {
1001  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1002  } else {
1003  char* dst = (char *) __infol->value + index * sizeof(bool);
1004  memcpy((void *) dst, &v, sizeof(bool));
1005  if (__interface) __interface->mark_data_changed();
1006  }
1007 }
1008 
1009 
1010 /** Set value of current field as integer.
1011  * @param v the new value
1012  * @param index array index (only use if field is an array)
1013  * @exception NullPointerException invalid iterator, possibly end iterator
1014  * @exception TypeMismatchException thrown if field is not of type int
1015  * @exception OutOfBoundsException thrown if index is out of bounds
1016  */
1017 void
1018 InterfaceFieldIterator::set_int8(int8_t v, unsigned int index)
1019 {
1020  if ( __infol == NULL ) {
1021  throw NullPointerException("Cannot set value of end element");
1022  } else if ( __infol->type != IFT_INT8 ) {
1023  throw TypeMismatchException("Field to be written is not of type int");
1024  } else if (index >= __infol->length) {
1025  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1026  } else {
1027  char* dst = (char *) __infol->value + index * sizeof(int8_t);
1028  memcpy((void *) dst, &v, sizeof(int8_t));
1029  if (__interface) __interface->mark_data_changed();
1030  }
1031 }
1032 
1033 
1034 /** Set value of current field as unsigned integer.
1035  * @param v the new value
1036  * @param index array index (only use if field is an array)
1037  * @exception NullPointerException invalid iterator, possibly end iterator
1038  * @exception TypeMismatchException thrown if field is not of type unsigned int
1039  * @exception OutOfBoundsException thrown if index is out of bounds
1040  */
1041 void
1042 InterfaceFieldIterator::set_uint8(uint8_t v, unsigned int index)
1043 {
1044  if ( __infol == NULL ) {
1045  throw NullPointerException("Cannot set value of end element");
1046  } else if ( __infol->type != IFT_UINT8 ) {
1047  throw TypeMismatchException("Field to be written is not of type unsigned int");
1048  } else if (index >= __infol->length) {
1049  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1050  } else {
1051  char* dst = (char *) __infol->value + index * sizeof(uint8_t);
1052  memcpy((void *) dst, &v, sizeof(uint8_t));
1053  if (__interface) __interface->mark_data_changed();
1054  }
1055 }
1056 
1057 
1058 /** Set value of current field as integer.
1059  * @param v the new value
1060  * @param index array index (only use if field is an array)
1061  * @exception NullPointerException invalid iterator, possibly end iterator
1062  * @exception TypeMismatchException thrown if field is not of type int
1063  * @exception OutOfBoundsException thrown if index is out of bounds
1064  */
1065 void
1066 InterfaceFieldIterator::set_int16(int16_t v, unsigned int index)
1067 {
1068  if ( __infol == NULL ) {
1069  throw NullPointerException("Cannot set value of end element");
1070  } else if ( __infol->type != IFT_INT16 ) {
1071  throw TypeMismatchException("Field to be written is not of type int");
1072  } else if (index >= __infol->length) {
1073  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1074  } else {
1075  char* dst = (char *) __infol->value + index * sizeof(int16_t);
1076  memcpy((void *) dst, &v, sizeof(int16_t));
1077  if (__interface) __interface->mark_data_changed();
1078  }
1079 }
1080 
1081 
1082 /** Set value of current field as unsigned integer.
1083  * @param v the new value
1084  * @param index array index (only use if field is an array)
1085  * @exception NullPointerException invalid iterator, possibly end iterator
1086  * @exception TypeMismatchException thrown if field is not of type unsigned int
1087  * @exception OutOfBoundsException thrown if index is out of bounds
1088  */
1089 void
1090 InterfaceFieldIterator::set_uint16(uint16_t v, unsigned int index)
1091 {
1092  if ( __infol == NULL ) {
1093  throw NullPointerException("Cannot set value of end element");
1094  } else if ( __infol->type != IFT_UINT16 ) {
1095  throw TypeMismatchException("Field to be written is not of type unsigned int");
1096  } else if (index >= __infol->length) {
1097  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1098  } else {
1099  char* dst = (char *) __infol->value + index * sizeof(uint16_t);
1100  memcpy((void *) dst, &v, sizeof(uint16_t));
1101  if (__interface) __interface->mark_data_changed();
1102  }
1103 }
1104 
1105 
1106 /** Set value of current field as integer.
1107  * @param v the new value
1108  * @param index array index (only use if field is an array)
1109  * @exception NullPointerException invalid iterator, possibly end iterator
1110  * @exception TypeMismatchException thrown if field is not of type int
1111  * @exception OutOfBoundsException thrown if index is out of bounds
1112  */
1113 void
1114 InterfaceFieldIterator::set_int32(int32_t v, unsigned int index)
1115 {
1116  if ( __infol == NULL ) {
1117  throw NullPointerException("Cannot set value of end element");
1118  } else if ( __infol->type != IFT_INT32 ) {
1119  throw TypeMismatchException("Field to be written is not of type int");
1120  } else if (index >= __infol->length) {
1121  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1122  } else {
1123  char* dst = (char *) __infol->value + index * sizeof(int32_t);
1124  memcpy((void *) dst, &v, sizeof(int32_t));
1125  if (__interface) __interface->mark_data_changed();
1126  }
1127 }
1128 
1129 
1130 /** Set value of current field as unsigned integer.
1131  * @param v the new value
1132  * @param index array index (only use if field is an array)
1133  * @exception NullPointerException invalid iterator, possibly end iterator
1134  * @exception TypeMismatchException thrown if field is not of type unsigned int
1135  * @exception OutOfBoundsException thrown if index is out of bounds
1136  */
1137 void
1138 InterfaceFieldIterator::set_uint32(uint32_t v, unsigned int index)
1139 {
1140  if ( __infol == NULL ) {
1141  throw NullPointerException("Cannot set value of end element");
1142  } else if ( __infol->type != IFT_UINT32 ) {
1143  throw TypeMismatchException("Field to be written is not of type unsigned int");
1144  } else if (index >= __infol->length) {
1145  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1146  } else {
1147  char* dst = (char *) __infol->value + index * sizeof(uint32_t);
1148  memcpy((void *) dst, &v, sizeof(uint32_t));
1149  if (__interface) __interface->mark_data_changed();
1150  }
1151 }
1152 
1153 
1154 /** Set value of current field as integer.
1155  * @param v the new value
1156  * @param index array index (only use if field is an array)
1157  * @exception NullPointerException invalid iterator, possibly end iterator
1158  * @exception TypeMismatchException thrown if field is not of type int
1159  * @exception OutOfBoundsException thrown if index is out of bounds
1160  */
1161 void
1162 InterfaceFieldIterator::set_int64(int64_t v, unsigned int index)
1163 {
1164  if ( __infol == NULL ) {
1165  throw NullPointerException("Cannot set value of end element");
1166  } else if ( __infol->type != IFT_INT64 ) {
1167  throw TypeMismatchException("Field to be written is not of type int");
1168  } else if (index >= __infol->length) {
1169  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1170  } else {
1171  char* dst = (char *) __infol->value + index * sizeof(int64_t);
1172  memcpy((void *) dst, &v, sizeof(int64_t));
1173  if (__interface) __interface->mark_data_changed();
1174  }
1175 }
1176 
1177 
1178 /** Set value of current field as unsigned integer.
1179  * @param v the new value
1180  * @param index array index (only use if field is an array)
1181  * @exception NullPointerException invalid iterator, possibly end iterator
1182  * @exception TypeMismatchException thrown if field is not of type unsigned int
1183  * @exception OutOfBoundsException thrown if index is out of bounds
1184  */
1185 void
1186 InterfaceFieldIterator::set_uint64(uint64_t v, unsigned int index)
1187 {
1188  if ( __infol == NULL ) {
1189  throw NullPointerException("Cannot set value of end element");
1190  } else if ( __infol->type != IFT_UINT64 ) {
1191  throw TypeMismatchException("Field to be written is not of type unsigned int");
1192  } else if (index >= __infol->length) {
1193  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1194  } else {
1195  char* dst = (char *) __infol->value + index * sizeof(uint64_t);
1196  memcpy((void *) dst, &v, sizeof(uint64_t));
1197  if (__interface) __interface->mark_data_changed();
1198  }
1199 }
1200 
1201 
1202 /** Set value of current field as float.
1203  * @param v the new value
1204  * @param index array index (only use if field is an array)
1205  * @exception NullPointerException invalid iterator, possibly end iterator
1206  * @exception TypeMismatchException thrown if field is not of type float
1207  * @exception OutOfBoundsException thrown if index is out of bounds
1208  */
1209 void
1210 InterfaceFieldIterator::set_float(float v, unsigned int index)
1211 {
1212  if ( __infol == NULL ) {
1213  throw NullPointerException("Cannot set value of end element");
1214  } else if ( __infol->type != IFT_FLOAT ) {
1215  throw TypeMismatchException("Field to be written is not of type float");
1216  } else if (index >= __infol->length) {
1217  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1218  } else {
1219  char* dst = (char *) __infol->value + index * sizeof(float);
1220  memcpy((void *) dst, &v, sizeof(float));
1221  if (__interface) __interface->mark_data_changed();
1222  }
1223 }
1224 
1225 
1226 /** Set value of current field as double.
1227  * @param v the new value
1228  * @param index array index (only use if field is an array)
1229  * @exception NullPointerException invalid iterator, possibly end iterator
1230  * @exception TypeMismatchException thrown if field is not of type double
1231  * @exception OutOfBoundsException thrown if index is out of bounds
1232  */
1233 void
1234 InterfaceFieldIterator::set_double(double v, unsigned int index)
1235 {
1236  if ( __infol == NULL ) {
1237  throw NullPointerException("Cannot set value of end element");
1238  } else if ( __infol->type != IFT_DOUBLE ) {
1239  throw TypeMismatchException("Field to be written is not of type double");
1240  } else if (index >= __infol->length) {
1241  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1242  } else {
1243  char* dst = (char *) __infol->value + index * sizeof(double);
1244  memcpy((void *) dst, &v, sizeof(double));
1245  if (__interface) __interface->mark_data_changed();
1246  }
1247 }
1248 
1249 
1250 /** Set value of current field as byte.
1251  * @param v the new value
1252  * @param index array index (only use if field is an array)
1253  * @exception NullPointerException invalid iterator, possibly end iterator
1254  * @exception TypeMismatchException thrown if field is not of type byte
1255  * @exception OutOfBoundsException thrown if index is out of bounds
1256  */
1257 void
1258 InterfaceFieldIterator::set_byte(uint8_t v, unsigned int index)
1259 {
1260  if ( __infol == NULL ) {
1261  throw NullPointerException("Cannot set value of end element");
1262  } else if ( __infol->type != IFT_BYTE ) {
1263  throw TypeMismatchException("Field to be written is not of type byte");
1264  } else if (index >= __infol->length) {
1265  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1266  } else {
1267  char* dst = (char *) __infol->value + index * sizeof(uint8_t);
1268  memcpy((void *) dst, &v, sizeof(uint8_t));
1269  if (__interface) __interface->mark_data_changed();
1270  }
1271 }
1272 
1273 /** Set value of current field as enum (from an integer).
1274  * @param e the new value
1275  * @param index array index (only use if field is an array)
1276  * @exception NullPointerException invalid iterator, possibly end iterator
1277  * @exception TypeMismatchException thrown if field is not of type int
1278  * @exception OutOfBoundsException thrown if index is out of bounds
1279  */
1280 void
1281 InterfaceFieldIterator::set_enum(int32_t e, unsigned int index)
1282 {
1283  if ( __infol == NULL ) {
1284  throw NullPointerException("Cannot set value of end element");
1285  } else if ( __infol->type != IFT_ENUM ) {
1286  throw TypeMismatchException("Field to be written is not of type enum");
1287  } else if (index >= __infol->length) {
1288  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1289  } else {
1290  interface_enum_map_t::const_iterator ev = __infol->enum_map->find(e);
1291  if (ev == __infol->enum_map->end()) {
1292  throw IllegalArgumentException("Integer value is not a canonical enum value");
1293  }
1294  char* dst = (char *) __infol->value + index * sizeof(int32_t);
1295  memcpy((void *) dst, &e, sizeof(int32_t));
1296  if (__interface) __interface->mark_data_changed();
1297  }
1298 }
1299 
1300 
1301 /** Set value of current field as enum (from an integer).
1302  * @param e the new value
1303  * @param index array index (only use if field is an array)
1304  * @exception NullPointerException invalid iterator, possibly end iterator
1305  * @exception TypeMismatchException thrown if field is not of type int
1306  * @exception OutOfBoundsException thrown if index is out of bounds
1307  */
1308 void
1309 InterfaceFieldIterator::set_enum_string(const char *e, unsigned int index)
1310 {
1311  if ( __infol == NULL ) {
1312  throw NullPointerException("Cannot set value of end element");
1313  } else if ( __infol->type != IFT_ENUM ) {
1314  throw TypeMismatchException("Field to be written is not of type enum");
1315  } else if (index >= __infol->length) {
1316  throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length);
1317  } else {
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));
1323  if (__interface) __interface->mark_data_changed();
1324  return;
1325  }
1326  }
1327  // else value was not found
1328  throw IllegalArgumentException("Integer value is not a canonical enum value");
1329  }
1330 }
1331 
1332 
1333 /** Set value of current field as bool array.
1334  * @param v an array of bools
1335  * @exception NullPointerException invalid iterator, possibly end iterator
1336  * @exception TypeMismatchException thrown if field is not of type bool or field
1337  * is not an array (length is 1)
1338  */
1339 void
1341 {
1342  if ( __infol == NULL ) {
1343  throw NullPointerException("Cannot set value of end element");
1344  } else if ( __infol->type != IFT_BOOL ) {
1345  throw TypeMismatchException("Field to be written is not of type bool");
1346  } else if (__infol->length == 1) {
1347  throw TypeMismatchException("Field %s is not an array", __infol->name);
1348  } else {
1349  memcpy(__infol->value, v, __infol->length * sizeof(bool));
1350  if (__interface) __interface->mark_data_changed();
1351  }
1352 }
1353 
1354 
1355 /** Set value of current field as integer array.
1356  * @param v an array of ints
1357  * @exception NullPointerException invalid iterator, possibly end iterator
1358  * @exception TypeMismatchException thrown if field is not of type int or field
1359  * is not an array (length is 1)
1360  */
1361 void
1363 {
1364  if ( __infol == NULL ) {
1365  throw NullPointerException("Cannot set value of end element");
1366  } else if ( __infol->type != IFT_INT8 ) {
1367  throw TypeMismatchException("Field to be written is not of type int");
1368  } else if (__infol->length == 1) {
1369  throw TypeMismatchException("Field %s is not an array", __infol->name);
1370  } else {
1371  memcpy(__infol->value, v, __infol->length * sizeof(int8_t));
1372  if (__interface) __interface->mark_data_changed();
1373  }
1374 }
1375 
1376 
1377 /** Set value of current field as unsigned integer array.
1378  * @param v an array of unsigned ints
1379  * @exception NullPointerException invalid iterator, possibly end iterator
1380  * @exception TypeMismatchException thrown if field is not of type unsigned int or field
1381  * is not an array (length is 1)
1382  */
1383 void
1385 {
1386  if ( __infol == NULL ) {
1387  throw NullPointerException("Cannot set value of end element");
1388  } else if ( __infol->type != IFT_UINT8 ) {
1389  throw TypeMismatchException("Field to be written is not of type unsigned int");
1390  } else if (__infol->length == 1) {
1391  throw TypeMismatchException("Field %s is not an array", __infol->name);
1392  } else {
1393  memcpy(__infol->value, v, __infol->length * sizeof(uint8_t));
1394  if (__interface) __interface->mark_data_changed();
1395  }
1396 }
1397 
1398 
1399 /** Set value of current field as integer array.
1400  * @param v an array of ints
1401  * @exception NullPointerException invalid iterator, possibly end iterator
1402  * @exception TypeMismatchException thrown if field is not of type int or field
1403  * is not an array (length is 1)
1404  */
1405 void
1407 {
1408  if ( __infol == NULL ) {
1409  throw NullPointerException("Cannot set value of end element");
1410  } else if ( __infol->type != IFT_INT16 ) {
1411  throw TypeMismatchException("Field to be written is not of type int");
1412  } else if (__infol->length == 1) {
1413  throw TypeMismatchException("Field %s is not an array", __infol->name);
1414  } else {
1415  memcpy(__infol->value, v, __infol->length * sizeof(int16_t));
1416  if (__interface) __interface->mark_data_changed();
1417  }
1418 }
1419 
1420 
1421 /** Set value of current field as unsigned integer array.
1422  * @param v an array of unsigned ints
1423  * @exception NullPointerException invalid iterator, possibly end iterator
1424  * @exception TypeMismatchException thrown if field is not of type unsigned int or field
1425  * is not an array (length is 1)
1426  */
1427 void
1429 {
1430  if ( __infol == NULL ) {
1431  throw NullPointerException("Cannot set value of end element");
1432  } else if ( __infol->type != IFT_UINT16 ) {
1433  throw TypeMismatchException("Field to be written is not of type unsigned int");
1434  } else if (__infol->length == 1) {
1435  throw TypeMismatchException("Field %s is not an array", __infol->name);
1436  } else {
1437  memcpy(__infol->value, v, __infol->length * sizeof(uint16_t));
1438  if (__interface) __interface->mark_data_changed();
1439  }
1440 }
1441 
1442 
1443 /** Set value of current field as integer array.
1444  * @param v an array of ints
1445  * @exception NullPointerException invalid iterator, possibly end iterator
1446  * @exception TypeMismatchException thrown if field is not of type int or field
1447  * is not an array (length is 1)
1448  */
1449 void
1451 {
1452  if ( __infol == NULL ) {
1453  throw NullPointerException("Cannot set value of end element");
1454  } else if ( __infol->type != IFT_INT32 ) {
1455  throw TypeMismatchException("Field to be written is not of type int");
1456  } else if (__infol->length == 1) {
1457  throw TypeMismatchException("Field %s is not an array", __infol->name);
1458  } else {
1459  memcpy(__infol->value, v, __infol->length * sizeof(int32_t));
1460  if (__interface) __interface->mark_data_changed();
1461  }
1462 }
1463 
1464 
1465 /** Set value of current field as unsigned integer array.
1466  * @param v an array of unsigned ints
1467  * @exception NullPointerException invalid iterator, possibly end iterator
1468  * @exception TypeMismatchException thrown if field is not of type unsigned int or field
1469  * is not an array (length is 1)
1470  */
1471 void
1473 {
1474  if ( __infol == NULL ) {
1475  throw NullPointerException("Cannot set value of end element");
1476  } else if ( __infol->type != IFT_UINT32 ) {
1477  throw TypeMismatchException("Field to be written is not of type unsigned int");
1478  } else if (__infol->length == 1) {
1479  throw TypeMismatchException("Field %s is not an array", __infol->name);
1480  } else {
1481  memcpy(__infol->value, v, __infol->length * sizeof(uint32_t));
1482  if (__interface) __interface->mark_data_changed();
1483  }
1484 }
1485 
1486 
1487 /** Set value of current field as integer array.
1488  * @param v an array of ints
1489  * @exception NullPointerException invalid iterator, possibly end iterator
1490  * @exception TypeMismatchException thrown if field is not of type int or field
1491  * is not an array (length is 1)
1492  */
1493 void
1495 {
1496  if ( __infol == NULL ) {
1497  throw NullPointerException("Cannot set value of end element");
1498  } else if ( __infol->type != IFT_INT64 ) {
1499  throw TypeMismatchException("Field to be written is not of type int");
1500  } else if (__infol->length == 1) {
1501  throw TypeMismatchException("Field %s is not an array", __infol->name);
1502  } else {
1503  memcpy(__infol->value, v, __infol->length * sizeof(int64_t));
1504  if (__interface) __interface->mark_data_changed();
1505  }
1506 }
1507 
1508 
1509 /** Set value of current field as unsigned integer array.
1510  * @param v an array of unsigned ints
1511  * @exception NullPointerException invalid iterator, possibly end iterator
1512  * @exception TypeMismatchException thrown if field is not of type unsigned int or field
1513  * is not an array (length is 1)
1514  */
1515 void
1517 {
1518  if ( __infol == NULL ) {
1519  throw NullPointerException("Cannot set value of end element");
1520  } else if ( __infol->type != IFT_UINT64 ) {
1521  throw TypeMismatchException("Field to be written is not of type unsigned int");
1522  } else if (__infol->length == 1) {
1523  throw TypeMismatchException("Field %s is not an array", __infol->name);
1524  } else {
1525  memcpy(__infol->value, v, __infol->length * sizeof(uint64_t));
1526  if (__interface) __interface->mark_data_changed();
1527  }
1528 }
1529 
1530 
1531 /** Set value of current field as float array.
1532  * @param v an array of floats
1533  * @exception NullPointerException invalid iterator, possibly end iterator
1534  * @exception TypeMismatchException thrown if field is not of type float or field
1535  * is not an array (length is 1)
1536  */
1537 void
1539 {
1540  if ( __infol == NULL ) {
1541  throw NullPointerException("Cannot set value of end element");
1542  } else if ( __infol->type != IFT_FLOAT ) {
1543  throw TypeMismatchException("Field to be written is not of type float");
1544  } else if (__infol->length == 1) {
1545  throw TypeMismatchException("Field %s is not an array", __infol->name);
1546  } else {
1547  memcpy(__infol->value, v, __infol->length * sizeof(float));
1548  if (__interface) __interface->mark_data_changed();
1549  }
1550 }
1551 
1552 /** Set value of current field as double array.
1553  * @param v an array of doubles
1554  * @exception NullPointerException invalid iterator, possibly end iterator
1555  * @exception TypeMismatchException thrown if field is not of type double or field
1556  * is not an array (length is 1)
1557  */
1558 void
1560 {
1561  if ( __infol == NULL ) {
1562  throw NullPointerException("Cannot set value of end element");
1563  } else if ( __infol->type != IFT_DOUBLE ) {
1564  throw TypeMismatchException("Field to be written is not of type double");
1565  } else if (__infol->length == 1) {
1566  throw TypeMismatchException("Field %s is not an array", __infol->name);
1567  } else {
1568  memcpy(__infol->value, v, __infol->length * sizeof(double));
1569  if (__interface) __interface->mark_data_changed();
1570  }
1571 }
1572 
1573 
1574 /** Set value of current field as byte array.
1575  * @param v an array of bytes
1576  * @exception NullPointerException invalid iterator, possibly end iterator
1577  * @exception TypeMismatchException thrown if field is not of type byte or field
1578  * is not an array (length is 1)
1579  */
1580 void
1582 {
1583  if ( __infol == NULL ) {
1584  throw NullPointerException("Cannot set value of end element");
1585  } else if ( __infol->type != IFT_BYTE ) {
1586  throw TypeMismatchException("Field to be written is not of type byte");
1587  } else if (__infol->length == 1) {
1588  throw TypeMismatchException("Field %s is not an array", __infol->name);
1589  } else {
1590  memcpy(__infol->value, v, __infol->length * sizeof(uint8_t));
1591  if (__interface) __interface->mark_data_changed();
1592  }
1593 }
1594 
1595 
1596 /** Set value of current field as string.
1597  * @param v a string
1598  * @exception NullPointerException invalid iterator, possibly end iterator
1599  * @exception TypeMismatchException thrown if field is not of type string
1600  */
1601 void
1603 {
1604  if ( __infol == NULL ) {
1605  throw NullPointerException("Cannot set value of end element");
1606  } else if ( __infol->type != IFT_STRING ) {
1607  throw TypeMismatchException("Field to be written is not of type string");
1608  } else {
1609  strncpy((char *) __infol->value, v, __infol->length);
1610  if (__interface) __interface->mark_data_changed();
1611  }
1612 }
1613 
1614 } // end namespace fawkes
64 bit integer field
Definition: types.h:43
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.
Definition: types.h:56
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.
Definition: types.h:59
InterfaceFieldIterator & operator+(unsigned int i)
Advance by i steps.
8 bit unsigned integer field
Definition: types.h:38
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
Definition: types.h:40
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
Definition: types.h:63
interface_fieldtype_t get_type() const
Get type of current field.
void set_uint8(uint8_t i, unsigned int index=0)
Set value of current field as unsigned integer.
string field
Definition: types.h:47
byte field, alias for uint8
Definition: types.h:48
A NULL pointer was supplied where not allowed.
Definition: software.h:34
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.
Definition: interface.h:79
16 bit integer field
Definition: types.h:39
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.
Definition: types.h:61
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.
Definition: types.h:62
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
Definition: types.h:57
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
Definition: types.h:44
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)
Definition: types.h:60
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.
float field
Definition: types.h:45
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).
32 bit integer field
Definition: types.h:41
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
Definition: types.h:58
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.
Index out of bounds.
Definition: software.h:88
boolean field
Definition: types.h:36
Expected parameter is missing.
Definition: software.h:82
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.
Definition: types.h:35
const void * get_value() const
Get value of current field.
32 bit unsigned integer field
Definition: types.h:42
field with interface specific enum type
Definition: types.h:49
8 bit integer field
Definition: types.h:37
System ran out of memory and desired operation could not be fulfilled.
Definition: system.h:32
void mark_data_changed()
Mark data as changed.
Definition: interface.cpp:773
double field
Definition: types.h:46
int64_t get_int64(unsigned int index=0) const
Get value of current field as integer.