127
127
/*----------------------------------------------------------------------------*/
129
129
* \brief Constructor.
130
* \param prog_name Force the name of the program.
132
claw::arguments_table::arguments_table( const std::string& prog_name )
133
: m_arguments(prog_name)
136
} // arguments_table::arguments_table()
138
/*----------------------------------------------------------------------------*/
140
* \brief Constructor.
130
141
* \param argc Number of arguments.
131
142
* \param argv Arguments.
133
144
* All supported arguments will be removed from argv.
135
146
claw::arguments_table::arguments_table( int& argc, char** &argv )
136
: m_arguments(argc, argv)
147
: m_arguments(argc, argv, claw::math::ordered_set<std::string>() )
139
150
} // arguments_table::arguments_table()
230
241
std::cout << m_arguments.get_program_name();
232
std::list<argument_attributes> optional;
233
std::list<argument_attributes>::const_iterator it_opt;
234
math::ordered_set<argument_attributes>::const_iterator it;
243
typedef math::ordered_set<argument_attributes>::const_iterator set_iterator;
245
std::list<set_iterator> optional;
246
std::list<set_iterator>::const_iterator it_opt;
236
249
for (it=m_short_arguments.begin(); it!=m_short_arguments.end(); ++it)
237
250
if ( it->is_optional() )
238
optional.push_back(*it);
251
optional.push_back(it);
240
253
std::cout << " " << it->format_short_help();
242
255
for (it=m_long_arguments.begin(); it!=m_long_arguments.end(); ++it)
243
if (it->get_second_name() == "")
256
if (it->get_second_name().empty())
245
258
if ( it->is_optional() )
246
optional.push_back(*it);
259
optional.push_back(it);
248
261
std::cout << " " << it->format_short_help();
251
264
for (it_opt=optional.begin(); it_opt!=optional.end(); ++it_opt)
252
std::cout << " " << it_opt->format_short_help();
265
std::cout << " " << (*it_opt)->format_short_help();
254
if ( free_args != "" )
267
if ( !free_args.empty() )
255
268
std::cout << " " << free_args;
257
270
std::cout << "\n\n";
314
327
/*----------------------------------------------------------------------------*/
329
* \brief Tell if only integer values are associated to an argument.
330
* \param arg_name The name of the argument to test.
333
claw::arguments_table::only_integer_values( const std::string& arg_name ) const
336
std::string short_name, long_name;
338
get_argument_names( arg_name, short_name, long_name );
340
if ( short_name.empty() && long_name.empty() )
344
if ( !short_name.empty() )
345
result = m_arguments.only_integer_values(short_name);
347
if ( !long_name.empty() )
348
result = result && m_arguments.only_integer_values(long_name);
352
} // arguments_table::only_integer_values()
354
/*----------------------------------------------------------------------------*/
356
* \brief Tell if only real values are associated to an argument.
357
* \param arg_name The name of the argument to test.
360
claw::arguments_table::only_real_values( const std::string& arg_name ) const
363
std::string short_name, long_name;
365
get_argument_names( arg_name, short_name, long_name );
367
if ( short_name.empty() && long_name.empty() )
371
if ( !short_name.empty() )
372
result = m_arguments.only_real_values(short_name);
374
if ( !long_name.empty() )
375
result = result && m_arguments.only_real_values(long_name);
379
} // arguments_table::only_real_values()
381
/*----------------------------------------------------------------------------*/
316
383
* \brief Get the name of the program.
318
385
const std::string& claw::arguments_table::get_program_name() const
398
465
/*----------------------------------------------------------------------------*/
467
* \brief Get all integer values of an argument.
468
* \param arg_name The name of the argument to get.
471
claw::arguments_table::get_all_of_integer( const std::string& arg_name ) const
473
std::list<int> result;
474
std::string short_name, long_name;
476
get_argument_names( arg_name, short_name, long_name );
478
if ( !short_name.empty() )
479
result = m_arguments.get_all_of_integer(short_name);
481
if ( !long_name.empty() )
483
const std::list<int> p(m_arguments.get_all_of_integer(long_name));
484
result.insert( result.end(), p.begin(), p.end() );
488
} // arguments_table::get_all_of_integer()
490
/*----------------------------------------------------------------------------*/
492
* \brief Get all real values of an argument.
493
* \param arg_name The name of the argument to get.
496
claw::arguments_table::get_all_of_real( const std::string& arg_name ) const
498
std::list<double> result;
499
std::string short_name, long_name;
501
get_argument_names( arg_name, short_name, long_name );
503
if ( !short_name.empty() )
504
result = m_arguments.get_all_of_real(short_name);
506
if ( !long_name.empty() )
508
const std::list<double> p(m_arguments.get_all_of_real(long_name));
509
result.insert( result.end(), p.begin(), p.end() );
513
} // arguments_table::get_all_of_real()
515
/*----------------------------------------------------------------------------*/
517
* \brief Get all string values of an argument.
518
* \param arg_name The name of the argument to get.
520
std::list<std::string>
521
claw::arguments_table::get_all_of_string( const std::string& arg_name ) const
523
std::list<std::string> result;
524
std::string short_name, long_name;
526
get_argument_names( arg_name, short_name, long_name );
528
if ( !short_name.empty() )
529
result = m_arguments.get_all_of_string(short_name);
531
if ( !long_name.empty() )
533
const std::list<std::string> p(m_arguments.get_all_of_string(long_name));
534
result.insert( result.end(), p.begin(), p.end() );
538
} // arguments_table::get_all_of_string()
540
/*----------------------------------------------------------------------------*/
400
542
* \brief Add an argument in our list.
402
544
* You can use this method to set default values to the parameters of your