cppassist  1.0.0.f4fab4f962ff
C++ sanctuary for small but powerful and frequently required, stand alone features.
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cppassist::CommandLineOption Class Reference

Command line option. More...

#include <cppassist/include/cppassist/cmdline/CommandLineOption.h>

Public Types

enum  OptionalState { NonOptional = 0, Optional = 1 }
 State whether or not an option is optional. More...
 

Public Member Functions

 CommandLineOption (const std::string &longName, const std::string &shortName, const std::string &valueName, const std::string &description, OptionalState optional=Optional)
 Constructor. More...
 
 ~CommandLineOption ()
 Destructor. More...
 
const std::string & name () const
 Get name. More...
 
const std::string & names () const
 Get names. More...
 
const std::string & longName () const
 Get long name. More...
 
void setLongName (const std::string &longName)
 Set long name. More...
 
const std::string & shortName () const
 Get short name. More...
 
void setShortName (const std::string &shortName)
 Set short name. More...
 
const std::string & valueName () const
 Get value name. More...
 
void setValueName (const std::string &name)
 Set value name. More...
 
const std::string & description () const
 Get description. More...
 
void setDescription (const std::string &description)
 Set description. More...
 
bool isOptional () const
 Check optional-flag. More...
 
OptionalState optional () const
 Check optional-flag. More...
 
void setOptional (OptionalState optional)
 Set optional-flag. More...
 
const std::string & value () const
 Get value. More...
 
void setValue (const std::string &value)
 Set value. More...
 

Protected Member Functions

void updateNames ()
 Update m_names. More...
 

Protected Attributes

std::string m_longName
 Long name (e.g., "--config-file") More...
 
std::string m_shortName
 Short name (e.g., "-c") More...
 
std::string m_names
 String containing both the short and long name (e.g., "-c, --config-file") More...
 
std::string m_valueName
 Value name (e.g., "filename") More...
 
std::string m_description
 Description text. More...
 
OptionalState m_optional
 Optional-state. More...
 
std::string m_value
 Option value. More...
 

Detailed Description

Command line option.

A command line option is a named value than can be specified on the command line. It can have a long and a short version. Immediatly after the option itself, the value must be specified on the command line.

Example: myapp [--config-file <filename>]

CommandLineOption optionConfigFile(
"--config-file", "-c",
"filename",
"Specify path to configuration file",

Member Enumeration Documentation

◆ OptionalState

State whether or not an option is optional.

Enumerator
NonOptional 
Optional 

Constructor & Destructor Documentation

◆ CommandLineOption()

cppassist::CommandLineOption::CommandLineOption ( const std::string &  longName,
const std::string &  shortName,
const std::string &  valueName,
const std::string &  description,
OptionalState  optional = Optional 
)

Constructor.

Parameters
[in]longNameLong name (e.g., "--config-file")
[in]shortNameShort name (e.g., "-c")
[in]valueNameName of the value (only relevant for the help text)
[in]descriptionDescription text
[in]optionalOptional-state

◆ ~CommandLineOption()

cppassist::CommandLineOption::~CommandLineOption ( )

Destructor.

Member Function Documentation

◆ name()

const std::string& cppassist::CommandLineOption::name ( ) const

Get name.

Returns
Long name if available, else short name

◆ names()

const std::string& cppassist::CommandLineOption::names ( ) const

Get names.

Returns
String containing both the short and long name (e.g., "-c, --config-file")

◆ longName()

const std::string& cppassist::CommandLineOption::longName ( ) const

Get long name.

Returns
Long name (e.g., "--config-file")

◆ setLongName()

void cppassist::CommandLineOption::setLongName ( const std::string &  longName)

Set long name.

Parameters
[in]longNameLong name (e.g., "--config-file")

◆ shortName()

const std::string& cppassist::CommandLineOption::shortName ( ) const

Get short name.

Returns
Short name (e.g., "-c")

◆ setShortName()

void cppassist::CommandLineOption::setShortName ( const std::string &  shortName)

Set short name.

Parameters
[in]shortNameShort name (e.g., "-c")

◆ valueName()

const std::string& cppassist::CommandLineOption::valueName ( ) const

Get value name.

Returns
Value name (e.g., "filename")

◆ setValueName()

void cppassist::CommandLineOption::setValueName ( const std::string &  name)

Set value name.

Parameters
[in]nameValue name (e.g., "filename")

◆ description()

const std::string& cppassist::CommandLineOption::description ( ) const

Get description.

Returns
Description text

◆ setDescription()

void cppassist::CommandLineOption::setDescription ( const std::string &  description)

Set description.

Parameters
[in]descriptionDescription text

◆ isOptional()

bool cppassist::CommandLineOption::isOptional ( ) const

Check optional-flag.

Returns
true if optional, else false

◆ optional()

OptionalState cppassist::CommandLineOption::optional ( ) const

Check optional-flag.

Returns
Optional-state

◆ setOptional()

void cppassist::CommandLineOption::setOptional ( OptionalState  optional)

Set optional-flag.

Parameters
[in]optionalOptional-state

◆ value()

const std::string& cppassist::CommandLineOption::value ( ) const

Get value.

Returns
Option value

◆ setValue()

void cppassist::CommandLineOption::setValue ( const std::string &  value)

Set value.

Parameters
[in]valueOption value

◆ updateNames()

void cppassist::CommandLineOption::updateNames ( )
protected

Update m_names.

Member Data Documentation

◆ m_longName

std::string cppassist::CommandLineOption::m_longName
protected

Long name (e.g., "--config-file")

◆ m_shortName

std::string cppassist::CommandLineOption::m_shortName
protected

Short name (e.g., "-c")

◆ m_names

std::string cppassist::CommandLineOption::m_names
protected

String containing both the short and long name (e.g., "-c, --config-file")

◆ m_valueName

std::string cppassist::CommandLineOption::m_valueName
protected

Value name (e.g., "filename")

◆ m_description

std::string cppassist::CommandLineOption::m_description
protected

Description text.

◆ m_optional

OptionalState cppassist::CommandLineOption::m_optional
protected

Optional-state.

◆ m_value

std::string cppassist::CommandLineOption::m_value
protected

Option value.


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