8 #ifndef MUTILS_COMMANDLINE_H 9 #define MUTILS_COMMANDLINE_H 94 std::string::size_type pos = 0;
95 while (pos < key.size()) {
96 key[pos] = toupper(key[pos]);
97 pos = key.find_first_of(
'-', pos);
98 if (pos !=
npos) { key.erase(pos, 1); }
106 std::string src =
"CommandLine[";
126 void init(
int argc,
char *argv[],
const std::vector<Option> *opts);
136 unsigned nMax = -1)
const;
140 unsigned nMax = -1)
const;
143 unsigned getOption(
const std::string &longName,
145 unsigned nMax = -1)
const;
154 size_t popOption(
const std::string &longName);
160 long getInteger(
char shortName,
long defValue)
const;
163 double getDouble(
char shortName,
double defValue)
const;
166 std::string
getString(
char shortName,
const std::string &defValue)
const;
169 void merge(Options &options)
const;
172 void usage(FILE *f,
const std::vector<Option> &opts,
173 const char *args =
"",
174 bool quiet =
false,
bool basename =
true)
const;
181 typedef std::multimap<std::string, std::string>
LongMap;
184 bool parseShort(
const char *name,
const char *next);
187 bool parseLong(
const char *name,
const char *next);
207 #endif // MUTILS_COMMANDLINE_H std::string valueName
Value name (for --help).
unsigned getOption(const Option &option, Arguments *values=nullptr, unsigned nMax=-1) const
Retrieves all copies of a command line option.
Command line option specification.
const Arguments & arguments() const
Returns remaining arguments (read-only).
Command line options and arguments.
std::string longName
Long option name.
~CommandLine()
Destructor.
std::string getString(char shortName, const std::string &defValue) const
Retrieves unique string option.
std::string scopeName
Associated Options scope name.
std::vector< std::string > Arguments
Command line arguments type.
void merge(Options &options) const
Merges command line into options dictionary.
std::multimap< std::string, std::string > LongMap
Long option map type.
size_t popOption(const Option &option)
Removes and destroys all copies of a command line option.
const std::string nullStr(1, 0)
const std::vector< Option > * validOpts_
Recognized command line options.
bool parseLong(const char *name, const char *next)
Processes a long option (possibly with a value).
std::multimap< char, std::string > ShortMap
Short option map type.
bool parseShort(const char *name, const char *next)
Processes one or more short options (the last possibly with a value).
The MathUtils miscellaneous utilities library.
std::string::size_type npos
std::string driver_
Invoked driver program name (argv[0] value).
std::string helpText
Option description (for --help).
std::string sectName
Associated Options section name.
void init(int argc, char *argv[], const std::vector< Option > *opts)
Initializes new command line input.
std::string keyword() const
Standard Options keyword name for this option.
const std::string & driver() const
Returns invoked driver program name (read-only).
LongMap longOpts_
Long option map.
std::string keyName
Associated Options keyword name.
void usage(FILE *f, const std::vector< Option > &opts, const char *args="", bool quiet=false, bool basename=true) const
Summarizes command line usage (including options).
std::string source() const
Command line option source information (for Options::MetaValues).
long getInteger(char shortName) const
Retrieves unique decimal integer option.
ShortMap shortOpts_
Short option map.
char shortName
Short option name.
double getDouble(char shortName, double defValue) const
Retrieves unique floating point option.
Arguments args_
Trailing command line arguments.
CommandLine()
Default constructor.