33 #define ARGCV( A ) ( sizeof( A ) / sizeof( ( A )[0] ) ), const_cast< char** >( A )
35 int main(
int argc,
char* argv[] )
41 setenv(
"MOAB_PROG_OPT_ABORT",
"1", 0 );
66 MPI_Init( &argc, &argv );
79 opts1.
addOpt<
void >(
",s",
"short opt", &value1 );
80 const char* argv1[] = {
"prog",
"-s" };
90 opts2.
addOpt<
void >(
"long,l",
"long opt", &value );
91 const char* argv2[] = {
"prog",
"-l",
"-l" };
103 opts3.
addOpt<
void >(
"long,l",
"long opt", &value );
104 const char* argv3[] = {
"prog",
"--long",
"--long" };
117 const char* argv1[] = {
"test",
"--flag" };
124 const char* argv2[] = {
"test",
"--flag",
"--no-flag" };
131 const char* argv3[] = {
"test",
"--flag",
"--no-flag",
"--flag" };
141 const char* argv1[] = {
"prog",
"-s" };
150 opts.
addOpt(
"long,s",
"my int opt", &val1 );
151 const char* argv[] = {
"test",
"-s",
"2",
"--long",
"-0xA",
"--long=5" };
163 std::vector< int > list;
177 const char* argv[] = {
"test",
"--",
"-1",
"-010" };
186 const double EPS = std::numeric_limits< double >::epsilon();
189 opts.
addOpt(
"long,s",
"my real opt", &val1 );
190 const char* argv[] = {
"test",
"-s",
"2",
"--long",
"2e5",
"--long=-0.01" };
202 std::vector< double > list;
212 const double EPS = std::numeric_limits< double >::epsilon();
217 const char* argv[] = {
"test",
"--",
"-1.2",
"1.01e-3" };
228 opts.
addOpt(
"long,s",
"my first opt", &val1 );
229 opts.
addOpt< std::string >(
"second,2",
"my second opt" );
231 const char* argv[] = {
"test",
"--long",
"2",
"-s",
"foobar",
"-2",
"two",
"--second=testval" };
255 std::vector< std::string > list;
274 const char* argv[] = {
"test",
"my_string",
"with spaces" };
283 std::string exp1 =
"ddd%";
284 std::string exp2 =
"%";
285 std::string exp2b =
"foo%bar";
286 std::string exp3 =
"%string%";
287 std::string exp4 =
"file.%";
290 std::string val1, val2, val3, val4;
291 opts.
addOpt(
",n",
"no subst flag", &val1, 0 );
295 std::string eqflg(
"--dosub=" );
297 const char* argv[] = {
"test", exp3.c_str(), exp4.c_str(),
"-s", exp2b.c_str(),
"-n", exp1.c_str(), eqflg.c_str() };
313 exp2b = std::string(
"foo" ) +
buffer +
"bar";
314 exp4 = std::string(
"file." ) +
buffer;
332 std::vector< std::string > list;
342 std::vector< int > list1, list2;
343 opts.
addOpt(
"ids,d",
"id list", &list1 );
344 const char* argv[] = {
"test",
"--ids=1,2,3",
"--ids",
"4-10",
"-d",
"4-5,2" };
346 const int exp1[] = { 1, 2, 3 };
347 const int exp1_len =
sizeof( exp1 ) /
sizeof( exp1[0] );
348 const int exp2[] = { 4, 5, 6, 7, 8, 9, 10 };
349 const int exp2_len =
sizeof( exp2 ) /
sizeof( exp2[0] );
350 const int exp3[] = { 4, 5, 2 };
351 const int exp3_len =
sizeof( exp3 ) /
sizeof( exp3[0] );
352 std::vector< int > all;
353 std::copy( exp1, exp1 + exp1_len, std::back_inserter( all ) );
354 std::copy( exp2, exp2 + exp2_len, std::back_inserter( all ) );
355 std::copy( exp3, exp3 + exp3_len, std::back_inserter( all ) );
362 std::vector< std::vector< int > > lists;
377 std::vector< int > list1;
379 const char* argv[] = {
"test",
"5,6,-3--1,10" };
381 const int exp1[] = { 5, 6, -3, -2, -1, 10 };
382 const int exp1_len =
sizeof( exp1 ) /
sizeof( exp1[0] );
393 opts1.
addOptionalArgs< std::string >( 0,
"opts",
"optional arguments" );
395 const char* argv1[] = {
"test",
"arg" };
397 std::vector< std::string > list;
400 CHECK( list.empty() );
404 opts2.
addOptionalArgs< std::string >( 0,
"opts",
"optional arguments" );
406 const char* argv2[] = {
"test",
"arg1",
"arg2",
"arg" };
419 std::string
init, fini;
421 opts1.
addOptionalArgs< std::string >( 1,
"mid",
"optional arguments" );
423 const char* argv1[] = {
"test",
"arg1",
"arg2" };
425 std::vector< std::string > list;
429 CHECK( list.empty() );
435 opts2.
addOptionalArgs< std::string >( 1,
"mid",
"optional arguments" );
437 const char* argv2[] = {
"test",
"arg1",
"arg2",
"arg3" };
452 bool flagval =
false;
454 opts.
addOpt<
void >(
",f",
"flag", &flagval );
455 opts.
addOpt(
",i",
"int", &intval );
456 opts.
addOpt(
",r",
"real", &realval );
457 opts.
addOpt(
",s",
"str", &strval );
459 const char* argv[] = {
"test",
"-ifsrff",
"-0xBEEF",
"string",
"-1.0e55" };