SOFA API  1c8b807d
Open source framework for multi-physics simuation
sofa::gui::common::ArgumentParser Class Reference

#include <ArgumentParser.h>

Detailed Description

Command line parser

This object parses arguments from a command line or from an input stream.

See also
Argument

Static Public Attributes

static std::vector< std::string > extra = std::vector<std::string>()
 

Public Member Functions

 ArgumentParser (int argc, char **argv)
 constructor

More...
 
 ~ArgumentParser ()
 
void addArgument (std::shared_ptr< cxxopts::Value > s, const std::string name, const std::string help)
 addArgument More...
 
void addArgument (std::shared_ptr< cxxopts::Value > s, const std::string name, const std::string help, std::function< void(const ArgumentParser *, const std::string &)> callback)
 addArgument More...
 
void addArgument (const std::string name, const std::string help)
 addArgument More...
 
void showHelp ()
 simply display the help (You need to add -h –help options in your main and call this function by yourself More...
 
void parse ()
 this is the main function. You have to call this function if you want to parse the arguments given to the constructor More...
 
void showArgs ()
 display args with values More...
 
template<typename T >
bool getValueFromKey (const std::string &key, T &value) const
 get the value associated to the key (if this key exists or the type is correct) More...
 
const std::unordered_map< std::string, std::string > & getMap () const
 
std::vector< std::string > getInputFileList ()
 

Static Public Member Functions

static const std::vector< std::string > extra_args ()
 return extra_args needed for python (arguments) More...
 

Attribute details

◆ extra

std::vector< std::string > sofa::gui::common::ArgumentParser::extra = std::vector<std::string>()
static

last parsed extra arguments extra parameter needed for python (arguments)

Constructor details

◆ ArgumentParser()

sofa::gui::common::ArgumentParser::ArgumentParser ( int  argc,
char **  argv 
)

constructor

Parameters
argcfrom command line
argvfrom command line

◆ ~ArgumentParser()

sofa::gui::common::ArgumentParser::~ArgumentParser ( )

Function details

◆ addArgument() [1/3]

void sofa::gui::common::ArgumentParser::addArgument ( const std::string  name,
const std::string  help 
)

addArgument

@usage Can be call if you want to add parameters

Parameters
nameargument name such as "help,h" after the comma it's a character use as short name
helpdescribing the argument

◆ addArgument() [2/3]

void sofa::gui::common::ArgumentParser::addArgument ( std::shared_ptr< cxxopts::Value >  s,
const std::string  name,
const std::string  help 
)

addArgument

@usage Can be call if you want to add parameters

Parameters
sa sptr to a cxxopts::Value for examples
See also
runSofa/main.cpp
Parameters
nameargument name such as "help,h" after the comma it's a character use as short name
helpdescribing the argument

◆ addArgument() [3/3]

void sofa::gui::common::ArgumentParser::addArgument ( std::shared_ptr< cxxopts::Value >  s,
const std::string  name,
const std::string  help,
std::function< void(const ArgumentParser *, const std::string &)>  callback 
)

addArgument

@usage Can be call if you want to add parameters

Parameters
sa sptr to a cxxopts::Value for examples
See also
runSofa/main.cpp
Parameters
nameargument name such as "h,help" after the comma it's a character use as short name
helpdescribing the argument
callbackwill be called when parsing is done and this arg has been modified

◆ extra_args()

static const std::vector<std::string> sofa::gui::common::ArgumentParser::extra_args ( )
inlinestatic

return extra_args needed for python (arguments)

◆ getInputFileList()

std::vector< std::string > sofa::gui::common::ArgumentParser::getInputFileList ( )

◆ getMap()

const std::unordered_map< std::string, std::string > & sofa::gui::common::ArgumentParser::getMap ( ) const

◆ getValueFromKey()

template<typename T >
bool sofa::gui::common::ArgumentParser::getValueFromKey ( const std::string &  key,
T &  value 
) const
inline

get the value associated to the key (if this key exists or the type is correct)

◆ parse()

void sofa::gui::common::ArgumentParser::parse ( )

this is the main function. You have to call this function if you want to parse the arguments given to the constructor

◆ showArgs()

void sofa::gui::common::ArgumentParser::showArgs ( )

display args with values

◆ showHelp()

void sofa::gui::common::ArgumentParser::showHelp ( )

simply display the help (You need to add -h –help options in your main and call this function by yourself

See also
runSofa/main.cpp)