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

A Positional command line ArgParam. More...

#include <PosParam.h>

Inheritance diagram for CmdLine::PosParam:
CmdLine::ArgParam CmdLine::Param

Classes

struct  Definition
 This definition is used to construct a PosParam. More...
 

Public Member Functions

 PosParam (Definition d)
 Constructs a new PosParam.
 
std::string Value () const
 Gets the value of the PosParam.
 
virtual std::string Name () const override
 Gets the name of the PosParam.
 
virtual std::string Description () const override
 Gets the description of the PosParam.
 
virtual std::string HelpInfo () const override
 Gets help info for the PosParam.
 
virtual bool IsSpecified () const override
 Indicates whether the PosParam has been specified.
 
virtual bool IsMandatory () const override
 Indicates whether the PosParam is mandatory.
 
bool Populate (std::deque< std::string > &args) override
 Populates this PosParam from an argument queue.
 
bool CanPopulate (const std::deque< std::string > &args) const override
 Determines if arguments can populate this PosParam.
 
std::size_t Consumes (const std::deque< std::string > &args) const override
 Gets the number of arguments the PosParam consumes.
 
- 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 Positional command line ArgParam.

A PosParam is a command line ArgParam that is populated based on the position of the command line arguments. Exactly one argument populates a PosParam by both specifying it and populating its value. By default, PosParams are populated after all Options have been parsed. However, if a MultiPosParam is also set on the Parser with a MultiPosParam::ParsingOrder of AfterOptions, then PosParams will be populated at the end. An example of when to use a PosParam is a copy program that has multiple source file paths and a single desitination path. The single destination path would populate a PosParam while the multile source paths would be captured by a MultiPosParam.

Constructor & Destructor Documentation

◆ PosParam()

CmdLine::PosParam::PosParam ( Definition d)

Constructs a new PosParam.

Parameters
dThe definition to construct the PosParam with.
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.
Value can only be set upon successful population.
Exceptions
Param::InvalidDefinitionDoesn't satisfy invariants.

Member Function Documentation

◆ CanPopulate()

bool CmdLine::PosParam::CanPopulate ( const std::deque< std::string > & args) const
overridevirtual

Determines if arguments can populate this PosParam.

Accepts a reference to an argument queue (deque) and determines if the next argument in the queue can populate the PosParam.

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

Implements CmdLine::ArgParam.

◆ Consumes()

std::size_t CmdLine::PosParam::Consumes ( const std::deque< std::string > & args) const
inlineoverridevirtual

Gets the number of arguments the PosParam consumes.

Each Positional consumes exactly 1 argument.

Parameters
argumentsThe argument queue to evaluate.
Returns
The number of arguments the PosParam will consume.

Implements CmdLine::ArgParam.

◆ Description()

virtual std::string CmdLine::PosParam::Description ( ) const
inlineoverridevirtual

Gets the description of the PosParam.

The description of the PosParam is used for generating help.

Returns
The description of the PosParam.

Implements CmdLine::Param.

◆ HelpInfo()

virtual std::string CmdLine::PosParam::HelpInfo ( ) const
overridevirtual

Gets help info for the PosParam.

The help info will include the name and description of the PosParam when generating help.

Returns
Help info for the PosParam.

Implements CmdLine::Param.

◆ IsMandatory()

virtual bool CmdLine::PosParam::IsMandatory ( ) const
inlineoverridevirtual

Indicates whether the PosParam is mandatory.

The command line Parser uses this to determine if a PosParam must be specified at the command line for parsing to be successful. If a mandatory PosParam is not specified, parsing will fail indicating the program was supplied with bad command line arguments.

Returns
True if the PosParam is mandatory, otherwise false.

Implements CmdLine::Param.

◆ IsSpecified()

virtual bool CmdLine::PosParam::IsSpecified ( ) const
inlineoverridevirtual

Indicates whether the PosParam has been specified.

A PosParam will only indicate it was specified if it has been successfully populated by a command line argument. The Parser also uses this to determine if a mandatory PosParam has been specified.

Returns
True if the PosParam is specified, otherwise false.

Implements CmdLine::Param.

◆ Name()

virtual std::string CmdLine::PosParam::Name ( ) const
inlineoverridevirtual

Gets the name of the PosParam.

The name of the PosParam is used for generating usage and help.

Returns
The name of the PosParam.

Implements CmdLine::Param.

◆ Populate()

bool CmdLine::PosParam::Populate ( std::deque< std::string > & args)
overridevirtual

Populates this PosParam from an argument queue.

Accepts a reference to an argument queue (deque) and attempts to populate the PosParam from the next argument in the queue. Populating the MultiPosParam marks it as specified and populates it with value from the command line argument. Successful population also consumes the argument from the queue that populated the PosParam.

Parameters
argsThe arguments to populate the PosParam with.
Returns
True if population is successful, otherwise false.
Precondition
Size of arguments >= 1.
Postcondition
The PosParam is marked specified.
The the next argument in the argument queue is removed.
The argument removed populates the the value.

Implements CmdLine::ArgParam.

◆ Value()

std::string CmdLine::PosParam::Value ( ) const
inline

Gets the value of the PosParam.

The value of a PosParam always equals the argument that populated it.

Returns
The value of the PosParam.

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