mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
Command line options parser.
This is a wrapper for the "The Lean Mean C++ Option Parser" command line parser.
Definition at line 58 of file clOptions.hpp.
#include <app/clOptions.hpp>
Public Member Functions | |
~clOptions () | |
D'tor. Deletes the options and buffer pointers. More... | |
void | clear () |
Clear the memory held by this object. More... | |
void | add (const std::string &optName, const char *const shortOpt, const char *const longOpt, int argT) |
Add a command line option target. More... | |
void | parse (int argc, char **argv, std::vector< std::string > *nonOptions=0) |
Parse the command line. More... | |
const char * | operator[] (const std::string &key) |
Get the value of the option, if present. More... | |
int | count (const std::string &key) |
Get the number of times the option was set on the command line. More... | |
void | getAll (std::vector< std::string > &args, const std::string &key) |
Fill a vector of strings with the arguments supplied for key, last to first. More... | |
bool | optSet (const std::string &key) |
Test whether this option was set. More... | |
int | numUnknown () |
Get the number of unknown options found by the parser. More... | |
int | unknown (std::vector< std::string > &unk) |
Get a vector of the unknown options found by the parser. More... | |
Public Attributes | |
unsigned int | nOpts {0} |
The number of options added. More... | |
mx::app::clOptions::~clOptions | ( | ) |
D'tor. Deletes the options and buffer pointers.
Definition at line 52 of file clOptions.cpp.
void mx::app::clOptions::add | ( | const std::string & | optName, |
const char *const | shortOpt, | ||
const char *const | longOpt, | ||
int | argT | ||
) |
Add a command line option target.
[in] | optName | The name of the option, used as its key |
[in] | shortOpt | The short option character |
[in] | longOpt | The long option keyword |
[in] | argT | The option type |
Definition at line 71 of file clOptions.cpp.
Referenced by mx::app::appConfigurator::parseCommandLine().
void mx::app::clOptions::clear | ( | ) |
Clear the memory held by this object.
Definition at line 58 of file clOptions.cpp.
int mx::app::clOptions::count | ( | const std::string & | key | ) |
Get the number of times the option was set on the command line.
[in] | key | the key identifying the element |
Definition at line 167 of file clOptions.cpp.
Referenced by mx::app::appConfigurator::parseCommandLine().
void mx::app::clOptions::getAll | ( | std::vector< std::string > & | args, |
const std::string & | key | ||
) |
Fill a vector of strings with the arguments supplied for key, last to first.
[out] | args | will be resized and populated with the arguments. Will be empty if no arguments specified. |
[in] | key | the key identifying the element |
Definition at line 176 of file clOptions.cpp.
Referenced by mx::app::appConfigurator::parseCommandLine().
int mx::app::clOptions::numUnknown | ( | ) |
Get the number of unknown options found by the parser.
Definition at line 252 of file clOptions.cpp.
References nOpts.
Referenced by mx::app::appConfigurator::parseCommandLine(), and unknown().
const char * mx::app::clOptions::operator[] | ( | const std::string & | key | ) |
Get the value of the option, if present.
For a true/false type, returns true or false as appropriate. Returns an empty string if no argument for the key. Otherwise return the argument.
[in] | key | the key identifying the element |
Definition at line 136 of file clOptions.cpp.
bool mx::app::clOptions::optSet | ( | const std::string & | key | ) |
Test whether this option was set.
[in] | key | the key identifying the element |
Definition at line 242 of file clOptions.cpp.
Referenced by mx::app::appConfigurator::parseCommandLine().
void mx::app::clOptions::parse | ( | int | argc, |
char ** | argv, | ||
std::vector< std::string > * | nonOptions = 0 |
||
) |
Parse the command line.
[in] | argc | From main(argc, argv), the number of command line arguments |
argv | in] From main(argc, argv), the command line arguments | |
[out] | nonOptions | [optional] the elements in argv which are not option or option-arguments. |
Definition at line 104 of file clOptions.cpp.
References nOpts.
Referenced by mx::app::appConfigurator::parseCommandLine().
int mx::app::clOptions::unknown | ( | std::vector< std::string > & | unk | ) |
Get a vector of the unknown options found by the parser.
[out] | unk | the vector to populate with the unknown options found |
Definition at line 258 of file clOptions.cpp.
References nOpts, and numUnknown().
Referenced by mx::app::appConfigurator::parseCommandLine().
unsigned int mx::app::clOptions::nOpts {0} |
The number of options added.
Definition at line 70 of file clOptions.hpp.
Referenced by numUnknown(), parse(), mx::app::appConfigurator::parseCommandLine(), and unknown().