PYTHIA
8.313
|
#include <InputParser.h>
Public Types | |
enum | Status { Valid = -1, Invalid = EXIT_FAILURE, Help = EXIT_SUCCESS } |
Public Member Functions | |
InputParser (string usage="", vector< string > examples={}, string extra="", ostream *stream=&cout, string optName="h", set< string > aliases={"-help","H"}) | |
bool | add (const string &optName, const string &defString, const string &helpText="", set< string > aliases={}) |
bool | require (const string &optName, const string &helpText="", set< string > aliases={}) |
Add required command line option to the parser. Do this before parsing. | |
Status | init (int &argc, char **argv) |
bool | parse (int &argc, char **argv) |
bool | has (const string &optName) const |
template<typename T > | |
T | get (const string &optName) |
template<typename T > | |
vector< T > | getVector (const string &optName) |
Templated method to get all the values of an option. More... | |
const string | help () const |
Convenience class for parsing C++ command-line arguments on the form ./mainXX -a A -b B etc.
Usage: (1) Create an InputParser object in your main program. (2) Specify the command-line options that should be available, including default values, using add. (3) Call the parse(int& argc, char** argv) method, with the two aruments forwarded from argc and argv from your main. (4) Extract given command-line values of type T, using get<T>.
enum Status |
Initialize the parser. This includes parsing, printing help if requested, and checking the required options.
|
inline |
Constructor. usage: Text to print when describing usage with help. examples: Vector of examples to print with help. extra: Extra text to print with help. stream: Optional pointer to stream to print messages to. optName: Option name for the help flag. aliases: Aliases for the help flag.
|
inline |
Add an optional command line option to the parser. Do this before parsing. Parameters: optName: The name of the option. defString: The default value for the option. helpText: The help text describing the option (optional). aliases: A set of aliases for the option (optional).
Check for name conflicts with existing options or aliases.
Create an OptionInfo object and add it to the options map.
Add aliases to the alias map.
|
inline |
Templated method to get the last value of an option. Returns the last value of the option converted to the specified type.
Retrieve the OptionInfo object for the given option name.
Return default-constructed T if string is empty.
Convert the string value to the specified type.
Error message and default constructed T() is conversion failed.
|
inline |
Templated method to get all the values of an option.
Retrieve the OptionInfo object for the given option name.
Return empty vector if no values.
Convert the string value to the specified type.
Error message and default constructed T() is conversion failed.
|
inline |
Check if an option is defined. Returns true if the option is defined, false otherwise.
|
inline |
Method to generate the help text for all options. Returns a formatted string containing the help text.
|
inline |
Parse the arguments.
Print the help if requested.
Check the required options are set.
|
inline |
Method to parse command line arguments. Returns true if parsing was successful, false otherwise. Print error messages to stream. The hflag option specifies the help option.
Check if the argument is an option (starts with '-').
Check for aliases and get the actual option name.
Check if the option is defined.
If the next argument is not an option, set the value for this option.
Treat as boolean flag and flip its value.