mpqc::GetLongOpt Class Reference
Documentation
Parse command line options.
Public Types | |
enum | OptType { Invalid, NoValue, OptionalValue, MandatoryValue } |
Public Member Functions | |
GetLongOpt (const char optmark='-') | |
~GetLongOpt () | |
void | parse (int argc, char *const *argv) |
void | parse (const std::string &str, const std::string &p) |
int | first_unprocessed_arg () const |
int | enroll (std::string opt, const OptType t, std::string desc) |
int | enroll (std::string opt, const OptType t, std::string desc, std::string default_value) |
std::optional< std::string > | retrieve (const std::string &opt) const |
void | usage (std::ostream &outfile=std::cout) const |
void | usage (std::string &&str) |
Member Enumeration Documentation
◆ OptType
Constructor & Destructor Documentation
◆ GetLongOpt()
GetLongOpt::GetLongOpt | ( | const char | optmark = '-' | ) |
Initialize the object.
- Parameters
-
optmark the option flag marker (default is -
).
◆ ~GetLongOpt()
|
inline |
Member Function Documentation
◆ enroll() [1/2]
int GetLongOpt::enroll | ( | std::string | opt, |
const OptType | t, | ||
std::string | desc | ||
) |
Enroll an option.
- Parameters
-
opt the option name t whether or not a value is expected desc a description of the option
◆ enroll() [2/2]
int GetLongOpt::enroll | ( | std::string | opt, |
const OptType | t, | ||
std::string | desc, | ||
std::string | default_value | ||
) |
Enroll an option, with the default value provided.
- Parameters
-
opt the option name t whether or not a value is expected desc a description of the option val the default value for the option with an optional value
◆ first_unprocessed_arg()
|
inline |
After calling parse() this will return the index of the first argument that was not processed
- Returns
- the index to the start of arguments that were not processed (an error occurred if the return value is < 1)
◆ parse() [1/2]
void GetLongOpt::parse | ( | const std::string & | str, |
const std::string & | p | ||
) |
Parse options in a string.
- Note
- call this once, after all options have been enrolled
- Warning
- this object becomes finalized, additional options cannot be enrolled
- Parameters
-
str the string to be parsed p a prefix that will be prefixed to error messages
◆ parse() [2/2]
void GetLongOpt::parse | ( | int | argc, |
char *const * | argv | ||
) |
Parse command line options.
- Note
- call this once, after all options have been enrolled
- Warning
- this object becomes finalized, additional options cannot be enrolled
- Parameters
-
argc the number of arguments, as passed to main
argv the arguments, as passed to main
◆ retrieve()
std::optional< std::string > GetLongOpt::retrieve | ( | const std::string & | opt | ) | const |
Retrieve the value of the option.
- Parameters
-
opt the name of the option
- Returns
- if
opt
was given, returnstd::optional<std::string>
initialized with the value of the option (empty string forNoValue
option types), otherwise a default-initializedstd::optional<std::string>
◆ usage() [1/2]
void mpqc::GetLongOpt::usage | ( | std::ostream & | outfile = std::cout | ) | const |
Print usage information.
- Parameters
-
outfile stream to use for printing (default: std::cout
)
◆ usage() [2/2]
|
inline |
Initialize usage synopsis.
- Parameters
-
str the usage synopsis
The documentation for this class was generated from the following files:
- mpqc/util/options/GetLongOpt.h
- mpqc/util/options/GetLongOpt.cpp