36 m_parser(m_spec,m_map,m_errors)
44 m_parser(m_spec,m_map,m_errors)
53 m_args =
Arg( args_in ) ;
58 void G::GetOpt::parseArgs(
Arg & args )
60 size_t pos = m_parser.parse( args.
array() ) ;
62 m_args.removeAt( 1U , pos-2U ) ;
69 std::string filename = m_args.v( n ) ;
70 m_args.removeAt( n ) ;
72 if( !filename.empty() )
73 addOptionsFromFile( filename ) ;
81 for( StringMap::const_iterator p = map.begin() ; p != map.end() ; ++p )
83 std::string key = (*p).first ;
84 std::string value = (*p).second ;
85 if( m_spec.valued(key) )
87 result.push_back(
"--" + key ) ;
88 result.push_back( value ) ;
92 result.push_back(
"--" + key +
"=" + value ) ;
100 m_parser.parse( optionsFromFile(filename) , 0U ) ;
115 return m_map.contains( m_spec.lookup(c) ) ;
120 return m_map.contains( name ) ;
125 return m_map.count( name ) ;
130 G_ASSERT( contains(c) ) ;
131 return value( m_spec.lookup(c) , default_ ) ;
134 std::string
G::GetOpt::value(
const std::string & name ,
const std::string & default_ )
const
136 return m_map.contains(name) ? m_map.value(name) : default_ ;
146 return m_errors.size() != 0U ;
151 showErrors( stream , m_args.prefix() +
": error" ) ;
156 for( StringArray::const_iterator p = m_errors.begin() ; p != m_errors.end() ; ++p )
158 stream << prefix_1 << prefix_2 << *p << std::endl ;
void showErrors(std::ostream &stream, std::string prefix_1, std::string prefix_2=std::string(": ")) const
A convenience function which streams out each errorList() item to the given stream, prefixed with the given prefix(es).
StringArray errorList() const
Returns the list of errors.
bool hasErrors() const
Returns true if there are errors.
std::vector< std::string > StringArray
A std::vector of std::strings.
void addOptionsFromFile(size_type n=1U)
Adds options from the config file named by the n'th non-option command-line argument (zero-based but ...
StringArray array(unsigned int shift=0U) const
Returns the arguments a string array, including the program name in the first position.
Arg args() const
Returns all the non-option command-line arguments.
unsigned int count(const std::string &option_name) const
Returns the number of times the option was supplied.
const Options & options() const
Returns a reference to the internal option specification object.
GetOpt(const Arg &arg, const std::string &spec)
Constructor taking a Arg reference and a G::Options specification string.
std::string value(const std::string &option_name, const std::string &default_=std::string()) const
Returns the value related to the option identified by its long-form name.
std::map< std::string, std::string > StringMap
A std::map of std::strings.
A class which holds a represention of the argc/argv command line array, and supports simple command-l...
bool contains(char option_letter) const
Returns true if the command line contains the option identified by its short-form letter...
void reload(const StringArray &arg)
Reinitialises the object with the given command-line arguments.
A class to represent allowed command-line options and to provide command-line usage text...
A Path object represents a file system path.