Robot Raconteur Core C++ Library
Loading...
Searching...
No Matches
RobotRaconteur::CommandLineConfigParser Class Reference

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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ CommandLineConfigParser()

RobotRaconteur::CommandLineConfigParser::CommandLineConfigParser ( uint32_t allowed_overrides,
const std::string & prefix = "robotraconteur-" )

Construct a new CommandLineConfigParser.

Must use boost::shared_ptr<CommandLineConfigParser>()

Parameters
allowed_overridesThe allowed overrides flags
prefixThe prefix to use for the options

Member Function Documentation

◆ AcceptParsedResult()

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

Parameters
vmThe boost::program_options variable map

◆ AddBoolOption()

void RobotRaconteur::CommandLineConfigParser::AddBoolOption ( const std::string & name,
const std::string & descr )

Add a new bool option.

Parameters
nameThe name of the option
descrDescription of the option

◆ AddIntOption()

void RobotRaconteur::CommandLineConfigParser::AddIntOption ( const std::string & name,
const std::string & descr )

Add a new int32_t option.

Parameters
nameThe name of the option
descrDescription of the option

◆ AddStringOption()

void RobotRaconteur::CommandLineConfigParser::AddStringOption ( const std::string & name,
const std::string & descr )

Add a new string option.

Parameters
nameThe name of the option
descrDescription of the option

◆ FillOptionsDescription()

void RobotRaconteur::CommandLineConfigParser::FillOptionsDescription ( boost::program_options::options_description & desc,
uint32_t allowed_overrides,
const std::string & prefix = "robotraconteur-" )
static

Fill the specified options_description with standard node command line options.

Parameters
descThe target option_descriptions structure
allowed_overridesThe allowed override flags
prefixThe prefix to use for the options

◆ GetOptionOrDefaultAsBool() [1/2]

bool RobotRaconteur::CommandLineConfigParser::GetOptionOrDefaultAsBool ( const std::string & option)

Get the option value as a bool.

Returns false if option not specified on command line

Parameters
optionThe name of the option
Returns
bool The option value, or false

◆ GetOptionOrDefaultAsBool() [2/2]

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

Parameters
optionThe name of the option
default_valueThe default option value
Returns
bool The option value, or default_value if not specified on command line

◆ GetOptionOrDefaultAsInt() [1/2]

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

Parameters
optionThe name of the option
Returns
int32_t The option value, or -1

◆ GetOptionOrDefaultAsInt() [2/2]

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

Parameters
optionThe name of the option
default_valueThe default option value
Returns
int32_t The option value, or default_value if not specified on command line

◆ GetOptionOrDefaultAsString() [1/2]

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

Parameters
optionThe name of the option
Returns
std::string The option value, or an empty string

◆ GetOptionOrDefaultAsString() [2/2]

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

Parameters
optionThe name of the option
default_valueThe default option value
Returns
std::string The option value, or default_value if not specified on command line

◆ ParseCommandLine() [1/2]

void RobotRaconteur::CommandLineConfigParser::ParseCommandLine ( const std::vector< std::string > & args)

Parse a specified string vector containing the options.

Results are stored in the instance

Parameters
argsThe options as a string vector

◆ ParseCommandLine() [2/2]

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

Parameters
argcargc from main()
argvargv from main()

◆ SetDefaults()

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().

Parameters
node_nameThe default NodeName
tcp_portThe default TCP port
default_flagsThe default flags

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