Helper for parsing command line arguments.
More...
#include <CommandLineArguments.h>
|
| CommandLineArguments (int argc, char *argv[]) |
|
std::string | getProgramName () const |
| Get the program name.
|
|
bool | isEmpty () const |
| Check if there are arguments yet to be parsed.
|
|
std::string | retrieveString (const std::string &defaultString="") |
| Get the first argument passed in and remove it from the internal buffer.
|
|
std::vector< std::string > | retrieveStrings (std::size_t numValues) |
| Get the first N arguments passed in and remove them from the internal buffer.
|
|
std::vector< std::string > | retrieveOptionArguments (const std::string &optionPrefix) |
| Get the arguments for an option. This method assumes that the options specified are of the form "{- | --}<optionName> <arg0> <arg1> ...", i.e., options have a single or double dash prefix followed by its name, then the actual arguments. Careful that some input forms may still require manual treatment (using retrieve()) such as a filename starting with a dash or a negative number, since they can be misinterpreted as the next option and cause the argument list for the current option being ended prematurely.
|
|
std::vector< std::string > | retrieveStrings (const std::string &startingPrefix, const std::string &endingPrefix, bool shouldIncludeStart=true, bool shouldIncludeEnd=true) |
| Get the arguments between a specified range.
|
|
template<typename T > |
T | retrieveInt (T defaultInt=0) |
| Get an integer from the arguments. Similar to retrieveString(const std::string&), while the result is converted to an integer.
|
|
template<typename T > |
T | retrieveFloat (T defaultFloat=0.0f) |
| Get a float from the arguments. Similar to retrieveString(const std::string&), while the result is converted to a float.
|
|
template<typename T > |
std::optional< T > | retrieve () |
|
Helper for parsing command line arguments.
◆ CommandLineArguments()
ph::CommandLineArguments::CommandLineArguments |
( |
int | argc, |
|
|
char * | argv[] ) |
◆ getProgramName()
std::string ph::CommandLineArguments::getProgramName |
( |
| ) |
const |
|
inline |
Get the program name.
- Returns
- An empty string if program name is not available.
◆ isEmpty()
bool ph::CommandLineArguments::isEmpty |
( |
| ) |
const |
|
inline |
Check if there are arguments yet to be parsed.
◆ retrieve()
template<typename T >
std::optional< T > ph::CommandLineArguments::retrieve |
( |
| ) |
|
|
inline |
◆ retrieveFloat()
template<typename T >
T ph::CommandLineArguments::retrieveFloat |
( |
T | defaultFloat = 0.0f | ) |
|
|
inline |
◆ retrieveInt()
template<typename T >
T ph::CommandLineArguments::retrieveInt |
( |
T | defaultInt = 0 | ) |
|
|
inline |
◆ retrieveOptionArguments()
std::vector< std::string > ph::CommandLineArguments::retrieveOptionArguments |
( |
const std::string & | optionPrefix | ) |
|
Get the arguments for an option. This method assumes that the options specified are of the form "{- | --}<optionName> <arg0> <arg1> ...", i.e., options have a single or double dash prefix followed by its name, then the actual arguments. Careful that some input forms may still require manual treatment (using retrieve()) such as a filename starting with a dash or a negative number, since they can be misinterpreted as the next option and cause the argument list for the current option being ended prematurely.
- Parameters
-
optionPrefix | The option's prefix. |
◆ retrieveString()
std::string ph::CommandLineArguments::retrieveString |
( |
const std::string & | defaultString = "" | ) |
|
Get the first argument passed in and remove it from the internal buffer.
- Parameters
-
defaultString | A default value if the operation cannot be done (such as isEmpty() is true). |
◆ retrieveStrings() [1/2]
std::vector< std::string > ph::CommandLineArguments::retrieveStrings |
( |
const std::string & | startingPrefix, |
|
|
const std::string & | endingPrefix, |
|
|
bool | shouldIncludeStart = true, |
|
|
bool | shouldIncludeEnd = true ) |
Get the arguments between a specified range.
- Parameters
-
startingPrefix | The first argument's prefix. |
endingPrefix | The last argument's prefix. |
shouldIncludeStart | Whether to include the first matching argument. |
shouldIncludeEnd | Whether to include the last matching argument. |
◆ retrieveStrings() [2/2]
std::vector< std::string > ph::CommandLineArguments::retrieveStrings |
( |
std::size_t | numValues | ) |
|
Get the first N arguments passed in and remove them from the internal buffer.
- Parameters
-
numValues | Number of values to be retrieved at once. |
The documentation for this class was generated from the following files: