Photon Common Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
ph::CommandLineArguments Class Referencefinal

Helper for parsing command line arguments. More...

#include <CommandLineArguments.h>

Public Member Functions

 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 >
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 >
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 ()
 

Detailed Description

Helper for parsing command line arguments.

Constructor & Destructor Documentation

◆ CommandLineArguments()

ph::CommandLineArguments::CommandLineArguments ( int argc,
char * argv[] )

Member Function Documentation

◆ 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

Get a float from the arguments. Similar to retrieveString(const std::string&), while the result is converted to a float.

◆ retrieveInt()

template<typename T >
T ph::CommandLineArguments::retrieveInt ( T defaultInt = 0)
inline

Get an integer from the arguments. Similar to retrieveString(const std::string&), while the result is converted to an integer.

◆ 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
optionPrefixThe 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
defaultStringA 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
startingPrefixThe first argument's prefix.
endingPrefixThe last argument's prefix.
shouldIncludeStartWhether to include the first matching argument.
shouldIncludeEndWhether 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
numValuesNumber of values to be retrieved at once.

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