LibCppCmd v1.0 Beta 15
C++ Command Line Parsing Library
|
A multi-value PosParam. More...
#include <MultiPosParam.h>
Classes | |
struct | Definition |
This definition is used to construct a MutiPosParam. More... | |
Public Types | |
enum class | ParsingOrder { End , AfterOptions } |
Determines the MultiPosParam parsing order. More... | |
Public Member Functions | |
MultiPosParam (Definition d) | |
Constructs a new MultiPosParam. | |
std::string | Name () const override |
Gets the name of the MultiPosParam. | |
std::string | Description () const override |
Getst the description of the MultiPosParam. | |
std::string | HelpInfo () const override |
Gets help information for the MultiPosParam. | |
bool | IsSpecified () const override |
Indicates whether the MultiPosParam has been specified. | |
bool | IsMandatory () const override |
Indicates whether the MultiPosParam is mandatory. | |
bool | Populate (std::deque< std::string > &args) override |
Populates the MultiPosParam from an argument queue. | |
bool | CanPopulate (const std::deque< std::string > &args) const override |
Determines if arguments can populate this MultiPosParam. | |
std::size_t | Consumes (const std::deque< std::string > &args) const override |
Gets the number of arguments the MultiPosParam consumes. | |
std::vector< std::string > | Values () const |
Gets the values the MultiPosParam has been populated with. | |
ParsingOrder | Order () const |
Gets the ParsingOrder of the MultiPosParam. | |
Public Member Functions inherited from CmdLine::ArgParam | |
virtual | ~ArgParam ()=default |
Destructs an ArgParam. | |
Public Member Functions inherited from CmdLine::Param | |
virtual | ~Param ()=default |
Destructs a Param. | |
A multi-value PosParam.
A MultiPosParam is a multi-value PosParam that is populated by multiple command line arguments rather than a single argument. MultiPosParam arguments are parsed by the command line Parser either immediately after the last Option is parsed or after the last single-value PosParam is parsed, depending on what MultiPosParam::ParsingOrder the MultiPosParam was created with. A MultiPosParam consumes a variable number of arguments based on how many arguments are left in the parser internal argument queue. Each argument consumed adds a single value to the values of the MultiPosParam. For example, a program that copies files might accept mutiple source file arguments and a single destination path argument. In this case, the program would use a MultiPosParam to capture the source files.
|
strong |
Determines the MultiPosParam parsing order.
The command line Parser will examine the parsing order of the MultiPosParam to determine when it should be parsed.
Enumerator | |
---|---|
End | Parse the MultiPosParam at the very end. Instructs the command line Parser to parse the MultiPosParam at the end, after the last single-value PosParam has been parsed. This is the default value. |
AfterOptions | Parse the MultiPosParam after the last Option. Instructs the command line Parser to parse the MultiPosParam immediately after the last Option has been parsed but before the first single-value PosParam. |
CmdLine::MultiPosParam::MultiPosParam | ( | Definition | d | ) |
Constructs a new MultiPosParam.
d | The Definition used to create the MultiPosParam. |
Param::InvalidDefinition | Doesn't satisfy invariants. |
|
overridevirtual |
Determines if arguments can populate this MultiPosParam.
Accepts a reference to an argument queue (deque) and determines if all the arguments in the queue can populate the MultiPosParam.
args | The argument queue to evaluate. |
Implements CmdLine::ArgParam.
|
overridevirtual |
Gets the number of arguments the MultiPosParam consumes.
Each MultiPosParam consumes a certain number of arguments from an argument queue upon successful population. The number of arguments the MultiPosParam consumes is equal to the number of non-option arguments remaining in the queue.
args | The argument queue to evaluate. |
Implements CmdLine::ArgParam.
|
inlineoverridevirtual |
Getst the description of the MultiPosParam.
The description of the MultiPosParam is used for generating HelpInfo().
Implements CmdLine::Param.
|
overridevirtual |
Gets help information for the MultiPosParam.
The help info will include the Name() and Description() of the MultiPosParam when generating help.
Implements CmdLine::Param.
|
inlineoverridevirtual |
Indicates whether the MultiPosParam is mandatory.
The command line Parser uses this to determine if a MultiPosParam must be specified at the command line for parsing to be successful. If a mandatory MultiPosParam is not specified, parsing will fail indicating the program was supplied with bad command line arguments.
Implements CmdLine::Param.
|
inlineoverridevirtual |
Indicates whether the MultiPosParam has been specified.
A MultiPosParam will only indicate it is specified if it has been successfully populated by command line arguments. The MultiPosParam must be populated by at least one argument to be specified. The command line Parser also uses this to determine if a mandatory MultiPosParam has been specified.
Implements CmdLine::Param.
|
inlineoverridevirtual |
Gets the name of the MultiPosParam.
The name of the MultiPosParam is used for generating usage and HelpInfo().
Implements CmdLine::Param.
|
inline |
Gets the ParsingOrder of the MultiPosParam.
The ParsingOrder determines whether a command line MultiPosParam is parsed imediately after the the last Option or at the end when the last single-value PosParam has been parsed.
|
overridevirtual |
Populates the MultiPosParam from an argument queue.
Accepts a reference to an argument queue (deque) and attempts to populate the MultiPosParam from the remaining arguments in the queue. Populating the MultiPosParam marks it as specified and populates it with values from the command line arguments. Successful population also consumes the remaining arguments in the queue.
args | The arguments to populate the MultiPosParam. |
Implements CmdLine::ArgParam.
|
inline |
Gets the values the MultiPosParam has been populated with.
With MultiPosParams, each value corresponds to exactly one command line argument and is populated in the order (position) of each argument.