LibCppCmd v1.0 Beta 15
C++ Command Line Parsing Library
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
CmdLine::MultiPosParam Class Reference

A multi-value PosParam. More...

#include <MultiPosParam.h>

Inheritance diagram for CmdLine::MultiPosParam:
CmdLine::ArgParam CmdLine::Param

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.
 

Detailed Description

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.

Member Enumeration Documentation

◆ ParsingOrder

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. 

Constructor & Destructor Documentation

◆ MultiPosParam()

CmdLine::MultiPosParam::MultiPosParam ( Definition d)

Constructs a new MultiPosParam.

Parameters
dThe Definition used to create the MultiPosParam.
Invariant
Name must be non-empty.
Name must contain only alpha numerics or - and _.
Name must not be longer than 20 characters.
Name must not start with an option prefix.
Can only be specified upon successful population.
Values can only be added upon successful population.
Exceptions
Param::InvalidDefinitionDoesn't satisfy invariants.

Member Function Documentation

◆ CanPopulate()

bool CmdLine::MultiPosParam::CanPopulate ( const std::deque< std::string > & args) const
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.

Parameters
argsThe argument queue to evaluate.
Returns
True if the arguments can populate, otherwise false.

Implements CmdLine::ArgParam.

◆ Consumes()

std::size_t CmdLine::MultiPosParam::Consumes ( const std::deque< std::string > & args) const
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.

Parameters
argsThe argument queue to evaluate.
Returns
The number of arguments the MultiPosParam will consume.

Implements CmdLine::ArgParam.

◆ Description()

std::string CmdLine::MultiPosParam::Description ( ) const
inlineoverridevirtual

Getst the description of the MultiPosParam.

The description of the MultiPosParam is used for generating HelpInfo().

Returns
The description of the MultiPosParam.

Implements CmdLine::Param.

◆ HelpInfo()

std::string CmdLine::MultiPosParam::HelpInfo ( ) const
overridevirtual

Gets help information for the MultiPosParam.

The help info will include the Name() and Description() of the MultiPosParam when generating help.

Returns
Help information for the MultiPosParam.

Implements CmdLine::Param.

◆ IsMandatory()

bool CmdLine::MultiPosParam::IsMandatory ( ) const
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.

Returns
True if the MultiPosParam is mandatory, otherwise false.

Implements CmdLine::Param.

◆ IsSpecified()

bool CmdLine::MultiPosParam::IsSpecified ( ) const
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.

Returns
True if the MultiPosParam is specified, otherwise false.

Implements CmdLine::Param.

◆ Name()

std::string CmdLine::MultiPosParam::Name ( ) const
inlineoverridevirtual

Gets the name of the MultiPosParam.

The name of the MultiPosParam is used for generating usage and HelpInfo().

Returns
The name of the MultiPosParam.

Implements CmdLine::Param.

◆ Order()

ParsingOrder CmdLine::MultiPosParam::Order ( ) const
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.

Returns
The ParsingOrder of the MultiPosParam.

◆ Populate()

bool CmdLine::MultiPosParam::Populate ( std::deque< std::string > & args)
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.

Parameters
argsThe arguments to populate the MultiPosParam.
Returns
True if population is successful, otherwise false.
Precondition
Size of arguments > 0.
All arguments are non-options.
Postcondition
The MultiPosParam is marked specified.
The argument queue, arguments, is emtpied.
Consumed arguments are added to the MultiPosParam values.

Implements CmdLine::ArgParam.

◆ Values()

std::vector< std::string > CmdLine::MultiPosParam::Values ( ) const
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.

Returns
The values the MultiPosParam was populated with.

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