43 claw::arguments_table::argument_attributes::argument_attributes
44 (
const std::string& name,
const std::string& second_name,
45 const std::string& help_message,
bool optional,
46 const std::string& value_type )
47 : m_name(name), m_second_name(second_name), m_help_message(help_message),
48 m_optional(optional), m_value_type(value_type)
58 bool claw::arguments_table::argument_attributes::operator<
59 (
const argument_attributes& that )
const
61 return m_name < that.m_name;
69 claw::arguments_table::argument_attributes::format_short_help()
const
71 std::string result(m_name);
73 if (!m_value_type.empty())
74 result +=
"=" + m_value_type;
77 return "[" + result +
"]";
86 std::string claw::arguments_table::argument_attributes::format_long_help()
const
88 std::string result(m_name);
90 if ( !m_second_name.empty() )
91 result +=
", " + m_second_name;
93 return result +
"\t" + m_help_message;
100 const std::string& claw::arguments_table::argument_attributes::get_name()
const
110 claw::arguments_table::argument_attributes::get_second_name()
const
112 return m_second_name;
119 bool claw::arguments_table::argument_attributes::is_optional()
const
133 : m_arguments(prog_name)
147 : m_arguments(argc, argv, claw::math::ordered_set<std::string>() )
162 const std::string& long_name,
163 const std::string& help_msg,
bool optional,
164 const std::string& val_name )
166 m_short_arguments.insert( argument_attributes(short_name, long_name, help_msg,
167 optional, val_name) );
168 m_long_arguments.insert( argument_attributes(long_name, short_name, help_msg,
169 optional, val_name) );
181 const std::string& help_msg,
183 const std::string& val_name )
185 m_long_arguments.insert( argument_attributes(long_name,
"", help_msg,
186 optional, val_name) );
198 const std::string& help_msg,
200 const std::string& val_name )
202 m_short_arguments.insert( argument_attributes(short_name,
"", help_msg,
203 optional, val_name) );
219 for (it=m_short_arguments.begin(); it!=m_short_arguments.end(); ++it)
220 allowed.
insert(it->get_name());
222 for (it=m_long_arguments.begin(); it!=m_long_arguments.end(); ++it)
223 allowed.
insert(it->get_name());
225 m_arguments.parse( argc, argv, allowed );
241 std::cout << m_arguments.get_program_name();
245 std::list<set_iterator> optional;
246 std::list<set_iterator>::const_iterator it_opt;
249 for (it=m_short_arguments.begin(); it!=m_short_arguments.end(); ++it)
250 if ( it->is_optional() )
251 optional.push_back(it);
253 std::cout <<
' ' << it->format_short_help();
255 for (it=m_long_arguments.begin(); it!=m_long_arguments.end(); ++it)
256 if (it->get_second_name().empty())
258 if ( it->is_optional() )
259 optional.push_back(it);
261 std::cout <<
' ' << it->format_short_help();
264 for (it_opt=optional.begin(); it_opt!=optional.end(); ++it_opt)
265 std::cout <<
' ' << (*it_opt)->format_short_help();
267 if ( !free_args.empty() )
268 std::cout <<
' ' << free_args;
272 for (it=m_short_arguments.begin(); it!=m_short_arguments.end(); ++it)
273 std::cout <<
"\t" << it->format_long_help() << std::endl;
275 for (it=m_long_arguments.begin(); it!=m_long_arguments.end(); ++it)
276 if (it->get_second_name().empty())
277 std::cout <<
"\t" << it->format_long_help() << std::endl;
294 for (it=m_short_arguments.begin(); (it!=m_short_arguments.end()) && ok; ++it)
295 if ( !it->is_optional() )
296 ok = ok && has_value(it->get_name());
298 for (it=m_long_arguments.begin(); (it!=m_long_arguments.end()) && ok; ++it)
299 if ( !it->is_optional() )
300 ok = ok && has_value(it->get_name());
313 std::string short_name, long_name;
315 get_argument_names( arg_name, short_name, long_name );
317 if ( !short_name.empty() )
318 result = m_arguments.has_value(short_name);
321 if ( !long_name.empty() )
322 result = m_arguments.has_value(long_name);
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);
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);
387 return m_arguments.get_program_name();
397 std::string short_name, long_name;
399 get_argument_names( arg_name, short_name, long_name );
401 return m_arguments.get_bool(short_name) || m_arguments.get_bool(long_name);
414 std::string short_name, long_name;
416 get_argument_names( arg_name, short_name, long_name );
418 if ( m_arguments.has_value(short_name) )
419 return m_arguments.get_integer(short_name);
421 return m_arguments.get_integer(long_name);
434 std::string short_name, long_name;
436 get_argument_names( arg_name, short_name, long_name );
438 if ( m_arguments.has_value(short_name) )
439 return m_arguments.get_real(short_name);
441 return m_arguments.get_real(long_name);
455 std::string short_name, long_name;
457 get_argument_names( arg_name, short_name, long_name );
459 if ( m_arguments.has_value(short_name) )
460 return m_arguments.get_string(short_name);
462 return m_arguments.get_string(long_name);
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() );
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() );
520 std::list<std::string>
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() );
552 m_arguments.add_argument( arg );
562 void claw::arguments_table::get_argument_names
563 (
const std::string& arg_name, std::string& short_name,
564 std::string& long_name )
const
566 argument_attributes attr(arg_name,
"",
"",
false,
"");
570 it = m_short_arguments.find( attr );
572 if (it != m_short_arguments.end())
574 short_name = arg_name;
575 long_name = it->get_second_name();
580 it = m_long_arguments.find( attr );
582 if (it != m_long_arguments.end())
584 short_name = it->get_second_name();
585 long_name = arg_name;