LibCppCmd v1.0 Beta 15
C++ Command Line Parsing Library
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
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 ProgParam.
 
std::string Description () const override
 Gets the description of the ProgParam.
 
bool IsSpecified () const override
 Indicates whether the ProgParam has been specified.
 
bool IsMandatory () const override
 Indicates whether the ProgParam is mandatory.
 
std::string HelpInfo () const override
 Gets help info for the ProgParam.
 
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 ProgramParameter is a CommandLine ArgumentParameter that is populated by the program name argument, which is the first CommandLine argument the OS passes to the program by convention. Upon successful population, the ProgramParameter's value will be populated by the program name argument, which will also mark the ProgramParameter as specified. Even if the value of the program argument is not important to the program, the ProgramParameter's name is still used to represent the program when the parser generates help and usage info.

Constructor & Destructor Documentation

◆ ProgParam()

CmdLine::ProgParam::ProgParam ( Definition d)

Constructs a new ProgParam.

Parameters
dThe definition to construct the ProgParam with.
Invariant
Name must be non-empty.
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::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
argumentsThe 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
argumentsThe 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 ProgParam.

The description of the ProgParam is used for generating help.

Returns
The description of the ProgParam.

Implements CmdLine::Param.

◆ HelpInfo()

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

Gets help info for the ProgParam.

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

Returns
Help info for the ProgParam.

Implements CmdLine::Param.

◆ IsMandatory()

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

Indicates whether the ProgParam is mandatory.

The command line Parser uses this to determine if the program name argument must be specified at the command line for parsing to be successful. If a mandatory ProgParam is not specified i.e. the correct command line argument necessary to populate the ProgParam was not supplied, parsing will fail indicating the program was supplied with bad command line arguments.

Returns
True if the ProgParam 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 ProgParam.

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

Returns
The name of the ProgParam.

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: