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

Provides parameters for ValueOption values. More...

#include <OptionParam.h>

Inheritance diagram for CmdLine::OptionParam:
CmdLine::Param

Classes

struct  Definition
 This definition is used to construct an OptionParam. More...
 

Public Member Functions

 OptionParam (Definition definition)
 Constructs a new OptionParam.
 
std::string Name () const override
 Gets the name of the OptionParam.
 
std::string Description () const override
 Getst the description of the OptionParam.
 
std::string HelpInfo () const override
 Gets help info for the OptionParam.
 
bool IsSpecified () const override
 Indicates whether the OptionParam has been specified.
 
bool IsMandatory () const override
 Indicates whether the OptionParam is mandatory.
 
std::string Value () const
 Gets the value the OptionParam was populated with.
 
bool Populate (NameValuePair p)
 Populates the OptionParam from a NameValuePair.
 
bool CanPopulate (NameValuePair p) const
 Checks if the NameValuePair can populate OptionParam.
 
- Public Member Functions inherited from CmdLine::Param
virtual ~Param ()=default
 Destructs a Param.
 

Detailed Description

Provides parameters for ValueOption values.

An OptionParam provides a way for a program to capture specific values passed to a ValueOption. OptionParams can be added to ValueOptions for this purpose. This is useful for ValueOptions that have a specific list of possible values when the program needs to check that one or more of those possible values was specified. The name of the OptionParam defines the possible Option value. If the value passed to the ValueOption at the command line is a NameValuePair, the the OptionParam will not only indicate that the name was specified as a possible value, it will also have its own value (the value of the NameValuePair). For example, assume a ValueOption "--print" instructs a program to print metadata values for a song. Assume the possible values for the "--print" ValueOption are "song", "artist", and "album". In this case you would add three OptionParams to the "--print" ValueOption. Assume then that the user specifies "--print song" at the command line. The OptionParam "song" would be specified but have no value of its own. Now assume the same program has an "--edit" ValueOption to change those same metadata properties. If the users specified "--edit 'song=Happy Birthday'", the "song" OptionParam would be specified and have the value "Happy Birthday".

Constructor & Destructor Documentation

◆ OptionParam()

CmdLine::OptionParam::OptionParam ( Definition definition)

Constructs a new OptionParam.

Parameters
definitionThe definition to construct the OptionParam.
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.
Value is only set by successful population.
Can only be specified upon successful population.
Exceptions
Parame:InvalidDefinitionDoesn't satisfy invariants.

Member Function Documentation

◆ CanPopulate()

bool CmdLine::OptionParam::CanPopulate ( NameValuePair p) const

Checks if the NameValuePair can populate OptionParam.

Parameters
pThe NameValuePair to evaluate.
Returns
True if it can populate, otherwise false.

◆ Description()

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

Getst the description of the OptionParam.

The description of the OptionParam is used for generating help.

Returns
The description of the OptionParam.

Implements CmdLine::Param.

◆ HelpInfo()

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

Gets help info for the OptionParam.

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

Returns
Help info for the OptionParam.

Implements CmdLine::Param.

◆ IsMandatory()

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

Indicates whether the OptionParam is mandatory.

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

Returns
True if the OptionParam is mandatory, otherwise false.

Implements CmdLine::Param.

◆ IsSpecified()

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

Indicates whether the OptionParam has been specified.

An OptionParam will only indicate it was specified if the OptionParam has been successfully populated by an OptionValue. The Parser also uses this to determine if a mandatory OptionParam has been specified.

Returns
True if the parameter is specified, otherwise false.

Implements CmdLine::Param.

◆ Name()

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

Gets the name of the OptionParam.

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

Returns
The name of the OptionParam.

Implements CmdLine::Param.

◆ Populate()

bool CmdLine::OptionParam::Populate ( NameValuePair p)

Populates the OptionParam from a NameValuePair.

An OptionParam is populated from a NameValuePair that represents an argument (value) that was passed to the ValueOption at the command line. If the NameValuePair itself does not specifiy a value, population will only mark the OptionParam as specified, otherwise it will both specify the OptionParam and populate its value.

Parameters
pThe NameValuePair to populate the OptionParam with.
Returns
True if population was successful, otherwise false.
Precondition
The pair's name must match the OptionParam's name.
Postcondition
The OptionParam is marked as specified.
If there was a value, the value will be set.

◆ Value()

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

Gets the value the OptionParam was populated with.

The value of an OptionParam is the value of a NameValuePair passed to the ValueOption at the command line. If just a name was passed, the value will be an empty string.

Returns
The value of the OptionParam.

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