LibCppCmdLine v1.0
A cross-platform C++ library for parsing command line arguments
Loading...
Searching...
No Matches
CmdLine::ProgParam Class Reference

A command line ArgParam populated by the program name. More...

#include <ProgParam.h>

Inheritance diagram for CmdLine::ProgParam:
CmdLine::ArgParam CmdLine::Param

Classes

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

Public Member Functions

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

A ProgParam is a command line ArgParam that is populated by the program name argument, which is the first command line argument the OS passes to the program by convention. Upon successful population, the parameter's value will be populated by the program name argument, which will also mark the parameter as specified. Even if the value of the program argument is not important to the program, the parameter's name is still used to represent the program when the parser generates help and usage info.

Invariant
Name must be non-empty.
Value can only be set upon successful population.

Constructor & Destructor Documentation

◆ ProgParam()

CmdLine::ProgParam::ProgParam ( Definition d)

Constructs a new ProgParam.

Parameters
dThe definition to construct the ProgParam with.
Exceptions
Param::InvalidDefinitionDoesn't satisfy invariants.

Member Function Documentation

◆ CanPopulate()

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

Determines if arguments can populate this ProgParam.

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

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

Implements CmdLine::ArgParam.

◆ Consumes()

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

Gets the number of arguments the ProgParam consumes.

Each ProgParam consumes exactly 1 argument from the argument queue upon successful population.

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

Implements CmdLine::ArgParam.

◆ Description()

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

Gets the description of the Param.

The description of the Param is used for generating help.

Returns
The description of the Param.

Implements CmdLine::Param.

◆ HelpInfo()

std::string CmdLine::ProgParam::HelpInfo ( ) const
inlineoverridevirtual

Gets help information for the Param.

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

Returns
Help information for the parameter.

Implements CmdLine::Param.

◆ IsMandatory()

bool CmdLine::ProgParam::IsMandatory ( ) const
inlineoverridevirtual

Indicates whether the Param is mandatory.

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

Returns
True if the parameter is mandatory, otherwise false.

Implements CmdLine::Param.

◆ IsSpecified()

bool CmdLine::ProgParam::IsSpecified ( ) const
inlineoverridevirtual

Indicates whether the ProgParam has been specified.

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

Returns
True if the ProgParam is specified, otherwise false.

Implements CmdLine::Param.

◆ Name()

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

Gets the name of the Param.

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

Returns
The name of the Param.

Implements CmdLine::Param.

◆ Populate()

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

Populates this ProgParam from an argument queue.

Accepts a reference to an argument queue (deque) and attempts to populate the ProgParam from the first argument in the queue. Populating the ProgParam marks it as specified and will also populate the ProgParam value with the argument. Successful population also consumes the argument from the queue that populated the argument.

Parameters
argsThe argument queue to populate the parameter with.
Returns
True if population is successful, otherwise false.
Precondition
Size of arguments >= 1.
Postcondition
The ProgParam 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::ProgParam::Value ( ) const
inline

Gets the value of the ProgParam.

The value of the ProgParam will be the same as the first command line argument, which by convention is the program name most operating systems pass to the program by convention.

Returns
The value of the ProgParam.

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