ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
modelspace::ArgParser Class Reference

Class to parse arguments from the command line in any language. More...

#include <ArgParser.h>

Public Member Functions

 ArgParser ()
 Default constructor for the arg parser – sets name to "args".
 
std::string operator() (const std::string &name)
 Function to get the string value of an arg.
 
int get (const std::string &name, std::string &val)
 Function to get the string value of an arg.
 
int get (const std::string &name, double &val)
 Function to get the string value of an arg as a double.
 
int get (const std::string &name, int &val)
 Function to get the string value of an arg as an int.
 
int parseArgs (int argc, char *argv[])
 Function to parse argc and argv for string arguments.
 
int parseArgs (std::vector< std::string > args)
 Function to loop through args and parse for values.
 
void addDefaultArgument (const std::string &name, const std::string &val)
 Function to add a default argument that can be overridden from the cmd line.
 
void addDefaultArgument (const std::string &name, double val)
 Function to add a default argument that can be overridden from the cmd line.
 
void addDefaultArgument (const std::string &name, int val)
 Function to add a default argument that can be overridden from the cmd line.
 
void dump ()
 Function to dump all argument value pairs held in the class.
 

Detailed Description

Class to parse arguments from the command line in any language.

Member Function Documentation

◆ addDefaultArgument() [1/3]

void modelspace::ArgParser::addDefaultArgument ( const std::string &  name,
const std::string &  val 
)

Function to add a default argument that can be overridden from the cmd line.

Parameters
nameThe name of the argument to add
valThe default value

◆ addDefaultArgument() [2/3]

void modelspace::ArgParser::addDefaultArgument ( const std::string &  name,
double  val 
)

Function to add a default argument that can be overridden from the cmd line.

Parameters
nameThe name of the argument to add
valThe default value

◆ addDefaultArgument() [3/3]

void modelspace::ArgParser::addDefaultArgument ( const std::string &  name,
int  val 
)

Function to add a default argument that can be overridden from the cmd line.

Parameters
nameThe name of the argument to add
valThe default value

◆ get() [1/3]

int modelspace::ArgParser::get ( const std::string &  name,
double &  val 
)

Function to get the string value of an arg as a double.

Parameters
nameThe arg to get
valThe returned value
Returns
The arg as a double value. Will produce error if value can't be cast to double

◆ get() [2/3]

int modelspace::ArgParser::get ( const std::string &  name,
int &  val 
)

Function to get the string value of an arg as an int.

Parameters
nameThe arg to get
valThe returned value
Returns
The arg as an int value. Will produce error if value can't be cast to int

◆ get() [3/3]

int modelspace::ArgParser::get ( const std::string &  name,
std::string &  val 
)

Function to get the string value of an arg.

Parameters
nameThe arg to get
valThe returned value
Returns
The arg as a string value. Empty string if arg does not exist

◆ operator()()

std::string modelspace::ArgParser::operator() ( const std::string &  name)
inline

Function to get the string value of an arg.

Parameters
nameThe arg to get
Returns
The arg as a string value. Empty string if arg does not exist

◆ parseArgs() [1/2]

int modelspace::ArgParser::parseArgs ( int  argc,
char *  argv[] 
)

Function to parse argc and argv for string arguments.

Parameters
argcC++ argc input
argvC++ argv input
Returns
Error code corresponding to success/failure

◆ parseArgs() [2/2]

int modelspace::ArgParser::parseArgs ( std::vector< std::string >  args)

Function to loop through args and parse for values.

Parameters
argsA std::vector of arguments
Returns
Error code corresponding to success/failure

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