A small class to manage the 'argv' parameters of a program.
More...
#include <command_line.hpp>
|
static void | init (unsigned int argc, char *argv[]) |
| The constructor takes the standard C arguments argc and argv and stores the information internally.
|
|
static void | addArgsFromUserConfig () |
|
static void | reportInvalidParameters () |
| Reports any parameters that have not been handled yet to be an error.
|
|
static bool | has (const std::string &option) |
|
template<typename T > |
static bool | has (const std::string &option, T *value) |
| Searches for an option 'option=XX'.
|
|
static bool | has (const std::string &option, std::string *value) |
| Searches for an option 'option=XX'.
|
|
static const std::string & | getExecName () |
| Returns the name of the executable.
|
|
|
static bool | has (const std::string &option, void *t, const char *const format) |
| Searches for an option 'option=XX'.
|
|
|
static std::vector< std::string > | m_argv |
| The array with all command line options.
|
|
static std::string | m_exec_name ="" |
| Name of the executable.
|
|
A small class to manage the 'argv' parameters of a program.
That includes the name of the executable (argv[0]) and all command line parameters. Example usage
int n;
...
CommandLine::reportInvalidParameters();
static void init(unsigned int argc, char *argv[])
The constructor takes the standard C arguments argc and argv and stores the information internally.
Definition: command_line.cpp:37
static bool has(const std::string &option, void *t, const char *const format)
Searches for an option 'option=XX'.
Definition: command_line.hpp:63
static void setLogLevel(int n)
Defines the minimum log level to be displayed.
Definition: log.hpp:128
The two 'has' functions will remove a parameter from the list of all parameters, so any parameters remaining at the end are invalid parameters, which will be listed by reportInvalidParameters.
◆ has() [1/3]
static bool CommandLine::has |
( |
const std::string & |
option, |
|
|
std::string * |
value |
|
) |
| |
|
inlinestatic |
Searches for an option 'option=XX'.
If found, *value will contain 'XX'. If the value was found and the type of XX and value matches each other, the entry is removed from the list of all command line arguments. It copies the result directly to value to include space.
- Parameters
-
option | The option (must include '-' or '–' as required). |
value | String pointer to store the value. |
- Returns
- true if the value was found, false otherwise.
◆ has() [2/3]
template<typename T >
static bool CommandLine::has |
( |
const std::string & |
option, |
|
|
T * |
value |
|
) |
| |
|
inlinestatic |
Searches for an option 'option=XX'.
If found, *value will contain 'XX'. If the value was found and the type of XX and value matches each other, the entry is removed from the list of all command line arguments.
- Parameters
-
option | The option (must include '-' or '–' as required). |
value | Pointer to store the value. |
- Returns
- true if the value was found, false otherwise.
◆ has() [3/3]
static bool CommandLine::has |
( |
const std::string & |
option, |
|
|
void * |
t, |
|
|
const char *const |
format |
|
) |
| |
|
inlinestaticprivate |
Searches for an option 'option=XX'.
If found, *t will contain 'XX'. If the value was found, the entry is removed from the list of all command line arguments.
- Parameters
-
option | The option (must include '-' or '–' as required). |
t | Address of a variable to store the value. |
format | The '' format to sscanf the value in t with. |
- Returns
- true if the value was found, false otherwise.
◆ init()
void CommandLine::init |
( |
unsigned int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
|
static |
The constructor takes the standard C arguments argc and argv and stores the information internally.
- Parameters
-
argc | Number of arguments (in argv). |
argv | Array of char* with all command line arguments. |
The documentation for this class was generated from the following files: