Project Malmo  0.30.0
Public Member Functions | List of all members
malmo::ArgumentParser Class Reference

A general purpose command-line argument parser. More...

#include <ArgumentParser.h>

Inheritance diagram for malmo::ArgumentParser:
malmo::AgentHost malmo::ALEAgentHost

Public Member Functions

 ArgumentParser (const std::string &title)
 Construct an argument parser. More...
 
void parseArgs (int argc, const char **argv)
 Parses a list of strings given in the C style. Throws std::exception if parsing fails. More...
 
void parse (const std::vector< std::string > &args)
 Parses a list of strings. Throws std::exception if parsing fails. More...
 
void addOptionalIntArgument (const std::string &name, const std::string &description, int defaultValue)
 Specify an integer argument that can be given on the command line. More...
 
void addOptionalFloatArgument (const std::string &name, const std::string &description, double defaultValue)
 Specify a floating-point argument that can be given on the command line. More...
 
void addOptionalStringArgument (const std::string &name, const std::string &description, const std::string &defaultValue)
 Specify a string argument that can be given on the command line. More...
 
void addOptionalFlag (const std::string &name, const std::string &description)
 Specify a boolean flag that can be given on the command line. More...
 
std::string getUsage () const
 Gets a string that describes the current set of options we expect. More...
 
bool receivedArgument (const std::string &name) const
 Gets whether a named argument was parsed on the command-line arguments. More...
 
int getIntArgument (const std::string &name) const
 Retrieves the value of a named integer argument. More...
 
double getFloatArgument (const std::string &name) const
 Retrieves the value of a named floating-point argument. More...
 
std::string getStringArgument (const std::string &name) const
 Retrieves the value of a named string argument. More...
 

Detailed Description

A general purpose command-line argument parser.

Constructor & Destructor Documentation

malmo::ArgumentParser::ArgumentParser ( const std::string &  title)

Construct an argument parser.

Parameters
titleThe title of the program to display.

Member Function Documentation

void malmo::ArgumentParser::addOptionalFlag ( const std::string &  name,
const std::string &  description 
)

Specify a boolean flag that can be given on the command line.

Parameters
nameThe name of the flag. To be given as "--name"
descriptionThe explanation of the flag that can be printed out.
void malmo::ArgumentParser::addOptionalFloatArgument ( const std::string &  name,
const std::string &  description,
double  defaultValue 
)

Specify a floating-point argument that can be given on the command line.

Parameters
nameThe name of the argument. To be given as "--name <value>"
descriptionThe explanation of the argument that can be printed out.
defaultValueThe value that this argument should have if not given on the command line.
void malmo::ArgumentParser::addOptionalIntArgument ( const std::string &  name,
const std::string &  description,
int  defaultValue 
)

Specify an integer argument that can be given on the command line.

Parameters
nameThe name of the argument. To be given as "--name <value>"
descriptionThe explanation of the argument that can be printed out.
defaultValueThe value that this argument should have if not given on the command line.
void malmo::ArgumentParser::addOptionalStringArgument ( const std::string &  name,
const std::string &  description,
const std::string &  defaultValue 
)

Specify a string argument that can be given on the command line.

Parameters
nameThe name of the argument. To be given as "--name <value>"
descriptionThe explanation of the argument that can be printed out.
defaultValueThe value that this argument should have if not given on the command line.
double malmo::ArgumentParser::getFloatArgument ( const std::string &  name) const

Retrieves the value of a named floating-point argument.

Parameters
nameThe name of the argument.
Returns
The value of the named argument.
int malmo::ArgumentParser::getIntArgument ( const std::string &  name) const

Retrieves the value of a named integer argument.

Parameters
nameThe name of the argument.
Returns
The value of the named argument.
std::string malmo::ArgumentParser::getStringArgument ( const std::string &  name) const

Retrieves the value of a named string argument.

Parameters
nameThe name of the argument.
Returns
The value of the named argument.
std::string malmo::ArgumentParser::getUsage ( ) const

Gets a string that describes the current set of options we expect.

Returns
The usage string, for displaying.
void malmo::ArgumentParser::parse ( const std::vector< std::string > &  args)

Parses a list of strings. Throws std::exception if parsing fails.

In C++: takes a std::vector<std::string>. In Python: takes a list of strings. In Lua: takes a table of strings.

Parameters
argsThe arguments to parse.
void malmo::ArgumentParser::parseArgs ( int  argc,
const char **  argv 
)

Parses a list of strings given in the C style. Throws std::exception if parsing fails.

Available in C++ only. In other languages use the parse function instead.

Parameters
argcThe number of arguments.
argvThe arguments to parse.
See also
parse()
bool malmo::ArgumentParser::receivedArgument ( const std::string &  name) const

Gets whether a named argument was parsed on the command-line arguments.

Parameters
nameThe name of the argument.
Returns
True if the named argument was received.

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