53 : m_program_name(prog_name)
86 parse(argc, argv, allowed);
112 (
int& argc,
char** &argv,
115 parse( argc, argv,
false, allowed );
125 return m_pairs.find( arg_name ) != m_pairs.end();
135 const valued_arguments_map::const_iterator itk(m_pairs.find(arg_name));
138 if ( itk == m_pairs.end() )
142 std::list<std::string>::const_iterator it;
143 for( it=itk->second.begin(); result && (it!=itk->second.end()); ++it )
144 result = result && text::is_of_type<int>(*it);
157 const valued_arguments_map::const_iterator itk(m_pairs.find(arg_name));
160 if ( itk == m_pairs.end() )
164 std::list<std::string>::const_iterator it;
165 for( it=itk->second.begin(); result && (it!=itk->second.end()); ++it )
166 result = result && text::is_of_type<double>(*it);
178 return m_program_name;
188 return m_flags.find( arg_name ) != m_flags.end();
200 "arguments::get_integer(): argument is not set." );
202 std::istringstream iss( m_pairs.find( arg_name )->second.back() );
218 "arguments::get_real(): argument is not set." );
220 std::istringstream iss( m_pairs.find( arg_name )->second.back() );
237 "arguments::get_string(): argument is not set." );
239 return m_pairs.find( arg_name )->second.back();
250 std::list<int> result;
251 const valued_arguments_map::const_iterator itk(m_pairs.find(arg_name));
253 if ( itk != m_pairs.end() )
255 std::list<std::string>::const_iterator it;
257 for( it=itk->second.begin(); it!=itk->second.end(); ++it )
258 if ( text::is_of_type<int>(*it) )
260 std::istringstream iss(*it);
263 result.push_back(val);
278 std::list<double> result;
279 const valued_arguments_map::const_iterator itk(m_pairs.find(arg_name));
281 if ( itk != m_pairs.end() )
283 std::list<std::string>::const_iterator it;
285 for( it=itk->second.begin(); it!=itk->second.end(); ++it )
286 if ( text::is_of_type<double>(*it) )
288 std::istringstream iss(*it);
291 result.push_back(val);
303 std::list<std::string>
306 std::list<std::string> result;
307 const valued_arguments_map::const_iterator itk(m_pairs.find(arg_name));
309 if ( itk != m_pairs.end() )
310 result = itk->second;
327 CLAW_ASSERT( arg !=
"--",
"arguments::add_argument(): arg can't be '--'" );
329 "arguments::add_argument(): arg must begin by '-'" );
331 std::string name, value;
332 const bool has_value = split_argument(arg, name, value);
335 m_flags.insert( arg );
337 m_pairs[name].push_back(value);
353 (
int& argc,
char** &argv,
bool always_allowed,
359 if (m_program_name.empty() && (argc!=0))
361 m_program_name = argv[0];
366 for (
int argi=base; (argi!=argc) && !stop; ++argi)
368 std::string arg(argv[argi]);
371 if ( (arg[0] ==
'-') && (arg.length() > 1) )
377 std::string name, value;
378 const bool has_value = split_argument( arg, name, value );
381 process_boolean( argv[argi], always_allowed, allowed );
382 else if ( always_allowed
383 || (allowed.
find( name ) != allowed.
end()) )
392 remove_null_arguments( argc, argv );
404 bool claw::arguments::split_argument
405 (
const std::string& arg, std::string& name, std::string& value )
const
407 CLAW_ASSERT( arg !=
"--",
"arguments::split_argument(): arg can't be '--'" );
409 "arguments::split_argument(): arg must begin by '-'" );
411 std::string::size_type pos = arg.find_first_of(
'=');
414 if ( pos == std::string::npos )
421 name = arg.substr(0, pos);
422 value = arg.substr(pos+1, arg.length() - pos - 1);
435 void claw::arguments::remove_null_arguments(
int& argc,
char** &argv )
const
439 for (
int i=0; i!=argc; ++i)
440 if ( argv[i] != NULL )
447 while ( (j!=argc) && !ok )
448 if ( argv[j] == NULL )
462 if ( (std::string(argv[c-1]) ==
"--") )
478 void claw::arguments::process_boolean
479 (
char* &arg,
bool always_allowed,
482 CLAW_ASSERT( std::string(arg) !=
"--",
"arg can't be '--'" );
484 "arg must be at least two characters long" );
485 CLAW_ASSERT( arg[0] ==
'-',
"arg must begin by '-'" );
489 if ( always_allowed || (allowed.
find(arg) != allowed.
end()) )
500 while ( arg[i] !=
'\0' )
504 if ( always_allowed || (allowed.
find(s) != allowed.
end()) )
509 for (
int j=i; arg[j]!=
'\0'; ++j )