|
Robot Raconteur Core C++ Library
|
Command line parser for node setup classes. More...
#include <NodeSetup.h>
Public Member Functions | |
| CommandLineConfigParser (uint32_t allowed_overrides, const std::string &prefix="robotraconteur-") | |
| Construct a new CommandLineConfigParser. | |
| void | SetDefaults (const std::string &node_name, uint16_t tcp_port, uint32_t default_flags) |
| Set the default NodeName, TCP port, and flags. | |
| void | AddStringOption (const std::string &name, const std::string &descr) |
| Add a new string option. | |
| void | AddBoolOption (const std::string &name, const std::string &descr) |
| Add a new bool option. | |
| void | AddIntOption (const std::string &name, const std::string &descr) |
| Add a new int32_t option. | |
| void | ParseCommandLine (int argc, char *argv[]) |
| Parse a specified argc and argv. | |
| void | ParseCommandLine (const std::vector< std::string > &args) |
| Parse a specified string vector containing the options. | |
| void | AcceptParsedResult (const boost::program_options::variables_map &vm) |
| Accept options from a boost::program_options::variables_map. | |
| std::string | GetOptionOrDefaultAsString (const std::string &option) |
| Get the option value as a string. | |
| std::string | GetOptionOrDefaultAsString (const std::string &option, const std::string &default_value) |
| Get the option value as a string. | |
| bool | GetOptionOrDefaultAsBool (const std::string &option) |
| Get the option value as a bool. | |
| bool | GetOptionOrDefaultAsBool (const std::string &option, bool default_value) |
| Get the option value as a bool. | |
| int32_t | GetOptionOrDefaultAsInt (const std::string &option) |
| Get the option value as an int32_t. | |
| int32_t | GetOptionOrDefaultAsInt (const std::string &option, int32_t default_value) |
| Get the option value as an int32_t. | |
Static Public Member Functions | |
| static void | FillOptionsDescription (boost::program_options::options_description &desc, uint32_t allowed_overrides, const std::string &prefix="robotraconteur-") |
| Fill the specified options_description with standard node command line options. | |
Command line parser for node setup classes.
The CommandLineConfigParser is used to parse command line options specified when a program is launched. These options allow for the node configuration to be changed without recompiling the software. See Command Line Options for a table of the standard command line options.
ClientNodeSetup, ServerNodeSetup, and SecureServerNodeSetup use this class to parse the argc and argv parameters. The RobotRaconteurNodeSetup constructors will accept either argc and argv, or will accept an initialize CommandLineConfigParser.
The CommandLineConfig() constructor takes the "allowed override" flags, and the option prefix. The "allowed override" specifies which options can be overridden using the command line. The prefix option allows the command line flag prefix to be changed. By default it expects all options to begin with --robotraconteur- followed by the name of the option. If there are multiple nodes, it is necessary to change the prefix to be unique for each node. For instance, "robotraconteur1-" for the first node and "robotraconteur2-" for the second node.
Users may add additional options to the parser. Use AddStringOption(), AddBoolOption(), or AddIntOption() to add additional options.
External instances of boost::program_options may be used. Use FillOptionDescription() to fill the options used by the parser, and AcceptParsedResults() to load the parsed results into the parser.
| RobotRaconteur::CommandLineConfigParser::CommandLineConfigParser | ( | uint32_t | allowed_overrides, |
| const std::string & | prefix = "robotraconteur-" ) |
Construct a new CommandLineConfigParser.
Must use boost::shared_ptr<CommandLineConfigParser>()
| allowed_overrides | The allowed overrides flags |
| prefix | The prefix to use for the options |
| void RobotRaconteur::CommandLineConfigParser::AcceptParsedResult | ( | const boost::program_options::variables_map & | vm | ) |
Accept options from a boost::program_options::variables_map.
Accept boost::program_options parse results
| vm | The boost::program_options variable map |
| void RobotRaconteur::CommandLineConfigParser::AddBoolOption | ( | const std::string & | name, |
| const std::string & | descr ) |
Add a new bool option.
| name | The name of the option |
| descr | Description of the option |
| void RobotRaconteur::CommandLineConfigParser::AddIntOption | ( | const std::string & | name, |
| const std::string & | descr ) |
Add a new int32_t option.
| name | The name of the option |
| descr | Description of the option |
| void RobotRaconteur::CommandLineConfigParser::AddStringOption | ( | const std::string & | name, |
| const std::string & | descr ) |
Add a new string option.
| name | The name of the option |
| descr | Description of the option |
|
static |
Fill the specified options_description with standard node command line options.
| desc | The target option_descriptions structure |
| allowed_overrides | The allowed override flags |
| prefix | The prefix to use for the options |
| bool RobotRaconteur::CommandLineConfigParser::GetOptionOrDefaultAsBool | ( | const std::string & | option | ) |
Get the option value as a bool.
Returns false if option not specified on command line
| option | The name of the option |
| bool RobotRaconteur::CommandLineConfigParser::GetOptionOrDefaultAsBool | ( | const std::string & | option, |
| bool | default_value ) |
Get the option value as a bool.
Returns default_value if option not specified on command line
| option | The name of the option |
| default_value | The default option value |
| int32_t RobotRaconteur::CommandLineConfigParser::GetOptionOrDefaultAsInt | ( | const std::string & | option | ) |
Get the option value as an int32_t.
Returns -1 if option not specified on command line
| option | The name of the option |
| int32_t RobotRaconteur::CommandLineConfigParser::GetOptionOrDefaultAsInt | ( | const std::string & | option, |
| int32_t | default_value ) |
Get the option value as an int32_t.
Returns default_value if option not specified on command line
| option | The name of the option |
| default_value | The default option value |
| std::string RobotRaconteur::CommandLineConfigParser::GetOptionOrDefaultAsString | ( | const std::string & | option | ) |
Get the option value as a string.
Returns empty string if option not specified on command line
| option | The name of the option |
| std::string RobotRaconteur::CommandLineConfigParser::GetOptionOrDefaultAsString | ( | const std::string & | option, |
| const std::string & | default_value ) |
Get the option value as a string.
Returns default_value if option not specified on command line
| option | The name of the option |
| default_value | The default option value |
| void RobotRaconteur::CommandLineConfigParser::ParseCommandLine | ( | const std::vector< std::string > & | args | ) |
Parse a specified string vector containing the options.
Results are stored in the instance
| args | The options as a string vector |
| void RobotRaconteur::CommandLineConfigParser::ParseCommandLine | ( | int | argc, |
| char * | argv[] ) |
Parse a specified argc and argv.
Pass argc and argv from main()
Results are stored in the instance
| argc | argc from main() |
| argv | argv from main() |
| void RobotRaconteur::CommandLineConfigParser::SetDefaults | ( | const std::string & | node_name, |
| uint16_t | tcp_port, | ||
| uint32_t | default_flags ) |
Set the default NodeName, TCP port, and flags.
The command line options will be allowed to override the options specified in allowed_overrides passed to CommandLineConfigParser().
| node_name | The default NodeName |
| tcp_port | The default TCP port |
| default_flags | The default flags |