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_BYTE: return "byte"; 00234 case IFT_STRING: return "string"; 00235 case IFT_ENUM: return __infol->enumtype; 00236 default: return "unknown"; 00237 } 00238 } 00239 } 00240 00241 00242 /** Get name of current field. 00243 * @return field name 00244 */ 00245 const char * 00246 InterfaceFieldIterator::get_name() const 00247 { 00248 if ( __infol == NULL ) { 00249 throw NullPointerException("Cannot get name of end element"); 00250 } else { 00251 return __infol->name; 00252 } 00253 } 00254 00255 00256 /** Get value of current field. 00257 * @return field value 00258 */ 00259 const void * 00260 InterfaceFieldIterator::get_value() const 00261 { 00262 if ( __infol == NULL ) { 00263 throw NullPointerException("Cannot get value of end element"); 00264 } else { 00265 return __infol->value; 00266 } 00267 } 00268 00269 00270 /** Get length of current field. 00271 * @return length of field 00272 */ 00273 size_t 00274 InterfaceFieldIterator::get_length() const 00275 { 00276 if ( __infol == NULL ) { 00277 throw NullPointerException("Cannot get length of end element"); 00278 } else { 00279 return __infol->length; 00280 } 00281 } 00282 00283 00284 /** Get value of current field as string. 00285 * @return field value as string 00286 */ 00287 const char * 00288 InterfaceFieldIterator::get_value_string() 00289 { 00290 if ( __infol == NULL ) { 00291 throw NullPointerException("Cannot get value of end element"); 00292 } else { 00293 if ( __value_string == NULL ) { 00294 if ( __infol->length == 0 ) throw OutOfBoundsException("Field length out of bounds", 00295 __infol->length, 1, (unsigned int)0xFFFFFFFF); 00296 00297 char *tmp1 = strdup(""); 00298 char *tmp2; 00299 00300 if ( __infol->type != IFT_STRING ) { 00301 for (size_t i = 0; i < __infol->length; ++i) { 00302 int rv = 0; 00303 switch (__infol->type) { 00304 case IFT_BOOL: 00305 rv = asprintf(&tmp2, "%s%s", tmp1, (((bool *)__infol->value)[i]) ? "true" : "false"); 00306 break; 00307 case IFT_INT8: 00308 rv = asprintf(&tmp2, "%s%i", tmp1, ((int8_t *)__infol->value)[i]); 00309 break; 00310 case IFT_INT16: 00311 rv = asprintf(&tmp2, "%s%i", tmp1, ((int16_t *)__infol->value)[i]); 00312 break; 00313 case IFT_INT32: 00314 rv = asprintf(&tmp2, "%s%i", tmp1, ((int32_t *)__infol->value)[i]); 00315 break; 00316 case IFT_INT64: 00317 #if __WORDSIZE == 64 00318 rv = asprintf(&tmp2, "%s%li", tmp1, ((int64_t *)__infol->value)[i]); 00319 #else 00320 rv = asprintf(&tmp2, "%s%lli", tmp1, ((int64_t *)__infol->value)[i]); 00321 #endif 00322 break; 00323 case IFT_UINT8: 00324 rv = asprintf(&tmp2, "%s%u", tmp1, ((uint8_t *)__infol->value)[i]); 00325 break; 00326 case IFT_UINT16: 00327 rv = asprintf(&tmp2, "%s%u", tmp1, ((uint16_t *)__infol->value)[i]); 00328 break; 00329 case IFT_UINT32: 00330 rv = asprintf(&tmp2, "%s%u", tmp1, ((uint32_t *)__infol->value)[i]); 00331 break; 00332 case IFT_UINT64: 00333 #if __WORDSIZE == 64 00334 rv = asprintf(&tmp2, "%s%lu", tmp1, ((uint64_t *)__infol->value)[i]); 00335 #else 00336 rv = asprintf(&tmp2, "%s%llu", tmp1, ((uint64_t *)__infol->value)[i]); 00337 #endif 00338 break; 00339 case IFT_FLOAT: 00340 rv = asprintf(&tmp2, "%s%f", tmp1, ((float *)__infol->value)[i]); 00341 break; 00342 case IFT_BYTE: 00343 rv = asprintf(&tmp2, "%s%u", tmp1, ((uint8_t *)__infol->value)[i]); 00344 break; 00345 case IFT_STRING: 00346 // cannot happen, caught with surrounding if statement 00347 00348 case IFT_ENUM: 00349 rv = asprintf(&tmp2, "%s%s", tmp1, __interface->enum_tostring(__infol->enumtype, ((int *)__infol->value)[i])); 00350 break; 00351 } 00352 00353 if ( rv == -1 ) { 00354 throw OutOfMemoryException("InterfaceFieldIterator::get_value_string(): asprintf() failed (1)"); 00355 } 00356 00357 free(tmp1); 00358 tmp1 = tmp2; 00359 if ( (__infol->length > 1) && (i < __infol->length - 1) ) { 00360 if (asprintf(&tmp2, "%s, ", tmp1) == -1) { 00361 throw OutOfMemoryException("InterfaceFieldIterator::get_value_string(): asprintf() failed (2)"); 00362 } 00363 free(tmp1); 00364 tmp1 = tmp2; 00365 } 00366 } 00367 00368 __value_string = tmp1; 00369 } else { 00370 // it's a string, or a small number 00371 if ( __infol->length > 1 ) { 00372 if (asprintf(&__value_string, "%s", (const char *)__infol->value) == -1) { 00373 throw OutOfMemoryException("InterfaceFieldIterator::get_value_string(): asprintf() failed (3)"); 00374 } 00375 } else { 00376 if (asprintf(&__value_string, "%c", *((const char *)__infol->value)) == -1) { 00377 throw OutOfMemoryException("InterfaceFieldIterator::get_value_string(): asprintf() failed (4)"); 00378 } 00379 } 00380 } 00381 } 00382 return __value_string; 00383 } 00384 } 00385 00386 00387 /** Get value of current field as bool. 00388 * @return field value 00389 * @param index array index (only use if field is an array) 00390 * @exception NullPointerException invalid iterator, possibly end iterator 00391 * @exception TypeMismatchException thrown if field is not of type bool 00392 * @exception OutOfBoundsException thrown if index is out of bounds 00393 */ 00394 bool 00395 InterfaceFieldIterator::get_bool(unsigned int index) const 00396 { 00397 if ( __infol == NULL ) { 00398 throw NullPointerException("Cannot get value of end element"); 00399 } else if ( __infol->type != IFT_BOOL ) { 00400 throw TypeMismatchException("Requested value is not of type bool"); 00401 } else if (index >= __infol->length) { 00402 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00403 } else { 00404 return ((bool *)__infol->value)[index]; 00405 } 00406 } 00407 00408 00409 /** Get value of current field as integer. 00410 * @return field value 00411 * @param index array index (only use if field is an array) 00412 * @exception NullPointerException invalid iterator, possibly end iterator 00413 * @exception TypeMismatchException thrown if field is not of type int 00414 * @exception OutOfBoundsException thrown if index is out of bounds 00415 */ 00416 int8_t 00417 InterfaceFieldIterator::get_int8(unsigned int index) const 00418 { 00419 if ( __infol == NULL ) { 00420 throw NullPointerException("Cannot get value of end element"); 00421 } else if ( __infol->type != IFT_INT8 ) { 00422 throw TypeMismatchException("Requested value is not of type int"); 00423 } else if (index >= __infol->length) { 00424 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00425 } else { 00426 return ((int8_t *)__infol->value)[index]; 00427 } 00428 } 00429 00430 00431 /** Get value of current field as unsigned integer. 00432 * @return field value 00433 * @param index array index (only use if field is an array) 00434 * @exception NullPointerException invalid iterator, possibly end iterator 00435 * @exception TypeMismatchException thrown if field is not of type unsigned int 00436 * @exception OutOfBoundsException thrown if index is out of bounds 00437 */ 00438 uint8_t 00439 InterfaceFieldIterator::get_uint8(unsigned int index) const 00440 { 00441 if ( __infol == NULL ) { 00442 throw NullPointerException("Cannot get value of end element"); 00443 } else if ( __infol->type != IFT_UINT8 ) { 00444 throw TypeMismatchException("Requested value is not of type unsigned int"); 00445 } else if (index >= __infol->length) { 00446 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00447 } else { 00448 return ((uint8_t *)__infol->value)[index]; 00449 } 00450 } 00451 00452 /** Get value of current field as integer. 00453 * @return field value 00454 * @param index array index (only use if field is an array) 00455 * @exception NullPointerException invalid iterator, possibly end iterator 00456 * @exception TypeMismatchException thrown if field is not of type int 00457 * @exception OutOfBoundsException thrown if index is out of bounds 00458 */ 00459 int16_t 00460 InterfaceFieldIterator::get_int16(unsigned int index) const 00461 { 00462 if ( __infol == NULL ) { 00463 throw NullPointerException("Cannot get value of end element"); 00464 } else if ( __infol->type != IFT_INT16 ) { 00465 throw TypeMismatchException("Requested value is not of type int"); 00466 } else if (index >= __infol->length) { 00467 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00468 } else { 00469 return ((int16_t *)__infol->value)[index]; 00470 } 00471 } 00472 00473 00474 /** Get value of current field as unsigned integer. 00475 * @return field value 00476 * @param index array index (only use if field is an array) 00477 * @exception NullPointerException invalid iterator, possibly end iterator 00478 * @exception TypeMismatchException thrown if field is not of type unsigned int 00479 * @exception OutOfBoundsException thrown if index is out of bounds 00480 */ 00481 uint16_t 00482 InterfaceFieldIterator::get_uint16(unsigned int index) const 00483 { 00484 if ( __infol == NULL ) { 00485 throw NullPointerException("Cannot get value of end element"); 00486 } else if ( __infol->type != IFT_UINT16 ) { 00487 throw TypeMismatchException("Requested value is not of type unsigned int"); 00488 } else if (index >= __infol->length) { 00489 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00490 } else { 00491 return ((uint16_t *)__infol->value)[index]; 00492 } 00493 } 00494 00495 /** Get value of current field as integer. 00496 * @return field value 00497 * @param index array index (only use if field is an array) 00498 * @exception NullPointerException invalid iterator, possibly end iterator 00499 * @exception TypeMismatchException thrown if field is not of type int 00500 * @exception OutOfBoundsException thrown if index is out of bounds 00501 */ 00502 int32_t 00503 InterfaceFieldIterator::get_int32(unsigned int index) const 00504 { 00505 if ( __infol == NULL ) { 00506 throw NullPointerException("Cannot get value of end element"); 00507 } else if ( __infol->type != IFT_INT32 ) { 00508 throw TypeMismatchException("Requested value is not of type int"); 00509 } else if (index >= __infol->length) { 00510 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00511 } else { 00512 return ((int32_t *)__infol->value)[index]; 00513 } 00514 } 00515 00516 00517 /** Get value of current field as unsigned integer. 00518 * @return field value 00519 * @param index array index (only use if field is an array) 00520 * @exception NullPointerException invalid iterator, possibly end iterator 00521 * @exception TypeMismatchException thrown if field is not of type unsigned int 00522 * @exception OutOfBoundsException thrown if index is out of bounds 00523 */ 00524 uint32_t 00525 InterfaceFieldIterator::get_uint32(unsigned int index) const 00526 { 00527 if ( __infol == NULL ) { 00528 throw NullPointerException("Cannot get value of end element"); 00529 } else if ( __infol->type != IFT_UINT32 ) { 00530 throw TypeMismatchException("Requested value is not of type unsigned int"); 00531 } else if (index >= __infol->length) { 00532 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00533 } else { 00534 return ((uint32_t *)__infol->value)[index]; 00535 } 00536 } 00537 00538 /** Get value of current field as integer. 00539 * @return field value 00540 * @param index array index (only use if field is an array) 00541 * @exception NullPointerException invalid iterator, possibly end iterator 00542 * @exception TypeMismatchException thrown if field is not of type int 00543 * @exception OutOfBoundsException thrown if index is out of bounds 00544 */ 00545 int64_t 00546 InterfaceFieldIterator::get_int64(unsigned int index) const 00547 { 00548 if ( __infol == NULL ) { 00549 throw NullPointerException("Cannot get value of end element"); 00550 } else if ( __infol->type != IFT_INT64 ) { 00551 throw TypeMismatchException("Requested value is not of type int"); 00552 } else if (index >= __infol->length) { 00553 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00554 } else { 00555 return ((int64_t *)__infol->value)[index]; 00556 } 00557 } 00558 00559 00560 /** Get value of current field as unsigned integer. 00561 * @return field value 00562 * @param index array index (only use if field is an array) 00563 * @exception NullPointerException invalid iterator, possibly end iterator 00564 * @exception TypeMismatchException thrown if field is not of type unsigned int 00565 * @exception OutOfBoundsException thrown if index is out of bounds 00566 */ 00567 uint64_t 00568 InterfaceFieldIterator::get_uint64(unsigned int index) const 00569 { 00570 if ( __infol == NULL ) { 00571 throw NullPointerException("Cannot get value of end element"); 00572 } else if ( __infol->type != IFT_UINT64 ) { 00573 throw TypeMismatchException("Requested value is not of type unsigned int"); 00574 } else if (index >= __infol->length) { 00575 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00576 } else { 00577 return ((uint64_t *)__infol->value)[index]; 00578 } 00579 } 00580 00581 00582 /** Get value of current field as float. 00583 * @return field value 00584 * @param index array index (only use if field is an array) 00585 * @exception NullPointerException invalid iterator, possibly end iterator 00586 * @exception TypeMismatchException thrown if field is not of type float 00587 * @exception OutOfBoundsException thrown if index is out of bounds 00588 */ 00589 float 00590 InterfaceFieldIterator::get_float(unsigned int index) const 00591 { 00592 if ( __infol == NULL ) { 00593 throw NullPointerException("Cannot get value of end element"); 00594 } else if ( __infol->type != IFT_FLOAT ) { 00595 throw TypeMismatchException("Requested value is not of type float"); 00596 } else if (index >= __infol->length) { 00597 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00598 } else { 00599 return ((float *)__infol->value)[index]; 00600 } 00601 } 00602 00603 00604 /** Get value of current field as byte. 00605 * @return field value 00606 * @param index array index (only use if field is an array) 00607 * @exception NullPointerException invalid iterator, possibly end iterator 00608 * @exception TypeMismatchException thrown if field is not of type byte 00609 * @exception OutOfBoundsException thrown if index is out of bounds 00610 */ 00611 uint8_t 00612 InterfaceFieldIterator::get_byte(unsigned int index) const 00613 { 00614 if ( __infol == NULL ) { 00615 throw NullPointerException("Cannot get value of end element"); 00616 } else if ( __infol->type != IFT_BYTE ) { 00617 throw TypeMismatchException("Requested value is not of type float"); 00618 } else if (index >= __infol->length) { 00619 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00620 } else { 00621 return ((uint8_t *)__infol->value)[index]; 00622 } 00623 } 00624 00625 00626 /** Get value of current field as bool array. 00627 * @return field value 00628 * @exception NullPointerException invalid iterator, possibly end iterator 00629 * @exception TypeMismatchException thrown if field is not of type bool or field 00630 * is not an array (length is 1) 00631 */ 00632 bool * 00633 InterfaceFieldIterator::get_bools() const 00634 { 00635 if ( __infol == NULL ) { 00636 throw NullPointerException("Cannot get value of end element"); 00637 } else if ( __infol->type != IFT_BOOL ) { 00638 throw TypeMismatchException("Requested value is not of type bool"); 00639 } else if (__infol->length == 1) { 00640 throw TypeMismatchException("Field %s is not an array", __infol->name); 00641 } else { 00642 return (bool *)__infol->value; 00643 } 00644 } 00645 00646 00647 /** Get value of current field as integer array. 00648 * @return field value 00649 * @exception NullPointerException invalid iterator, possibly end iterator 00650 * @exception TypeMismatchException thrown if field is not of type int or field 00651 * is not an array (length is 1) 00652 */ 00653 int8_t * 00654 InterfaceFieldIterator::get_int8s() const 00655 { 00656 if ( __infol == NULL ) { 00657 throw NullPointerException("Cannot get value of end element"); 00658 } else if ( __infol->type != IFT_INT8 ) { 00659 throw TypeMismatchException("Requested value is not of type int"); 00660 } else { 00661 return (int8_t *)__infol->value; 00662 } 00663 } 00664 00665 00666 /** Get value of current field as unsigned integer array. 00667 * @return field value 00668 * @exception NullPointerException invalid iterator, possibly end iterator 00669 * @exception TypeMismatchException thrown if field is not of type unsigned int 00670 * or field is not an array (length is 1) 00671 */ 00672 uint8_t * 00673 InterfaceFieldIterator::get_uint8s() const 00674 { 00675 if ( __infol == NULL ) { 00676 throw NullPointerException("Cannot get value of end element"); 00677 } else if ( __infol->type != IFT_UINT8 ) { 00678 throw TypeMismatchException("Requested value is not of type unsigned int"); 00679 } else { 00680 return (uint8_t *)__infol->value; 00681 } 00682 } 00683 00684 00685 /** Get value of current field as integer array. 00686 * @return field value 00687 * @exception NullPointerException invalid iterator, possibly end iterator 00688 * @exception TypeMismatchException thrown if field is not of type int or field 00689 * is not an array (length is 1) 00690 */ 00691 int16_t * 00692 InterfaceFieldIterator::get_int16s() const 00693 { 00694 if ( __infol == NULL ) { 00695 throw NullPointerException("Cannot get value of end element"); 00696 } else if ( __infol->type != IFT_INT16 ) { 00697 throw TypeMismatchException("Requested value is not of type int"); 00698 } else { 00699 return (int16_t *)__infol->value; 00700 } 00701 } 00702 00703 00704 /** Get value of current field as unsigned integer array. 00705 * @return field value 00706 * @exception NullPointerException invalid iterator, possibly end iterator 00707 * @exception TypeMismatchException thrown if field is not of type unsigned int 00708 * or field is not an array (length is 1) 00709 */ 00710 uint16_t * 00711 InterfaceFieldIterator::get_uint16s() const 00712 { 00713 if ( __infol == NULL ) { 00714 throw NullPointerException("Cannot get value of end element"); 00715 } else if ( __infol->type != IFT_UINT16 ) { 00716 throw TypeMismatchException("Requested value is not of type unsigned int"); 00717 } else { 00718 return (uint16_t *)__infol->value; 00719 } 00720 } 00721 00722 00723 /** Get value of current field as integer array. 00724 * @return field value 00725 * @exception NullPointerException invalid iterator, possibly end iterator 00726 * @exception TypeMismatchException thrown if field is not of type int or field 00727 * is not an array (length is 1) 00728 */ 00729 int32_t * 00730 InterfaceFieldIterator::get_int32s() const 00731 { 00732 if ( __infol == NULL ) { 00733 throw NullPointerException("Cannot get value of end element"); 00734 } else if ( __infol->type != IFT_INT32 ) { 00735 throw TypeMismatchException("Requested value is not of type int"); 00736 } else { 00737 return (int32_t *)__infol->value; 00738 } 00739 } 00740 00741 00742 /** Get value of current field as unsigned integer array. 00743 * @return field value 00744 * @exception NullPointerException invalid iterator, possibly end iterator 00745 * @exception TypeMismatchException thrown if field is not of type unsigned int 00746 * or field is not an array (length is 1) 00747 */ 00748 uint32_t * 00749 InterfaceFieldIterator::get_uint32s() const 00750 { 00751 if ( __infol == NULL ) { 00752 throw NullPointerException("Cannot get value of end element"); 00753 } else if ( __infol->type != IFT_UINT32 ) { 00754 throw TypeMismatchException("Requested value is not of type unsigned int"); 00755 } else { 00756 return (uint32_t *)__infol->value; 00757 } 00758 } 00759 00760 00761 /** Get value of current field as integer array. 00762 * @return field value 00763 * @exception NullPointerException invalid iterator, possibly end iterator 00764 * @exception TypeMismatchException thrown if field is not of type int or field 00765 * is not an array (length is 1) 00766 */ 00767 int64_t * 00768 InterfaceFieldIterator::get_int64s() const 00769 { 00770 if ( __infol == NULL ) { 00771 throw NullPointerException("Cannot get value of end element"); 00772 } else if ( __infol->type != IFT_INT64 ) { 00773 throw TypeMismatchException("Requested value is not of type int"); 00774 } else { 00775 return (int64_t *)__infol->value; 00776 } 00777 } 00778 00779 00780 /** Get value of current field as unsigned integer array. 00781 * @return field value 00782 * @exception NullPointerException invalid iterator, possibly end iterator 00783 * @exception TypeMismatchException thrown if field is not of type unsigned int 00784 * or field is not an array (length is 1) 00785 */ 00786 uint64_t * 00787 InterfaceFieldIterator::get_uint64s() const 00788 { 00789 if ( __infol == NULL ) { 00790 throw NullPointerException("Cannot get value of end element"); 00791 } else if ( __infol->type != IFT_UINT64 ) { 00792 throw TypeMismatchException("Requested value is not of type unsigned int"); 00793 } else { 00794 return (uint64_t *)__infol->value; 00795 } 00796 } 00797 00798 00799 /** Get value of current field as float array. 00800 * @return field value 00801 * @exception NullPointerException invalid iterator, possibly end iterator 00802 * @exception TypeMismatchException thrown if field is not of type float or field 00803 * is not an array (length is 1) 00804 */ 00805 float * 00806 InterfaceFieldIterator::get_floats() const 00807 { 00808 if ( __infol == NULL ) { 00809 throw NullPointerException("Cannot get value of end element"); 00810 } else if ( __infol->type != IFT_FLOAT ) { 00811 throw TypeMismatchException("Requested value is not of type float"); 00812 } else { 00813 return (float *)__infol->value; 00814 } 00815 } 00816 00817 00818 /** Get value of current field as byte array. 00819 * @return field value 00820 * @exception NullPointerException invalid iterator, possibly end iterator 00821 * @exception TypeMismatchException thrown if field is not of type byte or field 00822 * is not an array (length is 1) 00823 */ 00824 uint8_t * 00825 InterfaceFieldIterator::get_bytes() const 00826 { 00827 if ( __infol == NULL ) { 00828 throw NullPointerException("Cannot get value of end element"); 00829 } else if ( __infol->type != IFT_BYTE ) { 00830 throw TypeMismatchException("Requested value is not of type float"); 00831 } else { 00832 return (uint8_t *)__infol->value; 00833 } 00834 } 00835 00836 00837 /** Get value of current field as string. 00838 * @return field value 00839 * @exception NullPointerException invalid iterator, possibly end iterator 00840 * @exception TypeMismatchException thrown if field is not of type string 00841 */ 00842 const char * 00843 InterfaceFieldIterator::get_string() const 00844 { 00845 if ( __infol == NULL ) { 00846 throw NullPointerException("Cannot get value of end element"); 00847 } else if ( __infol->type != IFT_STRING ) { 00848 throw TypeMismatchException("Requested value is not of type string"); 00849 } else { 00850 return (const char *)__infol->value; 00851 } 00852 } 00853 00854 00855 /** Set value of current field as bool. 00856 * @param v the new value 00857 * @param index array index (only use if field is an array) 00858 * @exception NullPointerException invalid iterator, possibly end iterator 00859 * @exception TypeMismatchException thrown if field is not of type bool 00860 * @exception OutOfBoundsException thrown if index is out of bounds 00861 */ 00862 void 00863 InterfaceFieldIterator::set_bool(bool v, unsigned int index) 00864 { 00865 if ( __infol == NULL ) { 00866 throw NullPointerException("Cannot set value of end element"); 00867 } else if ( __infol->type != IFT_BOOL ) { 00868 throw TypeMismatchException("Field to be written is not of type bool"); 00869 } else if (index >= __infol->length) { 00870 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00871 } else { 00872 char* dst = (char *) __infol->value + index * sizeof(bool); 00873 memcpy((void *) dst, &v, sizeof(bool)); 00874 } 00875 } 00876 00877 00878 /** Set value of current field as integer. 00879 * @param v the new value 00880 * @param index array index (only use if field is an array) 00881 * @exception NullPointerException invalid iterator, possibly end iterator 00882 * @exception TypeMismatchException thrown if field is not of type int 00883 * @exception OutOfBoundsException thrown if index is out of bounds 00884 */ 00885 void 00886 InterfaceFieldIterator::set_int8(int8_t v, unsigned int index) 00887 { 00888 if ( __infol == NULL ) { 00889 throw NullPointerException("Cannot set value of end element"); 00890 } else if ( __infol->type != IFT_INT8 ) { 00891 throw TypeMismatchException("Field to be written is not of type int"); 00892 } else if (index >= __infol->length) { 00893 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00894 } else { 00895 char* dst = (char *) __infol->value + index * sizeof(int8_t); 00896 memcpy((void *) dst, &v, sizeof(int8_t)); 00897 } 00898 } 00899 00900 00901 /** Set value of current field as unsigned integer. 00902 * @param v the new value 00903 * @param index array index (only use if field is an array) 00904 * @exception NullPointerException invalid iterator, possibly end iterator 00905 * @exception TypeMismatchException thrown if field is not of type unsigned int 00906 * @exception OutOfBoundsException thrown if index is out of bounds 00907 */ 00908 void 00909 InterfaceFieldIterator::set_uint8(uint8_t v, unsigned int index) 00910 { 00911 if ( __infol == NULL ) { 00912 throw NullPointerException("Cannot set value of end element"); 00913 } else if ( __infol->type != IFT_UINT8 ) { 00914 throw TypeMismatchException("Field to be written is not of type unsigned int"); 00915 } else if (index >= __infol->length) { 00916 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00917 } else { 00918 char* dst = (char *) __infol->value + index * sizeof(uint8_t); 00919 memcpy((void *) dst, &v, sizeof(uint8_t)); 00920 } 00921 } 00922 00923 00924 /** Set value of current field as integer. 00925 * @param v the new value 00926 * @param index array index (only use if field is an array) 00927 * @exception NullPointerException invalid iterator, possibly end iterator 00928 * @exception TypeMismatchException thrown if field is not of type int 00929 * @exception OutOfBoundsException thrown if index is out of bounds 00930 */ 00931 void 00932 InterfaceFieldIterator::set_int16(int16_t v, unsigned int index) 00933 { 00934 if ( __infol == NULL ) { 00935 throw NullPointerException("Cannot set value of end element"); 00936 } else if ( __infol->type != IFT_INT16 ) { 00937 throw TypeMismatchException("Field to be written is not of type int"); 00938 } else if (index >= __infol->length) { 00939 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00940 } else { 00941 char* dst = (char *) __infol->value + index * sizeof(int16_t); 00942 memcpy((void *) dst, &v, sizeof(int16_t)); 00943 } 00944 } 00945 00946 00947 /** Set value of current field as unsigned integer. 00948 * @param v the new value 00949 * @param index array index (only use if field is an array) 00950 * @exception NullPointerException invalid iterator, possibly end iterator 00951 * @exception TypeMismatchException thrown if field is not of type unsigned int 00952 * @exception OutOfBoundsException thrown if index is out of bounds 00953 */ 00954 void 00955 InterfaceFieldIterator::set_uint16(uint16_t v, unsigned int index) 00956 { 00957 if ( __infol == NULL ) { 00958 throw NullPointerException("Cannot set value of end element"); 00959 } else if ( __infol->type != IFT_UINT16 ) { 00960 throw TypeMismatchException("Field to be written is not of type unsigned int"); 00961 } else if (index >= __infol->length) { 00962 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00963 } else { 00964 char* dst = (char *) __infol->value + index * sizeof(uint16_t); 00965 memcpy((void *) dst, &v, sizeof(uint16_t)); 00966 } 00967 } 00968 00969 00970 /** Set value of current field as integer. 00971 * @param v the new value 00972 * @param index array index (only use if field is an array) 00973 * @exception NullPointerException invalid iterator, possibly end iterator 00974 * @exception TypeMismatchException thrown if field is not of type int 00975 * @exception OutOfBoundsException thrown if index is out of bounds 00976 */ 00977 void 00978 InterfaceFieldIterator::set_int32(int32_t v, unsigned int index) 00979 { 00980 if ( __infol == NULL ) { 00981 throw NullPointerException("Cannot set value of end element"); 00982 } else if ( __infol->type != IFT_INT32 ) { 00983 throw TypeMismatchException("Field to be written is not of type int"); 00984 } else if (index >= __infol->length) { 00985 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 00986 } else { 00987 char* dst = (char *) __infol->value + index * sizeof(int32_t); 00988 memcpy((void *) dst, &v, sizeof(int32_t)); 00989 } 00990 } 00991 00992 00993 /** Set value of current field as unsigned integer. 00994 * @param v the new value 00995 * @param index array index (only use if field is an array) 00996 * @exception NullPointerException invalid iterator, possibly end iterator 00997 * @exception TypeMismatchException thrown if field is not of type unsigned int 00998 * @exception OutOfBoundsException thrown if index is out of bounds 00999 */ 01000 void 01001 InterfaceFieldIterator::set_uint32(uint32_t v, unsigned int index) 01002 { 01003 if ( __infol == NULL ) { 01004 throw NullPointerException("Cannot set value of end element"); 01005 } else if ( __infol->type != IFT_UINT32 ) { 01006 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01007 } else if (index >= __infol->length) { 01008 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01009 } else { 01010 char* dst = (char *) __infol->value + index * sizeof(uint32_t); 01011 memcpy((void *) dst, &v, sizeof(uint32_t)); 01012 } 01013 } 01014 01015 01016 /** Set value of current field as integer. 01017 * @param v the new value 01018 * @param index array index (only use if field is an array) 01019 * @exception NullPointerException invalid iterator, possibly end iterator 01020 * @exception TypeMismatchException thrown if field is not of type int 01021 * @exception OutOfBoundsException thrown if index is out of bounds 01022 */ 01023 void 01024 InterfaceFieldIterator::set_int64(int64_t v, unsigned int index) 01025 { 01026 if ( __infol == NULL ) { 01027 throw NullPointerException("Cannot set value of end element"); 01028 } else if ( __infol->type != IFT_INT64 ) { 01029 throw TypeMismatchException("Field to be written is not of type int"); 01030 } else if (index >= __infol->length) { 01031 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01032 } else { 01033 char* dst = (char *) __infol->value + index * sizeof(int64_t); 01034 memcpy((void *) dst, &v, sizeof(int64_t)); 01035 } 01036 } 01037 01038 01039 /** Set value of current field as unsigned integer. 01040 * @param v the new value 01041 * @param index array index (only use if field is an array) 01042 * @exception NullPointerException invalid iterator, possibly end iterator 01043 * @exception TypeMismatchException thrown if field is not of type unsigned int 01044 * @exception OutOfBoundsException thrown if index is out of bounds 01045 */ 01046 void 01047 InterfaceFieldIterator::set_uint64(uint64_t v, unsigned int index) 01048 { 01049 if ( __infol == NULL ) { 01050 throw NullPointerException("Cannot set value of end element"); 01051 } else if ( __infol->type != IFT_UINT64 ) { 01052 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01053 } else if (index >= __infol->length) { 01054 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01055 } else { 01056 char* dst = (char *) __infol->value + index * sizeof(uint64_t); 01057 memcpy((void *) dst, &v, sizeof(uint64_t)); 01058 } 01059 } 01060 01061 01062 /** Set value of current field as float. 01063 * @param v the new value 01064 * @param index array index (only use if field is an array) 01065 * @exception NullPointerException invalid iterator, possibly end iterator 01066 * @exception TypeMismatchException thrown if field is not of type float 01067 * @exception OutOfBoundsException thrown if index is out of bounds 01068 */ 01069 void 01070 InterfaceFieldIterator::set_float(float v, unsigned int index) 01071 { 01072 if ( __infol == NULL ) { 01073 throw NullPointerException("Cannot set value of end element"); 01074 } else if ( __infol->type != IFT_FLOAT ) { 01075 throw TypeMismatchException("Field to be written is not of type float"); 01076 } else if (index >= __infol->length) { 01077 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01078 } else { 01079 char* dst = (char *) __infol->value + index * sizeof(float); 01080 memcpy((void *) dst, &v, sizeof(float)); 01081 } 01082 } 01083 01084 01085 /** Set value of current field as byte. 01086 * @param v the new value 01087 * @param index array index (only use if field is an array) 01088 * @exception NullPointerException invalid iterator, possibly end iterator 01089 * @exception TypeMismatchException thrown if field is not of type byte 01090 * @exception OutOfBoundsException thrown if index is out of bounds 01091 */ 01092 void 01093 InterfaceFieldIterator::set_byte(uint8_t v, unsigned int index) 01094 { 01095 if ( __infol == NULL ) { 01096 throw NullPointerException("Cannot set value of end element"); 01097 } else if ( __infol->type != IFT_BYTE ) { 01098 throw TypeMismatchException("Field to be written is not of type byte"); 01099 } else if (index >= __infol->length) { 01100 throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); 01101 } else { 01102 char* dst = (char *) __infol->value + index * sizeof(uint8_t); 01103 memcpy((void *) dst, &v, sizeof(uint8_t)); 01104 } 01105 } 01106 01107 01108 /** Set value of current field as bool array. 01109 * @param v an array of bools 01110 * @exception NullPointerException invalid iterator, possibly end iterator 01111 * @exception TypeMismatchException thrown if field is not of type bool or field 01112 * is not an array (length is 1) 01113 */ 01114 void 01115 InterfaceFieldIterator::set_bools(bool *v) 01116 { 01117 if ( __infol == NULL ) { 01118 throw NullPointerException("Cannot set value of end element"); 01119 } else if ( __infol->type != IFT_BOOL ) { 01120 throw TypeMismatchException("Field to be written is not of type bool"); 01121 } else if (__infol->length == 1) { 01122 throw TypeMismatchException("Field %s is not an array", __infol->name); 01123 } else { 01124 memcpy(__infol->value, v, __infol->length * sizeof(bool)); 01125 } 01126 } 01127 01128 01129 /** Set value of current field as integer array. 01130 * @param v an array of ints 01131 * @exception NullPointerException invalid iterator, possibly end iterator 01132 * @exception TypeMismatchException thrown if field is not of type int or field 01133 * is not an array (length is 1) 01134 */ 01135 void 01136 InterfaceFieldIterator::set_int8s(int8_t *v) 01137 { 01138 if ( __infol == NULL ) { 01139 throw NullPointerException("Cannot set value of end element"); 01140 } else if ( __infol->type != IFT_INT8 ) { 01141 throw TypeMismatchException("Field to be written is not of type int"); 01142 } else if (__infol->length == 1) { 01143 throw TypeMismatchException("Field %s is not an array", __infol->name); 01144 } else { 01145 memcpy(__infol->value, v, __infol->length * sizeof(int8_t)); 01146 } 01147 } 01148 01149 01150 /** Set value of current field as unsigned integer array. 01151 * @param v an array of unsigned ints 01152 * @exception NullPointerException invalid iterator, possibly end iterator 01153 * @exception TypeMismatchException thrown if field is not of type unsigned int or field 01154 * is not an array (length is 1) 01155 */ 01156 void 01157 InterfaceFieldIterator::set_uint8s(uint8_t *v) 01158 { 01159 if ( __infol == NULL ) { 01160 throw NullPointerException("Cannot set value of end element"); 01161 } else if ( __infol->type != IFT_UINT8 ) { 01162 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01163 } else if (__infol->length == 1) { 01164 throw TypeMismatchException("Field %s is not an array", __infol->name); 01165 } else { 01166 memcpy(__infol->value, v, __infol->length * sizeof(uint8_t)); 01167 } 01168 } 01169 01170 01171 /** Set value of current field as integer array. 01172 * @param v an array of ints 01173 * @exception NullPointerException invalid iterator, possibly end iterator 01174 * @exception TypeMismatchException thrown if field is not of type int or field 01175 * is not an array (length is 1) 01176 */ 01177 void 01178 InterfaceFieldIterator::set_int16s(int16_t *v) 01179 { 01180 if ( __infol == NULL ) { 01181 throw NullPointerException("Cannot set value of end element"); 01182 } else if ( __infol->type != IFT_INT16 ) { 01183 throw TypeMismatchException("Field to be written is not of type int"); 01184 } else if (__infol->length == 1) { 01185 throw TypeMismatchException("Field %s is not an array", __infol->name); 01186 } else { 01187 memcpy(__infol->value, v, __infol->length * sizeof(int16_t)); 01188 } 01189 } 01190 01191 01192 /** Set value of current field as unsigned integer array. 01193 * @param v an array of unsigned ints 01194 * @exception NullPointerException invalid iterator, possibly end iterator 01195 * @exception TypeMismatchException thrown if field is not of type unsigned int or field 01196 * is not an array (length is 1) 01197 */ 01198 void 01199 InterfaceFieldIterator::set_uint16s(uint16_t *v) 01200 { 01201 if ( __infol == NULL ) { 01202 throw NullPointerException("Cannot set value of end element"); 01203 } else if ( __infol->type != IFT_UINT16 ) { 01204 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01205 } else if (__infol->length == 1) { 01206 throw TypeMismatchException("Field %s is not an array", __infol->name); 01207 } else { 01208 memcpy(__infol->value, v, __infol->length * sizeof(uint16_t)); 01209 } 01210 } 01211 01212 01213 /** Set value of current field as integer array. 01214 * @param v an array of ints 01215 * @exception NullPointerException invalid iterator, possibly end iterator 01216 * @exception TypeMismatchException thrown if field is not of type int or field 01217 * is not an array (length is 1) 01218 */ 01219 void 01220 InterfaceFieldIterator::set_int32s(int32_t *v) 01221 { 01222 if ( __infol == NULL ) { 01223 throw NullPointerException("Cannot set value of end element"); 01224 } else if ( __infol->type != IFT_INT32 ) { 01225 throw TypeMismatchException("Field to be written is not of type int"); 01226 } else if (__infol->length == 1) { 01227 throw TypeMismatchException("Field %s is not an array", __infol->name); 01228 } else { 01229 memcpy(__infol->value, v, __infol->length * sizeof(int32_t)); 01230 } 01231 } 01232 01233 01234 /** Set value of current field as unsigned integer array. 01235 * @param v an array of unsigned ints 01236 * @exception NullPointerException invalid iterator, possibly end iterator 01237 * @exception TypeMismatchException thrown if field is not of type unsigned int or field 01238 * is not an array (length is 1) 01239 */ 01240 void 01241 InterfaceFieldIterator::set_uint32s(uint32_t *v) 01242 { 01243 if ( __infol == NULL ) { 01244 throw NullPointerException("Cannot set value of end element"); 01245 } else if ( __infol->type != IFT_UINT32 ) { 01246 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01247 } else if (__infol->length == 1) { 01248 throw TypeMismatchException("Field %s is not an array", __infol->name); 01249 } else { 01250 memcpy(__infol->value, v, __infol->length * sizeof(uint32_t)); 01251 } 01252 } 01253 01254 01255 /** Set value of current field as integer array. 01256 * @param v an array of ints 01257 * @exception NullPointerException invalid iterator, possibly end iterator 01258 * @exception TypeMismatchException thrown if field is not of type int or field 01259 * is not an array (length is 1) 01260 */ 01261 void 01262 InterfaceFieldIterator::set_int64s(int64_t *v) 01263 { 01264 if ( __infol == NULL ) { 01265 throw NullPointerException("Cannot set value of end element"); 01266 } else if ( __infol->type != IFT_INT64 ) { 01267 throw TypeMismatchException("Field to be written is not of type int"); 01268 } else if (__infol->length == 1) { 01269 throw TypeMismatchException("Field %s is not an array", __infol->name); 01270 } else { 01271 memcpy(__infol->value, v, __infol->length * sizeof(int64_t)); 01272 } 01273 } 01274 01275 01276 /** Set value of current field as unsigned integer array. 01277 * @param v an array of unsigned ints 01278 * @exception NullPointerException invalid iterator, possibly end iterator 01279 * @exception TypeMismatchException thrown if field is not of type unsigned int or field 01280 * is not an array (length is 1) 01281 */ 01282 void 01283 InterfaceFieldIterator::set_uint64s(uint64_t *v) 01284 { 01285 if ( __infol == NULL ) { 01286 throw NullPointerException("Cannot set value of end element"); 01287 } else if ( __infol->type != IFT_UINT64 ) { 01288 throw TypeMismatchException("Field to be written is not of type unsigned int"); 01289 } else if (__infol->length == 1) { 01290 throw TypeMismatchException("Field %s is not an array", __infol->name); 01291 } else { 01292 memcpy(__infol->value, v, __infol->length * sizeof(uint64_t)); 01293 } 01294 } 01295 01296 01297 /** Set value of current field as float array. 01298 * @param v an array of floats 01299 * @exception NullPointerException invalid iterator, possibly end iterator 01300 * @exception TypeMismatchException thrown if field is not of type float or field 01301 * is not an array (length is 1) 01302 */ 01303 void 01304 InterfaceFieldIterator::set_floats(float *v) 01305 { 01306 if ( __infol == NULL ) { 01307 throw NullPointerException("Cannot set value of end element"); 01308 } else if ( __infol->type != IFT_FLOAT ) { 01309 throw TypeMismatchException("Field to be written is not of type float"); 01310 } else if (__infol->length == 1) { 01311 throw TypeMismatchException("Field %s is not an array", __infol->name); 01312 } else { 01313 memcpy(__infol->value, v, __infol->length * sizeof(float)); 01314 } 01315 } 01316 01317 01318 /** Set value of current field as byte array. 01319 * @param v an array of bytes 01320 * @exception NullPointerException invalid iterator, possibly end iterator 01321 * @exception TypeMismatchException thrown if field is not of type byte or field 01322 * is not an array (length is 1) 01323 */ 01324 void 01325 InterfaceFieldIterator::set_bytes(uint8_t *v) 01326 { 01327 if ( __infol == NULL ) { 01328 throw NullPointerException("Cannot set value of end element"); 01329 } else if ( __infol->type != IFT_BYTE ) { 01330 throw TypeMismatchException("Field to be written is not of type byte"); 01331 } else if (__infol->length == 1) { 01332 throw TypeMismatchException("Field %s is not an array", __infol->name); 01333 } else { 01334 memcpy(__infol->value, v, __infol->length * sizeof(uint8_t)); 01335 } 01336 } 01337 01338 01339 /** Set value of current field as string. 01340 * @param v a string 01341 * @exception NullPointerException invalid iterator, possibly end iterator 01342 * @exception TypeMismatchException thrown if field is not of type string 01343 */ 01344 void 01345 InterfaceFieldIterator::set_string(const char *v) 01346 { 01347 if ( __infol == NULL ) { 01348 throw NullPointerException("Cannot set value of end element"); 01349 } else if ( __infol->type != IFT_STRING ) { 01350 throw TypeMismatchException("Field to be written is not of type string"); 01351 } else { 01352 strncpy((char *) __infol->value, v, __infol->length); 01353 } 01354 } 01355 01356 } // end namespace fawkes