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