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

Used by the enroll member to specify whether or not a value is expected or optional.

Enumerator
Invalid 
NoValue 
OptionalValue 
MandatoryValue 

Constructor & Destructor Documentation

◆ GetLongOpt()

GetLongOpt::GetLongOpt ( const char  optmark = '-')

Initialize the object.

Parameters
optmarkthe option flag marker (default is -).

◆ ~GetLongOpt()

mpqc::GetLongOpt::~GetLongOpt ( )
inline

Member Function Documentation

◆ enroll() [1/2]

int GetLongOpt::enroll ( std::string  opt,
const OptType  t,
std::string  desc 
)

Enroll an option.

Parameters
optthe option name
twhether or not a value is expected
desca 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
optthe option name
twhether or not a value is expected
desca description of the option
valthe default value for the option with an optional value

◆ first_unprocessed_arg()

int mpqc::GetLongOpt::first_unprocessed_arg ( ) const
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
strthe string to be parsed
pa 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
argcthe number of arguments, as passed to main
argvthe arguments, as passed to main

◆ retrieve()

std::optional< std::string > GetLongOpt::retrieve ( const std::string &  opt) const

Retrieve the value of the option.

Parameters
optthe name of the option
Returns
if opt was given, return std::optional<std::string> initialized with the value of the option (empty string for NoValue option types), otherwise a default-initialized std::optional<std::string>

◆ usage() [1/2]

void mpqc::GetLongOpt::usage ( std::ostream &  outfile = std::cout) const

Print usage information.

Parameters
outfilestream to use for printing (default: std::cout)

◆ usage() [2/2]

void mpqc::GetLongOpt::usage ( std::string &&  str)
inline

Initialize usage synopsis.

Parameters
strthe usage synopsis

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