00001
00002
00003
00004
00007
00009
00010 #ifndef __X3DFIELDCONVERSION_H__
00011 #define __X3DFIELDCONVERSION_H__
00012
00013 #include <sstream>
00014 #include "Exception.h"
00015 #include "H3DTypes.h"
00016 #include "PixelImage.h"
00017
00018 using namespace std;
00019
00020 namespace H3D {
00021 namespace X3D {
00025 namespace Convert {
00032 H3D_VALUE_EXCEPTION( const string, X3DFieldConversionError );
00033
00040 H3D_VALUE_EXCEPTION( const string, UnimplementedConversionType );
00041
00047 inline const char *skipWhitespaces( const char *s ) {
00048 int i = 0;
00049 while( isspace(s[i]) && s[i]!='\0' ) {
00050 i++;
00051 }
00052 return s+i;
00053 }
00054
00060 inline const char *skipWhitespacesAndCommas( const char *s ) {
00061 int i = 0;
00062 while( true ) {
00063 if( s[i] == ',' || isspace(s[i] ) ) {
00064 i++;
00065 } else {
00066 break;
00067 }
00068 }
00069 return s+i;
00070 }
00071
00075 inline string getQuoteEnclosedStringValue( const char *s,
00076 const char *&rest ) {
00077 int i = 0;
00078 if( s[0] != '\"' ) {
00079 throw X3DFieldConversionError( "string" );
00080 }
00081 i++;
00082 while( s[i] !='\"' && s[i]!='\0' ) {
00083 i++;
00084 }
00085 if( s[i] != '\"' ) {
00086 throw X3DFieldConversionError( "string" );
00087 }
00088 char *new_s = new char[i+1];
00089 strncpy( new_s, &s[1], i-1 );
00090 new_s[i-1] = '\0';
00091 string ret( new_s );
00092 delete new_s;
00093 rest = &s[ i + 1 ];
00094 return ret;
00095 }
00096
00107 template< class Type >
00108 inline Type getValue( const char *s, const char *&rest ) {
00109 throw UnimplementedConversionType( typeid( Type ).name(),
00110 "" );
00111 }
00112
00113
00119 template<>
00120 inline string getValue<string>( const char *s, const char *&rest ) {
00121 string str( s );
00122 rest = &s[ str.length() ];
00123 return str;
00124 }
00125
00131 template<>
00132 inline bool getValue<bool>( const char *s, const char *&rest ) {
00133 int i = 0;
00134
00135 while( isspace(s[i]) && s[i]!='\0' ) {
00136 i++;
00137 }
00138 if( strncmp( s, "true", 4 ) == 0 ||
00139 strncmp( s, "TRUE", 4 ) == 0 ) {
00140 rest = &s[i+4];
00141 return true;
00142 }
00143 else if( strncmp( s, "false", 5 ) == 0 ||
00144 strncmp( s, "FALSE", 5 ) == 0) {
00145 rest = &s[i+5];
00146 return false;
00147 }
00148 throw X3DFieldConversionError( "bool" );
00149 }
00150
00156 template<>
00157 inline double getValue<double>( const char *s, const char *&rest ) {
00158
00159
00160 int i = 0;
00161 bool negative = false;
00162 unsigned long integer_part = 0;
00163 double fractional_part = 0;
00164 bool valid = false;
00165 while( isspace(s[i]) && s[i]!='\0' ) {
00166 i++;
00167 }
00168 if( s[i] == '+' ) {
00169 i++;
00170 } else if( s[i] == '-' ) {
00171 i++;
00172 negative = true;
00173 }
00174 while( isdigit( s[i] ) && s[i]!='\0' ) {
00175 integer_part = 10 * integer_part + ( s[i] - '0' );
00176 i++;
00177 valid = true;
00178 }
00179 if( s[i] == '.' ) {
00180 i++;
00181 unsigned int divider = 10;
00182 while( isdigit( s[i] ) && s[i]!='\0' ) {
00183 fractional_part = fractional_part + (double)( s[i] - '0' ) / divider;
00184 divider *= 10;
00185 valid = true;
00186 i++;
00187 }
00188 }
00189 int saved_i = i;
00190 int exponent = 0;
00191 bool exponent_negative = false;
00192 if( s[i] == 'd' || s[i] == 'D' || s[i] == 'e' || s[i] == 'E' ) {
00193 i++;
00194 if( s[i] == '+' ) {
00195 i++;
00196 } else if ( s[i] == '-' ) {
00197 i++;
00198 exponent_negative = true;
00199 }
00200
00201 int before_digit = i;
00202 while( isdigit( s[i] ) && s[i]!='\0' ) {
00203 exponent = 10 * exponent + ( s[i] - '0' );
00204 i++;
00205 }
00206
00207
00208 if( i == before_digit ) {
00209 i = saved_i;
00210 exponent = 0;
00211 } else {
00212 if( exponent_negative ) {
00213 exponent = -exponent;
00214 }
00215 }
00216 }
00217
00218 if( !valid ) {
00219 throw X3DFieldConversionError( "double" );
00220 } else {
00221 rest = &s[i];
00222 double res = integer_part + fractional_part;
00223 if( negative ) res = -res;
00224 if( exponent != 0 ) res = res * H3DPow( 10, exponent );
00225 return res;
00226 }
00227 }
00228
00234 template<>
00235 inline float getValue<float>( const char *s, const char *&rest ) {
00236 return (float)getValue<double>( s, rest );
00237 }
00238
00244 template<>
00245 inline int getValue<int>( const char *s, const char *&rest ) {
00246 int i = 0;
00247 bool valid = false;
00248
00249 while( isspace(s[i]) && s[i]!='\0' ) {
00250 i++;
00251 }
00252 if( s[0] == '0' && s[1] == 'x' ) {
00253 i+=2;
00254
00255 int max_index = i + 8;
00256 int return_value = 0;
00257 int pos_value;
00258 for( ; i < max_index; i++ ) {
00259 if (s[i]=='\0')
00260 break;
00261 if (s[i] > 0x29 && s[i] < 0x40 )
00262 pos_value = s[i] & 0x0f;
00263 else if (s[i] >='a' && s[i] <= 'f')
00264 pos_value= (s[i] & 0x0f) + 9;
00265 else if (s[i] >='A' && s[i] <= 'F')
00266 pos_value = (s[i] & 0x0f) + 9;
00267 else break;
00268
00269 valid = true;
00270 return_value = return_value << 4;
00271 return_value = return_value | pos_value;
00272 }
00273 if( !valid ) {
00274 throw X3DFieldConversionError( "int" );
00275 } else {
00276 rest = &s[i];
00277 return return_value;
00278 }
00279 } else {
00280
00281
00282 bool negative = false;
00283
00284 if( s[i] == '+' ) {
00285 i++;
00286 } else if ( s[i] == '-' ) {
00287 negative = true;
00288 i++;
00289 }
00290
00291 int result = 0;
00292 while( isdigit( s[i] ) && s[i]!='\0' ) {
00293 result = 10 * result + ( s[i] - '0' );
00294 i++;
00295 valid = true;
00296 }
00297
00298 if( !valid ) {
00299 throw X3DFieldConversionError( "int" );
00300 } else {
00301 rest = &s[i];
00302 if( negative ) result = -result;
00303 return result;
00304 }
00305 }
00306 }
00307
00313 template<>
00314 inline RGB getValue<RGB>( const char *s, const char *&rest ) {
00315 RGB color;
00316 const char *t1, *t2;
00317 color.r = getValue<H3DFloat>( s, t1 );
00318 if( !isspace(t1[0]) ) {
00319 throw X3DFieldConversionError( "RGB" );
00320 }
00321 color.g = getValue<H3DFloat>( t1, t2 );
00322 if( !isspace(t2[0]) ) {
00323 throw X3DFieldConversionError( "RGB" );
00324 }
00325 color.b = getValue<H3DFloat>( t2, rest );
00326 return color;
00327 }
00328
00334 template<>
00335 inline RGBA getValue<RGBA>( const char *s, const char *&rest ) {
00336 RGBA color;
00337 const char *t1, *t2;
00338 color.r = getValue<H3DFloat>( s, t1 );
00339 if( !isspace(t1[0]) ) {
00340 throw X3DFieldConversionError( "RGBA" );
00341 }
00342 color.g = getValue<H3DFloat>( t1, t2 );
00343 if( !isspace(t2[0]) ) {
00344 throw X3DFieldConversionError( "RGBA" );
00345 }
00346 color.b = getValue<H3DFloat>( t2, t1 );
00347 if( !isspace(t1[0]) ) {
00348 throw X3DFieldConversionError( "RGBA" );
00349 }
00350 color.a = getValue<H3DFloat>( t1, rest );
00351 return color;
00352 }
00353
00359 template<>
00360 inline Rotation getValue<Rotation>( const char *s,
00361 const char *&rest ) {
00362 Rotation rot;
00363 const char *t1, *t2;
00364 rot.axis.x = getValue<H3DFloat>( s, t1 );
00365 if( !isspace(t1[0]) ) {
00366 throw X3DFieldConversionError( "Rotation" );
00367 }
00368 rot.axis.y = getValue<H3DFloat>( t1, t2 );
00369 if( !isspace(t2[0]) ) {
00370 throw X3DFieldConversionError( "Rotation" );
00371 }
00372 rot.axis.z = getValue<H3DFloat>( t2, t1 );
00373 if( !isspace(t1[0]) ) {
00374 throw X3DFieldConversionError( "Rotation" );
00375 }
00376 rot.angle = getValue<H3DFloat>( t1, rest );
00377 return rot;
00378 }
00379
00385 template<>
00386 inline Quaternion getValue<Quaternion>( const char *s,
00387 const char *&rest ) {
00388 Quaternion q;
00389 const char *t1, *t2;
00390 q.v.x = getValue<H3DFloat>( s, t1 );
00391 if( !isspace(t1[0]) ) {
00392 throw X3DFieldConversionError( "Quaternion" );
00393 }
00394 q.v.y = getValue<H3DFloat>( t1, t2 );
00395 if( !isspace(t2[0]) ) {
00396 throw X3DFieldConversionError( "Quaternion" );
00397 }
00398 q.v.z = getValue<H3DFloat>( t2, t1 );
00399 if( !isspace(t1[0]) ) {
00400 throw X3DFieldConversionError( "Quaternion" );
00401 }
00402 q.w = getValue<H3DFloat>( t1, rest );
00403 return q;
00404 }
00405
00411 template<>
00412 inline Matrix4f getValue<Matrix4f>( const char *s, const char *&rest ) {
00413 Matrix4f m;
00414 const char *t1, *t2;
00415 m[0][0] = getValue<H3DFloat>( s, t1 );
00416 if( !isspace(t1[0]) ) {
00417 throw X3DFieldConversionError( "Matrix4f" );
00418 }
00419 m[0][1] = getValue<H3DFloat>( t1, t2 );
00420 if( !isspace(t2[0]) ) {
00421 throw X3DFieldConversionError( "Matrix4f" );
00422 }
00423 m[0][2] = getValue<H3DFloat>( t2, t1 );
00424 if( !isspace(t1[0]) ) {
00425 throw X3DFieldConversionError( "Matrix4f" );
00426 }
00427 m[0][3] = getValue<H3DFloat>( t1, t2 );
00428 if( !isspace(t2[0]) ) {
00429 throw X3DFieldConversionError( "Matrix4f" );
00430 }
00431
00432 m[1][0] = getValue<H3DFloat>( t2, t1 );
00433 if( !isspace(t1[0]) ) {
00434 throw X3DFieldConversionError( "Matrix4f" );
00435 }
00436 m[1][1] = getValue<H3DFloat>( t1, t2 );
00437 if( !isspace(t2[0]) ) {
00438 throw X3DFieldConversionError( "Matrix4f" );
00439 }
00440 m[1][2] = getValue<H3DFloat>( t2, t1 );
00441 if( !isspace(t1[0]) ) {
00442 throw X3DFieldConversionError( "Matrix4f" );
00443 }
00444 m[1][3] = getValue<H3DFloat>( t1, t2 );
00445 if( !isspace(t2[0]) ) {
00446 throw X3DFieldConversionError( "Matrix4f" );
00447 }
00448
00449 m[2][0] = getValue<H3DFloat>( t2, t1 );
00450 if( !isspace(t1[0]) ) {
00451 throw X3DFieldConversionError( "Matrix4f" );
00452 }
00453 m[2][1] = getValue<H3DFloat>( t1, t2 );
00454 if( !isspace(t2[0]) ) {
00455 throw X3DFieldConversionError( "Matrix4f" );
00456 }
00457 m[2][2] = getValue<H3DFloat>( t2, t1 );
00458 if( !isspace(t1[0]) ) {
00459 throw X3DFieldConversionError( "Matrix4f" );
00460 }
00461 m[2][3] = getValue<H3DFloat>( t1, t2 );
00462 if( !isspace(t2[0]) ) {
00463 throw X3DFieldConversionError( "Matrix4f" );
00464 }
00465
00466 m[3][0] = getValue<H3DFloat>( t2, t1 );
00467 if( !isspace(t1[0]) ) {
00468 throw X3DFieldConversionError( "Matrix4f" );
00469 }
00470 m[3][1] = getValue<H3DFloat>( t1, t2 );
00471 if( !isspace(t2[0]) ) {
00472 throw X3DFieldConversionError( "Matrix4f" );
00473 }
00474 m[3][2] = getValue<H3DFloat>( t2, t1 );
00475 if( !isspace(t1[0]) ) {
00476 throw X3DFieldConversionError( "Matrix4f" );
00477 }
00478 m[3][3] = getValue<H3DFloat>( t1, rest );
00479
00480 return m;
00481 }
00482
00488 template<>
00489 inline Matrix3f getValue<Matrix3f>( const char *s, const char *&rest ) {
00490 Matrix3f m;
00491 const char *t1, *t2;
00492 m[0][0] = getValue<H3DFloat>( s, t1 );
00493 if( !isspace(t1[0]) ) {
00494 throw X3DFieldConversionError( "Matrix3f" );
00495 }
00496 m[0][1] = getValue<H3DFloat>( t1, t2 );
00497 if( !isspace(t2[0]) ) {
00498 throw X3DFieldConversionError( "Matrix3f" );
00499 }
00500 m[0][2] = getValue<H3DFloat>( t2, t1 );
00501 if( !isspace(t1[0]) ) {
00502 throw X3DFieldConversionError( "Matrix3f" );
00503 }
00504 m[1][0] = getValue<H3DFloat>( t1, t2 );
00505 if( !isspace(t2[0]) ) {
00506 throw X3DFieldConversionError( "Matrix3f" );
00507 }
00508 m[1][1] = getValue<H3DFloat>( t2, t1 );
00509 if( !isspace(t1[0]) ) {
00510 throw X3DFieldConversionError( "Matrix3f" );
00511 }
00512 m[1][2] = getValue<H3DFloat>( t1, t2 );
00513 if( !isspace(t2[0]) ) {
00514 throw X3DFieldConversionError( "Matrix3f" );
00515 }
00516 m[2][0] = getValue<H3DFloat>( t2, t1 );
00517 if( !isspace(t1[0]) ) {
00518 throw X3DFieldConversionError( "Matrix3f" );
00519 }
00520 m[2][1] = getValue<H3DFloat>( t1, t2 );
00521 if( !isspace(t2[0]) ) {
00522 throw X3DFieldConversionError( "Matrix3f" );
00523 }
00524 m[2][2] = getValue<H3DFloat>( t2, rest );
00525
00526 return m;
00527 }
00528
00534 template<>
00535 inline Matrix4d getValue<Matrix4d>( const char *s, const char *&rest ) {
00536 Matrix4d m;
00537 const char *t1, *t2;
00538 m[0][0] = getValue<H3DDouble>( s, t1 );
00539 if( !isspace(t1[0]) ) {
00540 throw X3DFieldConversionError( "Matrix4d" );
00541 }
00542 m[0][1] = getValue<H3DDouble>( t1, t2 );
00543 if( !isspace(t2[0]) ) {
00544 throw X3DFieldConversionError( "Matrix4d" );
00545 }
00546 m[0][2] = getValue<H3DDouble>( t2, t1 );
00547 if( !isspace(t1[0]) ) {
00548 throw X3DFieldConversionError( "Matrix4d" );
00549 }
00550 m[0][3] = getValue<H3DDouble>( t1, t2 );
00551 if( !isspace(t2[0]) ) {
00552 throw X3DFieldConversionError( "Matrix4d" );
00553 }
00554
00555 m[1][0] = getValue<H3DDouble>( t2, t1 );
00556 if( !isspace(t1[0]) ) {
00557 throw X3DFieldConversionError( "Matrix4d" );
00558 }
00559 m[1][1] = getValue<H3DDouble>( t1, t2 );
00560 if( !isspace(t2[0]) ) {
00561 throw X3DFieldConversionError( "Matrix4d" );
00562 }
00563 m[1][2] = getValue<H3DDouble>( t2, t1 );
00564 if( !isspace(t1[0]) ) {
00565 throw X3DFieldConversionError( "Matrix4d" );
00566 }
00567 m[1][3] = getValue<H3DDouble>( t1, t2 );
00568 if( !isspace(t2[0]) ) {
00569 throw X3DFieldConversionError( "Matrix4d" );
00570 }
00571
00572 m[2][0] = getValue<H3DDouble>( t2, t1 );
00573 if( !isspace(t1[0]) ) {
00574 throw X3DFieldConversionError( "Matrix4d" );
00575 }
00576 m[2][1] = getValue<H3DDouble>( t1, t2 );
00577 if( !isspace(t2[0]) ) {
00578 throw X3DFieldConversionError( "Matrix4d" );
00579 }
00580 m[2][2] = getValue<H3DDouble>( t2, t1 );
00581 if( !isspace(t1[0]) ) {
00582 throw X3DFieldConversionError( "Matrix4d" );
00583 }
00584 m[2][3] = getValue<H3DDouble>( t1, t2 );
00585 if( !isspace(t2[0]) ) {
00586 throw X3DFieldConversionError( "Matrix4d" );
00587 }
00588
00589 m[3][0] = getValue<H3DDouble>( t2, t1 );
00590 if( !isspace(t1[0]) ) {
00591 throw X3DFieldConversionError( "Matrix4d" );
00592 }
00593 m[3][1] = getValue<H3DDouble>( t1, t2 );
00594 if( !isspace(t2[0]) ) {
00595 throw X3DFieldConversionError( "Matrix4d" );
00596 }
00597 m[3][2] = getValue<H3DDouble>( t2, t1 );
00598 if( !isspace(t1[0]) ) {
00599 throw X3DFieldConversionError( "Matrix4d" );
00600 }
00601 m[3][3] = getValue<H3DDouble>( t1, rest );
00602
00603 return m;
00604 }
00605
00611 template<>
00612 inline Matrix3d getValue<Matrix3d>( const char *s, const char *&rest ) {
00613 Matrix3d m;
00614 const char *t1, *t2;
00615 m[0][0] = getValue<H3DDouble>( s, t1 );
00616 if( !isspace(t1[0]) ) {
00617 throw X3DFieldConversionError( "Matrix3d" );
00618 }
00619 m[0][1] = getValue<H3DDouble>( t1, t2 );
00620 if( !isspace(t2[0]) ) {
00621 throw X3DFieldConversionError( "Matrix3d" );
00622 }
00623 m[0][2] = getValue<H3DDouble>( t2, t1 );
00624 if( !isspace(t1[0]) ) {
00625 throw X3DFieldConversionError( "Matrix3d" );
00626 }
00627 m[1][0] = getValue<H3DDouble>( t1, t2 );
00628 if( !isspace(t2[0]) ) {
00629 throw X3DFieldConversionError( "Matrix3d" );
00630 }
00631 m[1][1] = getValue<H3DDouble>( t2, t1 );
00632 if( !isspace(t1[0]) ) {
00633 throw X3DFieldConversionError( "Matrix3d" );
00634 }
00635 m[1][2] = getValue<H3DDouble>( t1, t2 );
00636 if( !isspace(t2[0]) ) {
00637 throw X3DFieldConversionError( "Matrix3d" );
00638 }
00639 m[2][0] = getValue<H3DDouble>( t2, t1 );
00640 if( !isspace(t1[0]) ) {
00641 throw X3DFieldConversionError( "Matrix3d" );
00642 }
00643 m[2][1] = getValue<H3DDouble>( t1, t2 );
00644 if( !isspace(t2[0]) ) {
00645 throw X3DFieldConversionError( "Matrix3d" );
00646 }
00647 m[2][2] = getValue<H3DDouble>( t2, rest );
00648
00649 return m;
00650 }
00651
00652
00653
00659 template<>
00660 inline Vec4f getValue<Vec4f>( const char *s, const char *&rest ) {
00661 Vec4f v;
00662 const char *t1, *t2;
00663 v.x = getValue<H3DFloat>( s, t1 );
00664 if( !isspace(t1[0]) ) {
00665 throw X3DFieldConversionError( "Vec4f" );
00666 }
00667 v.y = getValue<H3DFloat>( t1, t2 );
00668 if( !isspace(t2[0]) ) {
00669 throw X3DFieldConversionError( "Vec4f" );
00670 }
00671 v.z = getValue<H3DFloat>( t2, t1 );
00672 if( !isspace(t1[0]) ) {
00673 throw X3DFieldConversionError( "Vec4f" );
00674 }
00675 v.w = getValue<H3DFloat>( t1, rest );
00676 return v;
00677 }
00678
00684 template<>
00685 inline Vec4d getValue<Vec4d>( const char *s, const char *&rest ) {
00686 Vec4d v;
00687 const char *t1, *t2;
00688 v.x = getValue<H3DDouble>( s, t1 );
00689 if( !isspace(t1[0]) ) {
00690 throw X3DFieldConversionError( "Vec4d" );
00691 }
00692 v.y = getValue<H3DDouble>( t1, t2 );
00693 if( !isspace(t2[0]) ) {
00694 throw X3DFieldConversionError( "Vec4d" );
00695 }
00696 v.z = getValue<H3DDouble>( t2, t1 );
00697 if( !isspace(t1[0]) ) {
00698 throw X3DFieldConversionError( "Vec4d" );
00699 }
00700 v.w = getValue<H3DDouble>( t1, rest );
00701 return v;
00702 }
00703
00709 template<>
00710 inline Vec3f getValue<Vec3f>( const char *s, const char *&rest ) {
00711 Vec3f v;
00712 const char *t1, *t2;
00713 v.x = getValue<H3DFloat>( s, t1 );
00714 if( !isspace(t1[0]) ) {
00715 throw X3DFieldConversionError( "Vec3f" );
00716 }
00717 v.y = getValue<H3DFloat>( t1, t2 );
00718 if( !isspace(t2[0]) ) {
00719 throw X3DFieldConversionError( "Vec3f" );
00720 }
00721 v.z = getValue<H3DFloat>( t2, rest );
00722 return v;
00723 }
00724
00730 template<>
00731 inline Vec3d getValue<Vec3d>( const char *s, const char *&rest ) {
00732 Vec3d v;
00733 const char *t1, *t2;
00734 v.x = getValue<H3DDouble>( s, t1 );
00735 if( !isspace(t1[0]) ) {
00736 throw X3DFieldConversionError( "Vec3d" );
00737 }
00738 v.y = getValue<H3DDouble>( t1, t2 );
00739 if( !isspace(t2[0]) ) {
00740 throw X3DFieldConversionError( "Vec3d" );
00741 }
00742 v.z = getValue<H3DDouble>( t2, rest );
00743 return v;
00744 }
00745
00751 template<>
00752 inline Vec2f getValue<Vec2f>( const char *s, const char *&rest ) {
00753 Vec2f v;
00754 const char *t1;
00755 v.x = getValue<H3DFloat>( s, t1 );
00756 if( !isspace(t1[0]) ) {
00757 throw X3DFieldConversionError( "Vec2f" );
00758 }
00759 v.y = getValue<H3DFloat>( t1, rest );
00760 return v;
00761 }
00762
00768 template<>
00769 inline Vec2d getValue<Vec2d>( const char *s, const char *&rest ) {
00770 Vec2d v;
00771 const char *t1;
00772 v.x = getValue<H3DDouble>( s, t1 );
00773 if( !isspace(t1[0]) ) {
00774 throw X3DFieldConversionError( "Vec2d" );
00775 }
00776 v.y = getValue<H3DDouble>( t1, rest );
00777 return v;
00778 }
00779
00780 unsigned char *readImageData( const char *s,
00781 int width,
00782 int height,
00783 int depth,
00784 int nr_components );
00785 }
00786
00794 template< class Type >
00795 Type X3DStringToValue( const string &x3d_string ) {
00796 typedef Convert::X3DFieldConversionError ConversionError;
00797 const char *s = x3d_string.c_str();
00798 const char *t1;
00799 Type value;
00800 try {
00801 s = Convert::skipWhitespaces( s );
00802 value = Convert::getValue<Type>( s, t1 );
00803 s = Convert::skipWhitespaces( t1 );
00804 } catch( const ConversionError & ) {
00805 throw ConversionError( typeid( Type ).name() );
00806 }
00807 if( s[0] != '\0' ) {
00808 throw ConversionError( typeid( Type ).name() );
00809 }
00810 return value;
00811 }
00812
00820 template< class VectorType >
00821 inline void X3DStringToVector( const string &x3d_string,
00822 VectorType &values ) {
00823 typedef Convert::X3DFieldConversionError ConversionError;
00824 const char *s = x3d_string.c_str();
00825 const char *t1;
00826 values.clear();
00827 try {
00828 s = Convert::skipWhitespaces( s );
00829 while( s[0] != '\0' ) {
00830 values.push_back( Convert::getValue<
00831 typename VectorType::value_type >
00832 ( (const char*)s, t1 ) );
00833 s = Convert::skipWhitespacesAndCommas( t1 );
00834 }
00835 } catch( const ConversionError & ) {
00836 stringstream ss;
00837 ss << typeid( typename VectorType::value_type ).name()
00838 << " vector";
00839 throw ConversionError( ss.str() );
00840 }
00841 }
00842
00850 template< >
00851 inline void X3DStringToVector< vector< string > >(
00852 const string &x3d_string,
00853 vector< string > &values ) {
00854 typedef Convert::X3DFieldConversionError ConversionError;
00855 const char *s = x3d_string.c_str();
00856 const char *t1;
00857 values.clear();
00858 try {
00859 s = Convert::skipWhitespaces( s );
00860 if( s[0] != '\"' )
00861 values.push_back( Convert::getValue< string >( s, t1 ) );
00862 else
00863 while( s[0] != '\0' ) {
00864 values.push_back(
00865 Convert::getQuoteEnclosedStringValue( (const char*)s, t1 )
00866 );
00867 s = Convert::skipWhitespacesAndCommas( t1 );
00868 }
00869 } catch( const ConversionError & ) {
00870 stringstream ss;
00871 ss << " string vector";
00872 throw ConversionError( ss.str() );
00873 }
00874 }
00875
00882 PixelImage *X3DStringTo2DImage( const string &x3d_string );
00883
00890 PixelImage *X3DStringTo3DImage( const string &x3d_string );
00891 }
00892 };
00893
00894 #endif