SuperTuxKart
Loading...
Searching...
No Matches
Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
CommandLine Class Reference

A small class to manage the 'argv' parameters of a program. More...

#include <command_line.hpp>

Static Public Member Functions

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 Private Member Functions

static bool has (const std::string &option, void *t, const char *const format)
 Searches for an option 'option=XX'.
 

Static Private Attributes

static std::vector< std::string > m_argv
 The array with all command line options.
 
static std::string m_exec_name =""
 Name of the executable.
 

Detailed Description

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

CommandLine::init(argc, argv);
if( CommandLine::has("--help") ||
CommandLine::has("-h") ) ...
int n;
if(CommandLine::has("--log", &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.

Member Function Documentation

◆ 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
optionThe option (must include '-' or '–' as required).
valueString 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
optionThe option (must include '-' or '–' as required).
valuePointer 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
optionThe option (must include '-' or '–' as required).
tAddress of a variable to store the value.
formatThe '' 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
argcNumber of arguments (in argv).
argvArray of char* with all command line arguments.

The documentation for this class was generated from the following files: