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