00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 InterfaceFieldIterator::InterfaceFieldIterator()
00050 {
00051 __interface = NULL;
00052 __infol = NULL;
00053 __value_string = NULL;
00054 }
00055
00056
00057
00058
00059
00060
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
00072
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
00086 InterfaceFieldIterator::~InterfaceFieldIterator()
00087 {
00088 if ( __value_string ) free(__value_string);
00089 }
00090
00091
00092
00093
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
00109
00110
00111
00112 InterfaceFieldIterator
00113 InterfaceFieldIterator::operator++(int inc)
00114 {
00115 InterfaceFieldIterator rv(*this);
00116 ++(*this);
00117 return rv;
00118 }
00119
00120
00121
00122
00123
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
00136
00137
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
00150
00151
00152
00153 bool
00154 InterfaceFieldIterator::operator==(const InterfaceFieldIterator & fi) const
00155 {
00156 return (__infol == fi.__infol);
00157 }
00158
00159
00160
00161
00162
00163
00164 bool
00165 InterfaceFieldIterator::operator!=(const InterfaceFieldIterator & fi) const
00166 {
00167 return ! (*this == fi);
00168 }
00169
00170
00171
00172
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
00186
00187
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
00200
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
00214
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
00243
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
00257
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
00271
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
00285
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
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
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
00388
00389
00390
00391
00392
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
00410
00411
00412
00413
00414
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
00432
00433
00434
00435
00436
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
00453
00454
00455
00456
00457
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
00475
00476
00477
00478
00479
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
00496
00497
00498
00499
00500
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
00518
00519
00520
00521
00522
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
00539
00540
00541
00542
00543
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
00561
00562
00563
00564
00565
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
00583
00584
00585
00586
00587
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
00605
00606
00607
00608
00609
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
00627
00628
00629
00630
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
00648
00649
00650
00651
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
00667
00668
00669
00670
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
00686
00687
00688
00689
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
00705
00706
00707
00708
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
00724
00725
00726
00727
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
00743
00744
00745
00746
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
00762
00763
00764
00765
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
00781
00782
00783
00784
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
00800
00801
00802
00803
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
00819
00820
00821
00822
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
00838
00839
00840
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
00856
00857
00858
00859
00860
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
00879
00880
00881
00882
00883
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
00902
00903
00904
00905
00906
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
00925
00926
00927
00928
00929
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
00948
00949
00950
00951
00952
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
00971
00972
00973
00974
00975
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
00994
00995
00996
00997
00998
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
01017
01018
01019
01020
01021
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
01040
01041
01042
01043
01044
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
01063
01064
01065
01066
01067
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
01086
01087
01088
01089
01090
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
01109
01110
01111
01112
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
01130
01131
01132
01133
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
01151
01152
01153
01154
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
01172
01173
01174
01175
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
01193
01194
01195
01196
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
01214
01215
01216
01217
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
01235
01236
01237
01238
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
01256
01257
01258
01259
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
01277
01278
01279
01280
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
01298
01299
01300
01301
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
01319
01320
01321
01322
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
01340
01341
01342
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 }