A class which holds a represention of the argc/argv command line array, and supports simple command-line parsing. More...
#include <garg.h>
Public Types | |
typedef size_t | size_type |
Public Member Functions | |
Arg (int argc, char *argv[]) | |
Constructor taking argc/argv. More... | |
Arg () | |
Default constructor for Windows. More... | |
void | parse (HINSTANCE hinstance, const std::string &command_line) |
Windows only. More... | |
void | reparse (const std::string &command_line) |
Reinitialises the object with the given command-line. More... | |
~Arg () | |
Destructor. More... | |
size_type | c () const |
Returns the number of tokens in the command line, including the program name. More... | |
std::string | v (size_type i) const |
Returns the i'th argument. More... | |
std::string | prefix () const |
Returns the basename of v(0) without any extension. More... | |
bool | contains (const std::string &sw, size_type sw_args=0U, bool case_sensitive=true) const |
< An exception-free version of prefix() which can be used in main() outside of the outermost try block. More... | |
size_type | index (const std::string &sw, size_type sw_args=0U) const |
Returns the index of the given switch. More... | |
bool | remove (const std::string &sw, size_type sw_args=0U) |
Removes the given switch and its arguments. More... | |
void | removeAt (size_type sw_index, size_type sw_args=0U) |
Removes the given argument and the following 'sw_args' ones. More... | |
Arg & | operator= (const Arg &) |
Assignment operator. More... | |
Arg (const Arg &) | |
Copy constructor. More... | |
Static Public Member Functions | |
static const char * | prefix (char *argv[]) |
A class which holds a represention of the argc/argv command line array, and supports simple command-line parsing.
In some environments the argv(0) path is fixed up so that it refers to the running executable, regardless of what the parent process specified in the exec() call. Refer to the various implementations of G::Arg::setExe().
typedef size_t G::Arg::size_type |
G::Arg::Arg | ( | int | argc, |
char * | argv[] | ||
) |
G::Arg::Arg | ( | ) |
G::Arg::size_type G::Arg::c | ( | ) | const |
Returns the number of tokens in the command line, including the program name.
Definition at line 131 of file garg.cpp.
Referenced by filter_main().
bool G::Arg::contains | ( | const std::string & | sw, |
size_type | sw_args = 0U , |
||
bool | case_sensitive = true |
||
) | const |
G::Arg::size_type G::Arg::index | ( | const std::string & | sw, |
size_type | sw_args = 0U |
||
) | const |
void G::Arg::parse | ( | HINSTANCE | hinstance, |
const std::string & | command_line | ||
) |
Windows only.
Parses the given command line, splitting it up into an array of tokens.
std::string G::Arg::prefix | ( | ) | const |
Returns the basename of v(0) without any extension.
Typically used as a prefix in error messages.
Definition at line 142 of file garg.cpp.
Referenced by filter_main(), and main().
bool G::Arg::remove | ( | const std::string & | sw, |
size_type | sw_args = 0U |
||
) |
void G::Arg::reparse | ( | const std::string & | command_line | ) |
Reinitialises the object with the given command-line.
The command-line should not contain the program name: the v(0) value and prefix() are unchanged.
std::string G::Arg::v | ( | size_type | i | ) | const |
Returns the i'th argument.
Precondition: i < c()
Definition at line 136 of file garg.cpp.
References G_ASSERT.
Referenced by filter_main().