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 ) ;
120 return m_map.contains( m_spec.lookup(c) ) ;
125 return m_map.contains( name ) ;
130 return m_map.count(name) ;
135 G_ASSERT( contains(c) ) ;
136 return value( m_spec.lookup(c) , default_ ) ;
139 std::string
G::GetOpt::value(
const std::string & name ,
const std::string & default_ )
const
141 return m_map.contains(name) ? m_map.value(name) : default_ ;
151 return m_errors.size() != 0U ;
156 showErrors( stream , m_args.prefix() +
": error" ) ;
161 for( StringArray::const_iterator p = m_errors.begin() ; p != m_errors.end() ; ++p )
163 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).
size_t count(const std::string &option_name) const
Returns the number of times the option was supplied.
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.
const OptionMap & map() const
Returns a reference to the OptionMap sub-object.
A multimap-like container for command-line options and their values.
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.
const Options & options() const
Returns a reference to the option specification sub-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.