LOOS  v2.3.2
loos::OptionsFramework::RequiredArguments Class Reference

Provides simple way to add command-line arguments (required options) More...

#include <OptionsFramework.hpp>

Inheritance diagram for loos::OptionsFramework::RequiredArguments:
Collaboration diagram for loos::OptionsFramework::RequiredArguments:

Public Member Functions

 RequiredArguments (const std::string &argname, const std::string &argdesc)
 
void addArgument (const std::string &name, const std::string &description)
 Add a required argument given a name (tag) and a description (currently unused)
 
void addVariableArguments (const std::string &name, const std::string &description)
 Add a required argument that can be an arbitrary number of items. More...
 
std::string value (const std::string &s) const
 Retrieve the value for an argument.
 
std::vector< std::string > variableValues (const std::string &s) const
 Retrieve the variable-number argument.
 
- Public Member Functions inherited from loos::OptionsFramework::OptionsPackage
virtual void addGeneric (po::options_description &opts)
 Appends generic options (those that the user can see)
 

Detailed Description

Provides simple way to add command-line arguments (required options)

This class handles required command-line options (also known as command line arguments). Each argument is defined by a string tag and a description and is parsed from the command line as a string. Arguments are added via the addOption() method and the values are retrieved using value().

Since these are required options, the class will automatically generate a parsing error if any argument is unset.

The value returned for options are strings and must be parsed into the appropriate type. A simple way to do this is to use loos::parseStringAs<>.

Example:

RequiredArguments* ropts = new RequiredArguments;
ropts->addArgument("name", "Name of data file");
ropts->addArgument("scale", "Scaling to apply to data");
...
string name = ropts->value("name");
double scale = parseStringAs<double>(ropts->value("scale"));

The case where one or more arguments are required is supported via the RequiredArguments::addVariableArguments() and RequiredArguments::variableValues(). If this feature is used, then the RequiredArguments object must be the last OptionsPackage chained together in the AggregateOptions object.

Definition at line 600 of file OptionsFramework.hpp.

Member Function Documentation

void loos::OptionsFramework::RequiredArguments::addVariableArguments ( const std::string &  name,
const std::string &  description 
)

Add a required argument that can be an arbitrary number of items.

This argument will always appear at the end of the command line, after all other required arguments. It also means that the RequiredOptions object should be the last one added to the AggregateOptions object, otherwise any subsequence positional arguments will be missed.

Example:

RequiredArguments* ropts = new RequiredArguments;
ropts->addVariableArguments("selection", "selection");
...
vector<string> selections = ropts->variableValues("selection");

Definition at line 503 of file OptionsFramework.cpp.


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