Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * field_iterator.cpp - Iterate over field of an interface or a message 00004 * 00005 * Created: Fri Jul 17 21:28:58 2009 00006 * Copyright 2006 Tim Niemueller [www.niemueller.de] 00007 * 2009 Daniel Beck 00008 * 00009 ****************************************************************************/ 00010 00011 /* This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License as published by 00013 * the Free Software Foundation; either version 2 of the License, or 00014 * (at your option) any later version. A runtime exception applies to 00015 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU Library General Public License for more details. 00021 * 00022 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00023 */ 00024 00025 #include <interface/field_iterator.h> 00026 #include <interface/interface.h> 00027 00028 #include <core/exceptions/software.h> 00029 #include <core/exceptions/system.h> 00030 00031 #include <cstdlib> 00032 #include <cstring> 00033 #include <cstdio> 00034 00035 namespace fawkes { 00036 00037 /** @class InterfaceFieldIterator <interface/interface.h> 00038 * Interface field iterator. 00039 * This iterator is part of the BlackBoard introspection API. It can be used to 00040 * iterate over all available fields and values of an interface without actually 00041 * knowing the specific type of the interface. 00042 * @author Tim Niemueller 00043 */ 00044 00045 00046 /** Constructor. 00047 * Creates an invalid iterator. 00048 */ 00049 InterfaceFieldIterator::InterfaceFieldIterator() 00050 { 00051 __interface = NULL; 00052 __infol = NULL; 00053 __value_string = NULL; 00054 } 00055 00056 00057 /** Constructor. 00058 * This creates an iterator pointing to the given entry of the info list. 00059 * @param interface interface this field iterator is assigned to 00060 * @param info_list pointer to info list entry to start from 00061 */ 00062 InterfaceFieldIterator::InterfaceFieldIterator(const Interface *interface, 00063 const interface_fieldinfo_t *info_list) 00064 { 00065 __interface = interface; 00066 __infol = info_list; 00067 __value_string = NULL; 00068 } 00069 00070 00071 /** Copy constructor. 00072 * @param fit iterator to copy 00073 */ 00074 InterfaceFieldIterator::InterfaceFieldIterator(const InterfaceFieldIterator &fit) 00075 { 00076 __infol = fit.__infol; 00077 if ( fit.__value_string ) { 00078 __value_string = strdup(fit.__value_string); 00079 } else { 00080 __value_string = NULL; 00081 } 00082 } 00083 00084 00085 /** Destructor. */ 00086 InterfaceFieldIterator::~InterfaceFieldIterator() 00087 { 00088 if ( __value_string ) free(__value_string); 00089 } 00090 00091 00092 /** Prefix increment. 00093 * @return reference to this instance 00094 */ 00095 InterfaceFieldIterator & 00096 InterfaceFieldIterator::operator++() 00097 { 00098 if ( __infol != NULL ) { 00099 __infol = __infol->next; 00100 if ( __value_string ) free(__value_string); 00101 __value_string = NULL; 00102 } 00103 00104 return *this; 00105 } 00106 00107 00108 /** Postfix increment operator. 00109 * @param inc ignored 00110 * @return instance before advancing to the next shared memory segment 00111 */ 00112 InterfaceFieldIterator 00113 InterfaceFieldIterator::operator++(int inc) 00114 { 00115 InterfaceFieldIterator rv(*this); 00116 ++(*this); 00117 return rv; 00118 } 00119 00120 00121 /** Advance by i steps. 00122 * @param i number of (matching) segments to advance. 00123 * @return reference to this after advancing 00124 */ 00125 InterfaceFieldIterator & 00126 InterfaceFieldIterator::operator+(unsigned int i) 00127 { 00128 for (unsigned int j = 0; j < i; ++j) { 00129 ++(*this); 00130 } 00131 return *this; 00132 } 00133 00134 00135 /** Advance by i steps. 00136 * @param i number of (matching) segments to advance. 00137 * @return reference to this after advancing 00138 */ 00139 InterfaceFieldIterator & 00140 InterfaceFieldIterator::operator+=(unsigned int i) 00141 { 00142 for (unsigned int j = 0; j < i; ++j) { 00143 ++(*this); 00144 } 00145 return *this; 00146 } 00147 00148 00149 /** Check iterators for equality. 00150 * @param fi iterator to compare to 00151 * @return true if iterators point to the the same field, false otherwise 00152 */ 00153 bool 00154 InterfaceFieldIterator::operator==(const InterfaceFieldIterator & fi) const 00155 { 00156 return (__infol == fi.__infol); 00157 } 00158 00159 00160 /** Check iterators for inequality. 00161 * @param fi iterator to compare to 00162 * @return true if iteraters point to the different fields, false otherwise 00163 */ 00164 bool 00165 InterfaceFieldIterator::operator!=(const InterfaceFieldIterator & fi) const 00166 { 00167 return ! (*this == fi); 00168 } 00169 00170 00171 /** Get FieldHeader. 00172 * @return shared memory header 00173 */ 00174 const void * 00175 InterfaceFieldIterator::operator*() const 00176 { 00177 if ( __infol == NULL ) { 00178 throw NullPointerException("Cannot get value of end element"); 00179 } else { 00180 return __infol->value; 00181 } 00182 } 00183 00184 00185 /** Make this instance point to the same segment as fi. 00186 * @param fi field iterator to compare 00187 * @return reference to this instance 00188 */ 00189 InterfaceFieldIterator & 00190 InterfaceFieldIterator::operator=(const InterfaceFieldIterator & fi) 00191 { 00192 __interface = fi.__interface; 00193 __infol = fi.__infol; 00194 00195 return *this; 00196 } 00197 00198 00199 /** Get type of current field. 00200 * @return field type 00201 */ 00202 interface_fieldtype_t 00203 InterfaceFieldIterator::get_type() const 00204 { 00205 if ( __infol == NULL ) { 00206 throw NullPointerException("Cannot get type of end element"); 00207 } else { 00208 return __infol->type; 00209 } 00210 } 00211 00212 00213 /** Get type of current field as string. 00214 * @return field type as string 00215 */ 00216 const char * 00217 InterfaceFieldIterator::get_typename() const 00218 { 00219 if ( __infol == NULL ) { 00220 throw NullPointerException("Cannot get type of end element"); 00221 } else { 00222 switch (__infol->type) { 00223 case IFT_BOOL: return "bool"; 00224 case IFT_INT8: return "int8"; 00225 case IFT_UINT8: return "uint8"; 00226 case IFT_INT16: return "int16"; 00227 case IFT_UINT16: return "uint16"; 00228 case IFT_INT32: return "int32"; 00229 case IFT_UINT32: return "uint32"; 00230 case IFT_INT64: return "int64"; 00231 case IFT_UINT64: return "uint64"; 00232 case IFT_FLOAT: return "float"; 00233 case IFT_DOUBLE: return "double"; 00234 case IFT_BYTE: return "byte"; 00235 case IFT_STRING: return "string"; 00236 case IFT_ENUM: return __infol->enumtype; 00237 default: return "unknown"; 00238 } 00239 } 00240 } 00241 00242 00243 /** Get name of current field. 00244 * @return field name 00245 */ 00246 const char * 00247 InterfaceFieldIterator::get_name() const 00248 { 00249 if ( __infol == NULL ) { 00250 throw NullPointerException("Cannot get name of end element"); 00251 } else { 00252 return __infol->name; 00253 } 00254 } 00255 00256 00257 /** Get value of current field. 00258 * @return field value 00259 */ 00260 const void * 00261 InterfaceFieldIterator::get_value() const 00262 { 00263 if ( __infol == NULL ) { 00264 throw NullPointerException("Cannot get value of end element"); 00265 } else { 00266 return __infol->value; 00267 } 00268 } 00269 00270 00271 /** Get length of current field. 00272 * @return length of field 00273 */ 00274 size_t 00275 InterfaceFieldIterator::get_length() const 00276 { 00277 if ( __infol == NULL ) { 00278 throw NullPointerException("Cannot get length of end element"); 00279 } else { 00280 return __infol->length; 00281 } 00282 } 00283 00284 00285 /** Get value of current field as string. 00286 * @return field value as string 00287 */ 00288 const char * 00289 InterfaceFieldIterator::get_value_string() 00290 { 00291 if ( __infol == NULL ) { 00292 throw NullPointerException("Cannot get value of end element"); 00293 } else { 00294 if ( __value_string == NULL ) { 00295 if ( __infol->length == 0 ) throw OutOfBoundsException("Field length out of bounds", 00296 __infol->length, 1, (unsigned int)0xFFFFFFFF); 00297 00298 char *tmp1 = strdup(""); 00299 char *tmp2; 00300 00301 if ( __infol->type != IFT_STRING ) { 00302 for (size_t i = 0; i < __infol->length; ++i) { 00303 int rv = 0; 00304 switch (__infol->type) { 00305 case IFT_BOOL: 00306 rv = asprintf(&tmp2, "%s%s", tmp1, (((bool *)__infol->value)[i]) ? "true" : "false"); 00307 break; 00308 case IFT_INT8: 00309 rv = asprintf(&tmp2, "%s%i", tmp1, ((int8_t *)__infol->value)[i]); 00310 break; 00311 case IFT_INT16: 00312 rv = asprintf(&tmp2, "%s%i", tmp1, ((int16_t *)__infol->value)[i]); 00313 break; 00314 case IFT_INT32: 00315 rv = asprintf(&tmp2, "%s%i", tmp1, ((int32_t *)__infol->value)[i]); 00316 break; 00317 case IFT_INT64: 00318 #if (defined(__WORDSIZE) && __WORDSIZE == 64) || (defined(LONG_BIT) && LONG_BIT == 64) 00319 rv = asprintf(&tmp2, "%s%li", tmp1, ((int64_t *)__infol->value)[i]); 00320 #else 00321 rv = asprintf(&tmp2, "%s%lli", tmp1, ((int64_t *)__infol->value)[i]); 00322 #endif 00323 break; 00324 case IFT_UINT8: 00325 rv = asprintf(&tmp2, "%s%u", tmp1, ((uint8_t *)__infol->value)[i]); 00326 break; 00327 case IFT_UINT16: 00328 rv = asprintf(&tmp2, "%s%u", tmp1, ((uint16_t *)__infol->value)[i]); 00329 break; 00330 case IFT_UINT32: 00331 rv = asprintf(&tmp2, "%s%u", tmp1, ((uint32_t *)__infol->value)[i]); 00332 break; 00333 case IFT_UINT64: 00334 #if (defined(__WORDSIZE) && __WORDSIZE == 64) || (defined(LONG_BIT) && LONG_BIT == 64) 00335 rv = asprintf(&tmp2, "%s%lu", tmp1, ((uint64_t *)__infol->value)[i]); 00336 #else 00337 rv = asprintf(&tmp2, "%s%llu", tmp1, ((uint64_t *)__infol->value)[i]); 00338 #endif 00339 break; 00340 case IFT_FLOAT: 00341 rv = asprintf(&tmp2, "%s%f", tmp1, ((float *)__infol->value)[i]); 00342 break; 00343 case IFT_DOUBLE: 00344 rv = asprintf(&tmp2, "%s%f", tmp1, ((double *)__infol->value)[i]); 00345 break; 00346 case IFT_BYTE: 00347 rv = asprintf(&tmp2, "%s%u", tmp1, ((uint8_t *)__infol->value)[i]); 00348 break; 00349 case IFT_STRING: 00350 // cannot happen, caught with surrounding if statement 00351 00352 case IFT_ENUM: 00353 rv = asprintf(&tmp2, "%s%s", tmp1, __interface->enum_tostring(__infol->enumtype, ((int *)__infol->value)[i])); 00354 break; 00355 } 00356 00357 if ( rv == -1 ) { 00358 throw OutOfMemoryException("InterfaceFieldIterator::get_value_string(): asprintf() failed (1)"); 00359 } 00360 00361 free(tmp1); 00362 tmp1 = tmp2; 00363 if ( (__infol->length > 1) && (i < __infol->length - 1) ) { 00364 if (asprintf(&tmp2, "%s, ", tmp1) == -1) { 00365 throw OutOfMemoryException("InterfaceFieldIterator::get_value_string(): asprintf() failed (2)"); 00366 } 00367 free(tmp1); 00368 tmp1 = tmp2; 00369 } 00370 } 00371 00372 __value_string = tmp1; 00373 } else { 00374 // it's a string, or a small number 00375 if ( __infol->length > 1 ) { 00376 if (asprintf(&__value_string, "%s", (const char *)__infol->value) == -1) { 00377 throw OutOfMemoryException("InterfaceFieldIterator::get_value_string(): asprintf() failed (3)"); 00378 } 00379 } else { 00380 if (asprintf(&__value_string, "%c", *((const char *)__infol->value)) == -1) { 00381 throw OutOfMemoryException("InterfaceFieldIterator::get_value_string(): asprintf() failed (4)"); 00382 } 00383 } 00384 } 00385 } 00386 return __value_string; 00387 } 00388 } 00389 00390 00391 /** Get value of current field as bool. 00392 * @return field value 00393 * @param index array index (only use if field is an array) 00394 * @exception NullPointerException invalid iterator, possibly end iterator 00395 * @exception TypeMismatchException thrown if field is not of type bool 00396 * @exception OutOfBoundsException thrown if index is out of bounds 00397 */ 00398 bool 00399 InterfaceFieldIterator::get_bool(unsigned int index) const 00400 { 00401 if ( __infol == NULL ) { 00402 throw NullPointerException("Cannot get value of end element"); 00403 } else if ( __infol->type != IFT_BOOL ) { 00404 throw TypeMismatchException("Requested value is not of type bool"); 00405 } else if (index >= __infol->length) { 00406 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00407 } else { 00408 return ((bool *)__infol->value)[index]; 00409 } 00410 } 00411 00412 00413 /** Get value of current field as integer. 00414 * @return field value 00415 * @param index array index (only use if field is an array) 00416 * @exception NullPointerException invalid iterator, possibly end iterator 00417 * @exception TypeMismatchException thrown if field is not of type int 00418 * @exception OutOfBoundsException thrown if index is out of bounds 00419 */ 00420 int8_t 00421 InterfaceFieldIterator::get_int8(unsigned int index) const 00422 { 00423 if ( __infol == NULL ) { 00424 throw NullPointerException("Cannot get value of end element"); 00425 } else if ( __infol->type != IFT_INT8 ) { 00426 throw TypeMismatchException("Requested value is not of type int"); 00427 } else if (index >= __infol->length) { 00428 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00429 } else { 00430 return ((int8_t *)__infol->value)[index]; 00431 } 00432 } 00433 00434 00435 /** Get value of current field as unsigned integer. 00436 * @return field value 00437 * @param index array index (only use if field is an array) 00438 * @exception NullPointerException invalid iterator, possibly end iterator 00439 * @exception TypeMismatchException thrown if field is not of type unsigned int 00440 * @exception OutOfBoundsException thrown if index is out of bounds 00441 */ 00442 uint8_t 00443 InterfaceFieldIterator::get_uint8(unsigned int index) const 00444 { 00445 if ( __infol == NULL ) { 00446 throw NullPointerException("Cannot get value of end element"); 00447 } else if ( __infol->type != IFT_UINT8 ) { 00448 throw TypeMismatchException("Requested value is not of type unsigned int"); 00449 } else if (index >= __infol->length) { 00450 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00451 } else { 00452 return ((uint8_t *)__infol->value)[index]; 00453 } 00454 } 00455 00456 /** Get value of current field as integer. 00457 * @return field value 00458 * @param index array index (only use if field is an array) 00459 * @exception NullPointerException invalid iterator, possibly end iterator 00460 * @exception TypeMismatchException thrown if field is not of type int 00461 * @exception OutOfBoundsException thrown if index is out of bounds 00462 */ 00463 int16_t 00464 InterfaceFieldIterator::get_int16(unsigned int index) const 00465 { 00466 if ( __infol == NULL ) { 00467 throw NullPointerException("Cannot get value of end element"); 00468 } else if ( __infol->type != IFT_INT16 ) { 00469 throw TypeMismatchException("Requested value is not of type int"); 00470 } else if (index >= __infol->length) { 00471 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00472 } else { 00473 return ((int16_t *)__infol->value)[index]; 00474 } 00475 } 00476 00477 00478 /** Get value of current field as unsigned integer. 00479 * @return field value 00480 * @param index array index (only use if field is an array) 00481 * @exception NullPointerException invalid iterator, possibly end iterator 00482 * @exception TypeMismatchException thrown if field is not of type unsigned int 00483 * @exception OutOfBoundsException thrown if index is out of bounds 00484 */ 00485 uint16_t 00486 InterfaceFieldIterator::get_uint16(unsigned int index) const 00487 { 00488 if ( __infol == NULL ) { 00489 throw NullPointerException("Cannot get value of end element"); 00490 } else if ( __infol->type != IFT_UINT16 ) { 00491 throw TypeMismatchException("Requested value is not of type unsigned int"); 00492 } else if (index >= __infol->length) { 00493 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00494 } else { 00495 return ((uint16_t *)__infol->value)[index]; 00496 } 00497 } 00498 00499 /** Get value of current field as integer. 00500 * @return field value 00501 * @param index array index (only use if field is an array) 00502 * @exception NullPointerException invalid iterator, possibly end iterator 00503 * @exception TypeMismatchException thrown if field is not of type int 00504 * @exception OutOfBoundsException thrown if index is out of bounds 00505 */ 00506 int32_t 00507 InterfaceFieldIterator::get_int32(unsigned int index) const 00508 { 00509 if ( __infol == NULL ) { 00510 throw NullPointerException("Cannot get value of end element"); 00511 } else if ( __infol->type != IFT_INT32 ) { 00512 throw TypeMismatchException("Requested value is not of type int"); 00513 } else if (index >= __infol->length) { 00514 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00515 } else { 00516 return ((int32_t *)__infol->value)[index]; 00517 } 00518 } 00519 00520 00521 /** Get value of current field as unsigned integer. 00522 * @return field value 00523 * @param index array index (only use if field is an array) 00524 * @exception NullPointerException invalid iterator, possibly end iterator 00525 * @exception TypeMismatchException thrown if field is not of type unsigned int 00526 * @exception OutOfBoundsException thrown if index is out of bounds 00527 */ 00528 uint32_t 00529 InterfaceFieldIterator::get_uint32(unsigned int index) const 00530 { 00531 if ( __infol == NULL ) { 00532 throw NullPointerException("Cannot get value of end element"); 00533 } else if ( __infol->type != IFT_UINT32 ) { 00534 throw TypeMismatchException("Requested value is not of type unsigned int"); 00535 } else if (index >= __infol->length) { 00536 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00537 } else { 00538 return ((uint32_t *)__infol->value)[index]; 00539 } 00540 } 00541 00542 /** Get value of current field as integer. 00543 * @return field value 00544 * @param index array index (only use if field is an array) 00545 * @exception NullPointerException invalid iterator, possibly end iterator 00546 * @exception TypeMismatchException thrown if field is not of type int 00547 * @exception OutOfBoundsException thrown if index is out of bounds 00548 */ 00549 int64_t 00550 InterfaceFieldIterator::get_int64(unsigned int index) const 00551 { 00552 if ( __infol == NULL ) { 00553 throw NullPointerException("Cannot get value of end element"); 00554 } else if ( __infol->type != IFT_INT64 ) { 00555 throw TypeMismatchException("Requested value is not of type int"); 00556 } else if (index >= __infol->length) { 00557 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00558 } else { 00559 return ((int64_t *)__infol->value)[index]; 00560 } 00561 } 00562 00563 00564 /** Get value of current field as unsigned integer. 00565 * @return field value 00566 * @param index array index (only use if field is an array) 00567 * @exception NullPointerException invalid iterator, possibly end iterator 00568 * @exception TypeMismatchException thrown if field is not of type unsigned int 00569 * @exception OutOfBoundsException thrown if index is out of bounds 00570 */ 00571 uint64_t 00572 InterfaceFieldIterator::get_uint64(unsigned int index) const 00573 { 00574 if ( __infol == NULL ) { 00575 throw NullPointerException("Cannot get value of end element"); 00576 } else if ( __infol->type != IFT_UINT64 ) { 00577 throw TypeMismatchException("Requested value is not of type unsigned int"); 00578 } else if (index >= __infol->length) { 00579 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00580 } else { 00581 return ((uint64_t *)__infol->value)[index]; 00582 } 00583 } 00584 00585 00586 /** Get value of current field as float. 00587 * @return field value 00588 * @param index array index (only use if field is an array) 00589 * @exception NullPointerException invalid iterator, possibly end iterator 00590 * @exception TypeMismatchException thrown if field is not of type float 00591 * @exception OutOfBoundsException thrown if index is out of bounds 00592 */ 00593 float 00594 InterfaceFieldIterator::get_float(unsigned int index) const 00595 { 00596 if ( __infol == NULL ) { 00597 throw NullPointerException("Cannot get value of end element"); 00598 } else if ( __infol->type != IFT_FLOAT ) { 00599 throw TypeMismatchException("Requested value is not of type float"); 00600 } else if (index >= __infol->length) { 00601 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00602 } else { 00603 return ((float *)__infol->value)[index]; 00604 } 00605 } 00606 00607 00608 /** Get value of current field as double. 00609 * @return field value 00610 * @param index array index (only use if field is an array) 00611 * @exception NullPointerException invalid iterator, possibly end iterator 00612 * @exception TypeMismatchException thrown if field is not of type float 00613 * @exception OutOfBoundsException thrown if index is out of bounds 00614 */ 00615 double 00616 InterfaceFieldIterator::get_double(unsigned int index) const 00617 { 00618 if ( __infol == NULL ) { 00619 throw NullPointerException("Cannot get value of end element"); 00620 } else if ( __infol->type != IFT_DOUBLE ) { 00621 throw TypeMismatchException("Requested value is not of type double"); 00622 } else if (index >= __infol->length) { 00623 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00624 } else { 00625 return ((double *)__infol->value)[index]; 00626 } 00627 } 00628 00629 00630 /** Get value of current field as byte. 00631 * @return field value 00632 * @param index array index (only use if field is an array) 00633 * @exception NullPointerException invalid iterator, possibly end iterator 00634 * @exception TypeMismatchException thrown if field is not of type byte 00635 * @exception OutOfBoundsException thrown if index is out of bounds 00636 */ 00637 uint8_t 00638 InterfaceFieldIterator::get_byte(unsigned int index) const 00639 { 00640 if ( __infol == NULL ) { 00641 throw NullPointerException("Cannot get value of end element"); 00642 } else if ( __infol->type != IFT_BYTE ) { 00643 throw TypeMismatchException("Requested value is not of type byte"); 00644 } else if (index >= __infol->length) { 00645 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00646 } else { 00647 return ((uint8_t *)__infol->value)[index]; 00648 } 00649 } 00650 00651 00652 /** Get value of current enum field as integer. 00653 * @return field value 00654 * @param index array index (only use if field is an array) 00655 * @exception NullPointerException invalid iterator, possibly end iterator 00656 * @exception TypeMismatchException thrown if field is not of type int 00657 * @exception OutOfBoundsException thrown if index is out of bounds 00658 */ 00659 int32_t 00660 InterfaceFieldIterator::get_enum(unsigned int index) const 00661 { 00662 if ( __infol == NULL ) { 00663 throw NullPointerException("Cannot get value of end element"); 00664 } else if ( __infol->type != IFT_ENUM ) { 00665 throw TypeMismatchException("Requested value is not of type enum"); 00666 } else if (index >= __infol->length) { 00667 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00668 } else { 00669 return ((int32_t *)__infol->value)[index]; 00670 } 00671 } 00672 00673 /** Get value of current field as bool array. 00674 * @return field value 00675 * @exception NullPointerException invalid iterator, possibly end iterator 00676 * @exception TypeMismatchException thrown if field is not of type bool or field 00677 * is not an array (length is 1) 00678 */ 00679 bool * 00680 InterfaceFieldIterator::get_bools() const 00681 { 00682 if ( __infol == NULL ) { 00683 throw NullPointerException("Cannot get value of end element"); 00684 } else if ( __infol->type != IFT_BOOL ) { 00685 throw TypeMismatchException("Requested value is not of type bool"); 00686 } else if (__infol->length == 1) { 00687 throw TypeMismatchException("Field %s is not an array", __infol->name); 00688 } else { 00689 return (bool *)__infol->value; 00690 } 00691 } 00692 00693 00694 /** Get value of current field as integer array. 00695 * @return field value 00696 * @exception NullPointerException invalid iterator, possibly end iterator 00697 * @exception TypeMismatchException thrown if field is not of type int or field 00698 * is not an array (length is 1) 00699 */ 00700 int8_t * 00701 InterfaceFieldIterator::get_int8s() const 00702 { 00703 if ( __infol == NULL ) { 00704 throw NullPointerException("Cannot get value of end element"); 00705 } else if ( __infol->type != IFT_INT8 ) { 00706 throw TypeMismatchException("Requested value is not of type int"); 00707 } else { 00708 return (int8_t *)__infol->value; 00709 } 00710 } 00711 00712 00713 /** Get value of current field as unsigned integer array. 00714 * @return field value 00715 * @exception NullPointerException invalid iterator, possibly end iterator 00716 * @exception TypeMismatchException thrown if field is not of type unsigned int 00717 * or field is not an array (length is 1) 00718 */ 00719 uint8_t * 00720 InterfaceFieldIterator::get_uint8s() const 00721 { 00722 if ( __infol == NULL ) { 00723 throw NullPointerException("Cannot get value of end element"); 00724 } else if ( __infol->type != IFT_UINT8 ) { 00725 throw TypeMismatchException("Requested value is not of type unsigned int"); 00726 } else { 00727 return (uint8_t *)__infol->value; 00728 } 00729 } 00730 00731 00732 /** Get value of current field as integer array. 00733 * @return field value 00734 * @exception NullPointerException invalid iterator, possibly end iterator 00735 * @exception TypeMismatchException thrown if field is not of type int or field 00736 * is not an array (length is 1) 00737 */ 00738 int16_t * 00739 InterfaceFieldIterator::get_int16s() const 00740 { 00741 if ( __infol == NULL ) { 00742 throw NullPointerException("Cannot get value of end element"); 00743 } else if ( __infol->type != IFT_INT16 ) { 00744 throw TypeMismatchException("Requested value is not of type int"); 00745 } else { 00746 return (int16_t *)__infol->value; 00747 } 00748 } 00749 00750 00751 /** Get value of current field as unsigned integer array. 00752 * @return field value 00753 * @exception NullPointerException invalid iterator, possibly end iterator 00754 * @exception TypeMismatchException thrown if field is not of type unsigned int 00755 * or field is not an array (length is 1) 00756 */ 00757 uint16_t * 00758 InterfaceFieldIterator::get_uint16s() const 00759 { 00760 if ( __infol == NULL ) { 00761 throw NullPointerException("Cannot get value of end element"); 00762 } else if ( __infol->type != IFT_UINT16 ) { 00763 throw TypeMismatchException("Requested value is not of type unsigned int"); 00764 } else { 00765 return (uint16_t *)__infol->value; 00766 } 00767 } 00768 00769 00770 /** Get value of current field as integer array. 00771 * @return field value 00772 * @exception NullPointerException invalid iterator, possibly end iterator 00773 * @exception TypeMismatchException thrown if field is not of type int or field 00774 * is not an array (length is 1) 00775 */ 00776 int32_t * 00777 InterfaceFieldIterator::get_int32s() const 00778 { 00779 if ( __infol == NULL ) { 00780 throw NullPointerException("Cannot get value of end element"); 00781 } else if ( __infol->type != IFT_INT32 ) { 00782 throw TypeMismatchException("Requested value is not of type int"); 00783 } else { 00784 return (int32_t *)__infol->value; 00785 } 00786 } 00787 00788 00789 /** Get value of current field as unsigned integer array. 00790 * @return field value 00791 * @exception NullPointerException invalid iterator, possibly end iterator 00792 * @exception TypeMismatchException thrown if field is not of type unsigned int 00793 * or field is not an array (length is 1) 00794 */ 00795 uint32_t * 00796 InterfaceFieldIterator::get_uint32s() const 00797 { 00798 if ( __infol == NULL ) { 00799 throw NullPointerException("Cannot get value of end element"); 00800 } else if ( __infol->type != IFT_UINT32 ) { 00801 throw TypeMismatchException("Requested value is not of type unsigned int"); 00802 } else { 00803 return (uint32_t *)__infol->value; 00804 } 00805 } 00806 00807 00808 /** Get value of current field as integer array. 00809 * @return field value 00810 * @exception NullPointerException invalid iterator, possibly end iterator 00811 * @exception TypeMismatchException thrown if field is not of type int or field 00812 * is not an array (length is 1) 00813 */ 00814 int64_t * 00815 InterfaceFieldIterator::get_int64s() const 00816 { 00817 if ( __infol == NULL ) { 00818 throw NullPointerException("Cannot get value of end element"); 00819 } else if ( __infol->type != IFT_INT64 ) { 00820 throw TypeMismatchException("Requested value is not of type int"); 00821 } else { 00822 return (int64_t *)__infol->value; 00823 } 00824 } 00825 00826 00827 /** Get value of current field as unsigned integer array. 00828 * @return field value 00829 * @exception NullPointerException invalid iterator, possibly end iterator 00830 * @exception TypeMismatchException thrown if field is not of type unsigned int 00831 * or field is not an array (length is 1) 00832 */ 00833 uint64_t * 00834 InterfaceFieldIterator::get_uint64s() const 00835 { 00836 if ( __infol == NULL ) { 00837 throw NullPointerException("Cannot get value of end element"); 00838 } else if ( __infol->type != IFT_UINT64 ) { 00839 throw TypeMismatchException("Requested value is not of type unsigned int"); 00840 } else { 00841 return (uint64_t *)__infol->value; 00842 } 00843 } 00844 00845 00846 /** Get value of current field as float array. 00847 * @return field value 00848 * @exception NullPointerException invalid iterator, possibly end iterator 00849 * @exception TypeMismatchException thrown if field is not of type float or field 00850 * is not an array (length is 1) 00851 */ 00852 float * 00853 InterfaceFieldIterator::get_floats() const 00854 { 00855 if ( __infol == NULL ) { 00856 throw NullPointerException("Cannot get value of end element"); 00857 } else if ( __infol->type != IFT_FLOAT ) { 00858 throw TypeMismatchException("Requested value is not of type float"); 00859 } else { 00860 return (float *)__infol->value; 00861 } 00862 } 00863 00864 00865 /** Get value of current field as double array. 00866 * @return field value 00867 * @exception NullPointerException invalid iterator, possibly end iterator 00868 * @exception TypeMismatchException thrown if field is not of type double or field 00869 * is not an array (length is 1) 00870 */ 00871 double * 00872 InterfaceFieldIterator::get_doubles() const 00873 { 00874 if ( __infol == NULL ) { 00875 throw NullPointerException("Cannot get value of end element"); 00876 } else if ( __infol->type != IFT_DOUBLE ) { 00877 throw TypeMismatchException("Requested value is not of type double"); 00878 } else { 00879 return (double *)__infol->value; 00880 } 00881 } 00882 00883 00884 /** Get value of current field as byte array. 00885 * @return field value 00886 * @exception NullPointerException invalid iterator, possibly end iterator 00887 * @exception TypeMismatchException thrown if field is not of type byte or field 00888 * is not an array (length is 1) 00889 */ 00890 uint8_t * 00891 InterfaceFieldIterator::get_bytes() const 00892 { 00893 if ( __infol == NULL ) { 00894 throw NullPointerException("Cannot get value of end element"); 00895 } else if ( __infol->type != IFT_BYTE ) { 00896 throw TypeMismatchException("Requested value is not of type byte"); 00897 } else { 00898 return (uint8_t *)__infol->value; 00899 } 00900 } 00901 00902 00903 /** Get value of current enum field as integer array. 00904 * @return field value 00905 * @exception NullPointerException invalid iterator, possibly end iterator 00906 * @exception TypeMismatchException thrown if field is not of type int or field 00907 * is not an array (length is 1) 00908 */ 00909 int32_t * 00910 InterfaceFieldIterator::get_enums() const 00911 { 00912 if ( __infol == NULL ) { 00913 throw NullPointerException("Cannot get value of end element"); 00914 } else if ( __infol->type != IFT_ENUM ) { 00915 throw TypeMismatchException("Requested value is not of type enum"); 00916 } else { 00917 return (int32_t *)__infol->value; 00918 } 00919 } 00920 00921 00922 /** Get value of current field as string. 00923 * @return field value 00924 * @exception NullPointerException invalid iterator, possibly end iterator 00925 * @exception TypeMismatchException thrown if field is not of type string 00926 */ 00927 const char * 00928 InterfaceFieldIterator::get_string() const 00929 { 00930 if ( __infol == NULL ) { 00931 throw NullPointerException("Cannot get value of end element"); 00932 } else if ( __infol->type != IFT_STRING ) { 00933 throw TypeMismatchException("Requested value is not of type string"); 00934 } else { 00935 return (const char *)__infol->value; 00936 } 00937 } 00938 00939 00940 /** Set value of current field as bool. 00941 * @param v the new value 00942 * @param index array index (only use if field is an array) 00943 * @exception NullPointerException invalid iterator, possibly end iterator 00944 * @exception TypeMismatchException thrown if field is not of type bool 00945 * @exception OutOfBoundsException thrown if index is out of bounds 00946 */ 00947 void 00948 InterfaceFieldIterator::set_bool(bool v, unsigned int index) 00949 { 00950 if ( __infol == NULL ) { 00951 throw NullPointerException("Cannot set value of end element"); 00952 } else if ( __infol->type != IFT_BOOL ) { 00953 throw TypeMismatchException("Field to be written is not of type bool"); 00954 } else if (index >= __infol->length) { 00955 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00956 } else { 00957 char* dst = (char *) __infol->value + index * sizeof(bool); 00958 memcpy((void *) dst, &v, sizeof(bool)); 00959 } 00960 } 00961 00962 00963 /** Set value of current field as integer. 00964 * @param v the new value 00965 * @param index array index (only use if field is an array) 00966 * @exception NullPointerException invalid iterator, possibly end iterator 00967 * @exception TypeMismatchException thrown if field is not of type int 00968 * @exception OutOfBoundsException thrown if index is out of bounds 00969 */ 00970 void 00971 InterfaceFieldIterator::set_int8(int8_t v, unsigned int index) 00972 { 00973 if ( __infol == NULL ) { 00974 throw NullPointerException("Cannot set value of end element"); 00975 } else if ( __infol->type != IFT_INT8 ) { 00976 throw TypeMismatchException("Field to be written is not of type int"); 00977 } else if (index >= __infol->length) { 00978 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00979 } else { 00980 char* dst = (char *) __infol->value + index * sizeof(int8_t); 00981 memcpy((void *) dst, &v, sizeof(int8_t)); 00982 } 00983 } 00984 00985 00986 /** Set value of current field as unsigned integer. 00987 * @param v the new value 00988 * @param index array index (only use if field is an array) 00989 * @exception NullPointerException invalid iterator, possibly end iterator 00990 * @exception TypeMismatchException thrown if field is not of type unsigned int 00991 * @exception OutOfBoundsException thrown if index is out of bounds 00992 */ 00993 void 00994 InterfaceFieldIterator::set_uint8(uint8_t v, unsigned int index) 00995 { 00996 if ( __infol == NULL ) { 00997 throw NullPointerException("Cannot set value of end element"); 00998 } else if ( __infol->type != IFT_UINT8 ) { 00999 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01000 } else if (index >= __infol->length) { 01001 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01002 } else { 01003 char* dst = (char *) __infol->value + index * sizeof(uint8_t); 01004 memcpy((void *) dst, &v, sizeof(uint8_t)); 01005 } 01006 } 01007 01008 01009 /** Set value of current field as integer. 01010 * @param v the new value 01011 * @param index array index (only use if field is an array) 01012 * @exception NullPointerException invalid iterator, possibly end iterator 01013 * @exception TypeMismatchException thrown if field is not of type int 01014 * @exception OutOfBoundsException thrown if index is out of bounds 01015 */ 01016 void 01017 InterfaceFieldIterator::set_int16(int16_t v, unsigned int index) 01018 { 01019 if ( __infol == NULL ) { 01020 throw NullPointerException("Cannot set value of end element"); 01021 } else if ( __infol->type != IFT_INT16 ) { 01022 throw TypeMismatchException("Field to be written is not of type int"); 01023 } else if (index >= __infol->length) { 01024 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01025 } else { 01026 char* dst = (char *) __infol->value + index * sizeof(int16_t); 01027 memcpy((void *) dst, &v, sizeof(int16_t)); 01028 } 01029 } 01030 01031 01032 /** Set value of current field as unsigned integer. 01033 * @param v the new value 01034 * @param index array index (only use if field is an array) 01035 * @exception NullPointerException invalid iterator, possibly end iterator 01036 * @exception TypeMismatchException thrown if field is not of type unsigned int 01037 * @exception OutOfBoundsException thrown if index is out of bounds 01038 */ 01039 void 01040 InterfaceFieldIterator::set_uint16(uint16_t v, unsigned int index) 01041 { 01042 if ( __infol == NULL ) { 01043 throw NullPointerException("Cannot set value of end element"); 01044 } else if ( __infol->type != IFT_UINT16 ) { 01045 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01046 } else if (index >= __infol->length) { 01047 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01048 } else { 01049 char* dst = (char *) __infol->value + index * sizeof(uint16_t); 01050 memcpy((void *) dst, &v, sizeof(uint16_t)); 01051 } 01052 } 01053 01054 01055 /** Set value of current field as integer. 01056 * @param v the new value 01057 * @param index array index (only use if field is an array) 01058 * @exception NullPointerException invalid iterator, possibly end iterator 01059 * @exception TypeMismatchException thrown if field is not of type int 01060 * @exception OutOfBoundsException thrown if index is out of bounds 01061 */ 01062 void 01063 InterfaceFieldIterator::set_int32(int32_t v, unsigned int index) 01064 { 01065 if ( __infol == NULL ) { 01066 throw NullPointerException("Cannot set value of end element"); 01067 } else if ( __infol->type != IFT_INT32 ) { 01068 throw TypeMismatchException("Field to be written is not of type int"); 01069 } else if (index >= __infol->length) { 01070 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01071 } else { 01072 char* dst = (char *) __infol->value + index * sizeof(int32_t); 01073 memcpy((void *) dst, &v, sizeof(int32_t)); 01074 } 01075 } 01076 01077 01078 /** Set value of current field as unsigned integer. 01079 * @param v the new value 01080 * @param index array index (only use if field is an array) 01081 * @exception NullPointerException invalid iterator, possibly end iterator 01082 * @exception TypeMismatchException thrown if field is not of type unsigned int 01083 * @exception OutOfBoundsException thrown if index is out of bounds 01084 */ 01085 void 01086 InterfaceFieldIterator::set_uint32(uint32_t v, unsigned int index) 01087 { 01088 if ( __infol == NULL ) { 01089 throw NullPointerException("Cannot set value of end element"); 01090 } else if ( __infol->type != IFT_UINT32 ) { 01091 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01092 } else if (index >= __infol->length) { 01093 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01094 } else { 01095 char* dst = (char *) __infol->value + index * sizeof(uint32_t); 01096 memcpy((void *) dst, &v, sizeof(uint32_t)); 01097 } 01098 } 01099 01100 01101 /** Set value of current field as integer. 01102 * @param v the new value 01103 * @param index array index (only use if field is an array) 01104 * @exception NullPointerException invalid iterator, possibly end iterator 01105 * @exception TypeMismatchException thrown if field is not of type int 01106 * @exception OutOfBoundsException thrown if index is out of bounds 01107 */ 01108 void 01109 InterfaceFieldIterator::set_int64(int64_t v, unsigned int index) 01110 { 01111 if ( __infol == NULL ) { 01112 throw NullPointerException("Cannot set value of end element"); 01113 } else if ( __infol->type != IFT_INT64 ) { 01114 throw TypeMismatchException("Field to be written is not of type int"); 01115 } else if (index >= __infol->length) { 01116 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01117 } else { 01118 char* dst = (char *) __infol->value + index * sizeof(int64_t); 01119 memcpy((void *) dst, &v, sizeof(int64_t)); 01120 } 01121 } 01122 01123 01124 /** Set value of current field as unsigned integer. 01125 * @param v the new value 01126 * @param index array index (only use if field is an array) 01127 * @exception NullPointerException invalid iterator, possibly end iterator 01128 * @exception TypeMismatchException thrown if field is not of type unsigned int 01129 * @exception OutOfBoundsException thrown if index is out of bounds 01130 */ 01131 void 01132 InterfaceFieldIterator::set_uint64(uint64_t v, unsigned int index) 01133 { 01134 if ( __infol == NULL ) { 01135 throw NullPointerException("Cannot set value of end element"); 01136 } else if ( __infol->type != IFT_UINT64 ) { 01137 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01138 } else if (index >= __infol->length) { 01139 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01140 } else { 01141 char* dst = (char *) __infol->value + index * sizeof(uint64_t); 01142 memcpy((void *) dst, &v, sizeof(uint64_t)); 01143 } 01144 } 01145 01146 01147 /** Set value of current field as float. 01148 * @param v the new value 01149 * @param index array index (only use if field is an array) 01150 * @exception NullPointerException invalid iterator, possibly end iterator 01151 * @exception TypeMismatchException thrown if field is not of type float 01152 * @exception OutOfBoundsException thrown if index is out of bounds 01153 */ 01154 void 01155 InterfaceFieldIterator::set_float(float v, unsigned int index) 01156 { 01157 if ( __infol == NULL ) { 01158 throw NullPointerException("Cannot set value of end element"); 01159 } else if ( __infol->type != IFT_FLOAT ) { 01160 throw TypeMismatchException("Field to be written is not of type float"); 01161 } else if (index >= __infol->length) { 01162 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01163 } else { 01164 char* dst = (char *) __infol->value + index * sizeof(float); 01165 memcpy((void *) dst, &v, sizeof(float)); 01166 } 01167 } 01168 01169 01170 /** Set value of current field as double. 01171 * @param v the new value 01172 * @param index array index (only use if field is an array) 01173 * @exception NullPointerException invalid iterator, possibly end iterator 01174 * @exception TypeMismatchException thrown if field is not of type double 01175 * @exception OutOfBoundsException thrown if index is out of bounds 01176 */ 01177 void 01178 InterfaceFieldIterator::set_double(double v, unsigned int index) 01179 { 01180 if ( __infol == NULL ) { 01181 throw NullPointerException("Cannot set value of end element"); 01182 } else if ( __infol->type != IFT_DOUBLE ) { 01183 throw TypeMismatchException("Field to be written is not of type double"); 01184 } else if (index >= __infol->length) { 01185 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01186 } else { 01187 char* dst = (char *) __infol->value + index * sizeof(double); 01188 memcpy((void *) dst, &v, sizeof(double)); 01189 } 01190 } 01191 01192 01193 /** Set value of current field as byte. 01194 * @param v the new value 01195 * @param index array index (only use if field is an array) 01196 * @exception NullPointerException invalid iterator, possibly end iterator 01197 * @exception TypeMismatchException thrown if field is not of type byte 01198 * @exception OutOfBoundsException thrown if index is out of bounds 01199 */ 01200 void 01201 InterfaceFieldIterator::set_byte(uint8_t v, unsigned int index) 01202 { 01203 if ( __infol == NULL ) { 01204 throw NullPointerException("Cannot set value of end element"); 01205 } else if ( __infol->type != IFT_BYTE ) { 01206 throw TypeMismatchException("Field to be written is not of type byte"); 01207 } else if (index >= __infol->length) { 01208 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01209 } else { 01210 char* dst = (char *) __infol->value + index * sizeof(uint8_t); 01211 memcpy((void *) dst, &v, sizeof(uint8_t)); 01212 } 01213 } 01214 01215 01216 /** Set value of current field as bool array. 01217 * @param v an array of bools 01218 * @exception NullPointerException invalid iterator, possibly end iterator 01219 * @exception TypeMismatchException thrown if field is not of type bool or field 01220 * is not an array (length is 1) 01221 */ 01222 void 01223 InterfaceFieldIterator::set_bools(bool *v) 01224 { 01225 if ( __infol == NULL ) { 01226 throw NullPointerException("Cannot set value of end element"); 01227 } else if ( __infol->type != IFT_BOOL ) { 01228 throw TypeMismatchException("Field to be written is not of type bool"); 01229 } else if (__infol->length == 1) { 01230 throw TypeMismatchException("Field %s is not an array", __infol->name); 01231 } else { 01232 memcpy(__infol->value, v, __infol->length * sizeof(bool)); 01233 } 01234 } 01235 01236 01237 /** Set value of current field as integer array. 01238 * @param v an array of ints 01239 * @exception NullPointerException invalid iterator, possibly end iterator 01240 * @exception TypeMismatchException thrown if field is not of type int or field 01241 * is not an array (length is 1) 01242 */ 01243 void 01244 InterfaceFieldIterator::set_int8s(int8_t *v) 01245 { 01246 if ( __infol == NULL ) { 01247 throw NullPointerException("Cannot set value of end element"); 01248 } else if ( __infol->type != IFT_INT8 ) { 01249 throw TypeMismatchException("Field to be written is not of type int"); 01250 } else if (__infol->length == 1) { 01251 throw TypeMismatchException("Field %s is not an array", __infol->name); 01252 } else { 01253 memcpy(__infol->value, v, __infol->length * sizeof(int8_t)); 01254 } 01255 } 01256 01257 01258 /** Set value of current field as unsigned integer array. 01259 * @param v an array of unsigned ints 01260 * @exception NullPointerException invalid iterator, possibly end iterator 01261 * @exception TypeMismatchException thrown if field is not of type unsigned int or field 01262 * is not an array (length is 1) 01263 */ 01264 void 01265 InterfaceFieldIterator::set_uint8s(uint8_t *v) 01266 { 01267 if ( __infol == NULL ) { 01268 throw NullPointerException("Cannot set value of end element"); 01269 } else if ( __infol->type != IFT_UINT8 ) { 01270 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01271 } else if (__infol->length == 1) { 01272 throw TypeMismatchException("Field %s is not an array", __infol->name); 01273 } else { 01274 memcpy(__infol->value, v, __infol->length * sizeof(uint8_t)); 01275 } 01276 } 01277 01278 01279 /** Set value of current field as integer array. 01280 * @param v an array of ints 01281 * @exception NullPointerException invalid iterator, possibly end iterator 01282 * @exception TypeMismatchException thrown if field is not of type int or field 01283 * is not an array (length is 1) 01284 */ 01285 void 01286 InterfaceFieldIterator::set_int16s(int16_t *v) 01287 { 01288 if ( __infol == NULL ) { 01289 throw NullPointerException("Cannot set value of end element"); 01290 } else if ( __infol->type != IFT_INT16 ) { 01291 throw TypeMismatchException("Field to be written is not of type int"); 01292 } else if (__infol->length == 1) { 01293 throw TypeMismatchException("Field %s is not an array", __infol->name); 01294 } else { 01295 memcpy(__infol->value, v, __infol->length * sizeof(int16_t)); 01296 } 01297 } 01298 01299 01300 /** Set value of current field as unsigned integer array. 01301 * @param v an array of unsigned ints 01302 * @exception NullPointerException invalid iterator, possibly end iterator 01303 * @exception TypeMismatchException thrown if field is not of type unsigned int or field 01304 * is not an array (length is 1) 01305 */ 01306 void 01307 InterfaceFieldIterator::set_uint16s(uint16_t *v) 01308 { 01309 if ( __infol == NULL ) { 01310 throw NullPointerException("Cannot set value of end element"); 01311 } else if ( __infol->type != IFT_UINT16 ) { 01312 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01313 } else if (__infol->length == 1) { 01314 throw TypeMismatchException("Field %s is not an array", __infol->name); 01315 } else { 01316 memcpy(__infol->value, v, __infol->length * sizeof(uint16_t)); 01317 } 01318 } 01319 01320 01321 /** Set value of current field as integer array. 01322 * @param v an array of ints 01323 * @exception NullPointerException invalid iterator, possibly end iterator 01324 * @exception TypeMismatchException thrown if field is not of type int or field 01325 * is not an array (length is 1) 01326 */ 01327 void 01328 InterfaceFieldIterator::set_int32s(int32_t *v) 01329 { 01330 if ( __infol == NULL ) { 01331 throw NullPointerException("Cannot set value of end element"); 01332 } else if ( __infol->type != IFT_INT32 ) { 01333 throw TypeMismatchException("Field to be written is not of type int"); 01334 } else if (__infol->length == 1) { 01335 throw TypeMismatchException("Field %s is not an array", __infol->name); 01336 } else { 01337 memcpy(__infol->value, v, __infol->length * sizeof(int32_t)); 01338 } 01339 } 01340 01341 01342 /** Set value of current field as unsigned integer array. 01343 * @param v an array of unsigned ints 01344 * @exception NullPointerException invalid iterator, possibly end iterator 01345 * @exception TypeMismatchException thrown if field is not of type unsigned int or field 01346 * is not an array (length is 1) 01347 */ 01348 void 01349 InterfaceFieldIterator::set_uint32s(uint32_t *v) 01350 { 01351 if ( __infol == NULL ) { 01352 throw NullPointerException("Cannot set value of end element"); 01353 } else if ( __infol->type != IFT_UINT32 ) { 01354 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01355 } else if (__infol->length == 1) { 01356 throw TypeMismatchException("Field %s is not an array", __infol->name); 01357 } else { 01358 memcpy(__infol->value, v, __infol->length * sizeof(uint32_t)); 01359 } 01360 } 01361 01362 01363 /** Set value of current field as integer array. 01364 * @param v an array of ints 01365 * @exception NullPointerException invalid iterator, possibly end iterator 01366 * @exception TypeMismatchException thrown if field is not of type int or field 01367 * is not an array (length is 1) 01368 */ 01369 void 01370 InterfaceFieldIterator::set_int64s(int64_t *v) 01371 { 01372 if ( __infol == NULL ) { 01373 throw NullPointerException("Cannot set value of end element"); 01374 } else if ( __infol->type != IFT_INT64 ) { 01375 throw TypeMismatchException("Field to be written is not of type int"); 01376 } else if (__infol->length == 1) { 01377 throw TypeMismatchException("Field %s is not an array", __infol->name); 01378 } else { 01379 memcpy(__infol->value, v, __infol->length * sizeof(int64_t)); 01380 } 01381 } 01382 01383 01384 /** Set value of current field as unsigned integer array. 01385 * @param v an array of unsigned ints 01386 * @exception NullPointerException invalid iterator, possibly end iterator 01387 * @exception TypeMismatchException thrown if field is not of type unsigned int or field 01388 * is not an array (length is 1) 01389 */ 01390 void 01391 InterfaceFieldIterator::set_uint64s(uint64_t *v) 01392 { 01393 if ( __infol == NULL ) { 01394 throw NullPointerException("Cannot set value of end element"); 01395 } else if ( __infol->type != IFT_UINT64 ) { 01396 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01397 } else if (__infol->length == 1) { 01398 throw TypeMismatchException("Field %s is not an array", __infol->name); 01399 } else { 01400 memcpy(__infol->value, v, __infol->length * sizeof(uint64_t)); 01401 } 01402 } 01403 01404 01405 /** Set value of current field as float array. 01406 * @param v an array of floats 01407 * @exception NullPointerException invalid iterator, possibly end iterator 01408 * @exception TypeMismatchException thrown if field is not of type float or field 01409 * is not an array (length is 1) 01410 */ 01411 void 01412 InterfaceFieldIterator::set_floats(float *v) 01413 { 01414 if ( __infol == NULL ) { 01415 throw NullPointerException("Cannot set value of end element"); 01416 } else if ( __infol->type != IFT_FLOAT ) { 01417 throw TypeMismatchException("Field to be written is not of type float"); 01418 } else if (__infol->length == 1) { 01419 throw TypeMismatchException("Field %s is not an array", __infol->name); 01420 } else { 01421 memcpy(__infol->value, v, __infol->length * sizeof(float)); 01422 } 01423 } 01424 01425 /** Set value of current field as double array. 01426 * @param v an array of doubles 01427 * @exception NullPointerException invalid iterator, possibly end iterator 01428 * @exception TypeMismatchException thrown if field is not of type double or field 01429 * is not an array (length is 1) 01430 */ 01431 void 01432 InterfaceFieldIterator::set_doubles(double *v) 01433 { 01434 if ( __infol == NULL ) { 01435 throw NullPointerException("Cannot set value of end element"); 01436 } else if ( __infol->type != IFT_DOUBLE ) { 01437 throw TypeMismatchException("Field to be written is not of type double"); 01438 } else if (__infol->length == 1) { 01439 throw TypeMismatchException("Field %s is not an array", __infol->name); 01440 } else { 01441 memcpy(__infol->value, v, __infol->length * sizeof(double)); 01442 } 01443 } 01444 01445 01446 /** Set value of current field as byte array. 01447 * @param v an array of bytes 01448 * @exception NullPointerException invalid iterator, possibly end iterator 01449 * @exception TypeMismatchException thrown if field is not of type byte or field 01450 * is not an array (length is 1) 01451 */ 01452 void 01453 InterfaceFieldIterator::set_bytes(uint8_t *v) 01454 { 01455 if ( __infol == NULL ) { 01456 throw NullPointerException("Cannot set value of end element"); 01457 } else if ( __infol->type != IFT_BYTE ) { 01458 throw TypeMismatchException("Field to be written is not of type byte"); 01459 } else if (__infol->length == 1) { 01460 throw TypeMismatchException("Field %s is not an array", __infol->name); 01461 } else { 01462 memcpy(__infol->value, v, __infol->length * sizeof(uint8_t)); 01463 } 01464 } 01465 01466 01467 /** Set value of current field as string. 01468 * @param v a string 01469 * @exception NullPointerException invalid iterator, possibly end iterator 01470 * @exception TypeMismatchException thrown if field is not of type string 01471 */ 01472 void 01473 InterfaceFieldIterator::set_string(const char *v) 01474 { 01475 if ( __infol == NULL ) { 01476 throw NullPointerException("Cannot set value of end element"); 01477 } else if ( __infol->type != IFT_STRING ) { 01478 throw TypeMismatchException("Field to be written is not of type string"); 01479 } else { 01480 strncpy((char *) __infol->value, v, __infol->length); 01481 } 01482 } 01483 01484 } // end namespace fawkes