58 mData = strdup( str );
59 for(
char* i = strtok(
mData, separator ); i; i = strtok( 0, separator ) )
71 const char* last = copy.
mOptions.back();
72 const char* endptr = last + strlen( last ) + 1;
73 size_t len = endptr - copy.
mData;
74 mData = (
char*)malloc( len );
76 for(
size_t i = 0; i <
mOptions.size(); ++i )
85 if(
this == © )
return *
this;
93 const char* last = copy.
mOptions.back();
94 const char* endptr = last + strlen( last ) + 1;
95 size_t len = endptr - copy.
mData;
96 mData = (
char*)malloc( len );
98 for(
size_t i = 0; i <
mOptions.size(); ++i )
130 long int pval = strtol( s, &endptr, 0 );
156 long int pval = strtol( s, &endptr, 0 );
180 long int sval = strtol( s, &endptr, 0 );
182 #define EATSPACE( a ) \
183 while( ( *( a ) == ' ' || *( a ) == ',' ) && !strempty( a ) ) \
186 long int eval = sval;
191 eval = strtol( s, &endptr, 0 );
201 for(
int i = sval; i <= eval; i++ )
202 values.push_back( i );
223 double sval = strtod( s, &endptr );
226 values.push_back( sval );
245 value = strtod( s, &endptr );
262 char separator[3] = {
' ',
',',
'\0' };
263 char* tmp_str = strdup( s );
264 for(
char* i = strtok( tmp_str, separator ); i; i = strtok( 0, separator ) )
266 values.push_back( std::string( i ) );
294 std::vector< const char* >::const_iterator i;
297 const char* opt = *i;
300 value = opt + strlen( name );
303 if( *value ==
'=' ) ++value;
316 const char* array[] = { value, NULL };
326 for( index = 0; values[index]; ++index )
335 static const char* values[] = {
"true",
"yes",
"1",
"on",
"false",
"no",
"0",
"off", 0 };
336 const int num_true = 4;
342 value = index < num_true;
346 value = default_value;
359 while( !
strempty( name ) && toupper( *name ) == toupper( *option ) )
390 std::vector< bool >::iterator i = std::find(
mSeen.begin(),
mSeen.end(),
false );
391 if( i ==
mSeen.end() )
398 const char* end = strchr( opt,
'=' );
399 name = end ? std::string( opt, end - opt ) : std::string( opt );
407 using namespace moab;
412 if( MB_SUCCESS != ( A ) ) \
414 std::cerr << "Failure at line " << __LINE__ << ": error code " << ( A ) << std::endl; \
418 #define EQUAL( A, B ) \
419 if( ( A ) != ( B ) ) \
421 std::cerr << "Failure at line " << __LINE__ << ": expected " << ( B ) << " but got " << ( A ) << std::endl; \
427 FileOptions tool(
"INT1=1;NUL1;STR1=ABC;DBL1=1.0;dbl2=2.0;DBL3=3.0;INT2=2;nul2;NUL3;INT3=3;str2=once upon a "
428 "time;str3==fubar=;;INTS=1-3,5,6;DBLS=1.0,2.0, 3.0;STRS=var1, var2_var2;STRS2=" );
436 rval = tool.get_option(
"STR1", s );
441 rval = tool.get_option(
"STR1", s );
446 rval = tool.get_option(
"NUL2", s );
448 EQUAL( s.empty(),
true );
451 rval = tool.get_null_option(
"nul1" );
455 rval = tool.get_null_option(
"INT1" );
459 rval = tool.get_int_option(
"int1", i );
463 rval = tool.get_int_option(
"int2", i );
468 rval = tool.get_int_option(
"dbl2", i );
472 rval = tool.get_int_option(
"NUL3", i );
476 rval = tool.get_real_option(
"dbl1", d );
480 rval = tool.get_real_option(
"dbl2", d );
484 rval = tool.get_real_option(
"int3", d );
489 rval = tool.get_real_option(
"str2", d );
493 rval = tool.get_real_option(
"NUL3", d );
497 rval = tool.get_str_option(
"DBL3", s );
502 rval = tool.get_str_option(
"STR2", s );
504 EQUAL( s,
"once upon a time" );
507 rval = tool.get_str_option(
"nul3", s );
511 EQUAL(
false, tool.all_seen() );
512 rval = tool.get_unseen_option( s );
518 rval = tool.get_option(
"NUL3", s );
520 EQUAL( s.empty(),
true );
522 rval = tool.get_option(
"STR3", s );
524 EQUAL( s,
"=fubar=" );
527 unsigned l = tool.size();
531 std::vector< int > ivals;
532 rval = tool.get_ints_option(
"INTS", ivals );
534 EQUAL( 5, ivals.size() );
535 EQUAL( 1, ivals[0] );
536 EQUAL( 2, ivals[1] );
537 EQUAL( 3, ivals[2] );
538 EQUAL( 5, ivals[3] );
539 EQUAL( 6, ivals[4] );
542 std::vector< double > vals;
543 rval = tool.get_reals_option(
"DBLS", vals );
545 EQUAL( 3, vals.size() );
546 EQUAL( 1.0, vals[0] );
547 EQUAL( 2.0, vals[1] );
548 EQUAL( 3.0, vals[2] );
551 std::vector< std::string > svals;
552 rval = tool.get_strs_option(
"STRS", svals );
554 EQUAL( 2, svals.size() );
555 EQUAL(
"var1", svals[0] );
556 EQUAL(
"var2_var2", svals[1] );
559 rval = tool.get_strs_option(
"STRS2", svals );
563 EQUAL(
true, tool.all_seen() );
564 rval = tool.get_unseen_option( s );
574 EQUAL(
false, tool2.all_seen() );
575 rval = tool2.get_unseen_option( s );
579 rval = tool2.get_option(
"opt1", s );
583 rval = tool2.get_option(
"opt2", s );
592 EQUAL(
true, tool2.all_seen() );
593 rval = tool2.get_unseen_option( s );
603 EQUAL(
true, tool3.all_seen() );
610 EQUAL(
true, tool4.all_seen() );
617 EQUAL(
true, tool5.all_seen() );
623 rval = tool6.get_option(
"opt1", s );
627 rval = tool6.get_option(
"opt2", s );
645 EQUAL( tool8.size(), tool.size() );