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::CommandLineSwitch Class Reference

Command line switch. More...

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

Public Types

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

Public Member Functions

 CommandLineSwitch (const std::string &longName, const std::string &shortName, const std::string &description, OptionalState optional=Optional)
 Constructor. More...
 
 ~CommandLineSwitch ()
 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 & 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...
 
bool activated () const
 Check if switch has been activated. More...
 
void setActivated (bool activated)
 Set if switch has been activated. More...
 
unsigned int count () const
 Get number of times the switch has been activated. More...
 
void setCount (unsigned int count)
 Set number of times the switch has been activated. More...
 

Protected Member Functions

void updateNames ()
 Update m_names. More...
 

Protected Attributes

std::string m_longName
 Long name (e.g., "--debug") More...
 
std::string m_shortName
 Short name (e.g., "-d") More...
 
std::string m_names
 String containing both the short and long name (e.g., "-d, --debug") More...
 
std::string m_description
 Description text. More...
 
OptionalState m_optional
 Optional-state. More...
 
bool m_activated
 true if activated, else false More...
 
unsigned int m_count
 Activation count. More...
 

Detailed Description

Command line switch.

A command line switch is a binary option that can be turned on by specifying the switch on the command line. It can have a long and a short version. If the switch isn't specified on the command line, it is turned off by default.

Example: myapp [--debug]

CommandLineSwitch switchDebug(
"--debug", "-d",
"Enabled debug mode",

Member Enumeration Documentation

◆ OptionalState

State whether or not a switch is optional.

Enumerator
NonOptional 
Optional 

Constructor & Destructor Documentation

◆ CommandLineSwitch()

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

Constructor.

Parameters
[in]longNameLong name (e.g., "--debug")
[in]shortNameShort name (e.g., "-d")
[in]descriptionDescription text
[in]optionalOptional-state

◆ ~CommandLineSwitch()

cppassist::CommandLineSwitch::~CommandLineSwitch ( )

Destructor.

Member Function Documentation

◆ name()

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

Get name.

Returns
Long name if available, else short name

◆ names()

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

Get names.

Returns
String containing both the short and long name (e.g., "-d, --debug")

◆ longName()

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

Get long name.

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

◆ setLongName()

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

Set long name.

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

◆ shortName()

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

Get short name.

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

◆ setShortName()

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

Set short name.

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

◆ description()

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

Get description.

Returns
Description text

◆ setDescription()

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

Set description.

Parameters
[in]descriptionDescription text

◆ isOptional()

bool cppassist::CommandLineSwitch::isOptional ( ) const

Check optional-flag.

Returns
true if optional, else false

◆ optional()

OptionalState cppassist::CommandLineSwitch::optional ( ) const

Check optional-flag.

Returns
Optional-state

◆ setOptional()

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

Set optional-flag.

Parameters
[in]optionalOptional-state

◆ activated()

bool cppassist::CommandLineSwitch::activated ( ) const

Check if switch has been activated.

Returns
true if activated, else false

◆ setActivated()

void cppassist::CommandLineSwitch::setActivated ( bool  activated)

Set if switch has been activated.

Parameters
[in]activatedtrue if activated, else false

◆ count()

unsigned int cppassist::CommandLineSwitch::count ( ) const

Get number of times the switch has been activated.

Returns
Activation count

◆ setCount()

void cppassist::CommandLineSwitch::setCount ( unsigned int  count)

Set number of times the switch has been activated.

Parameters
[in]countActivation count

◆ updateNames()

void cppassist::CommandLineSwitch::updateNames ( )
protected

Update m_names.

Member Data Documentation

◆ m_longName

std::string cppassist::CommandLineSwitch::m_longName
protected

Long name (e.g., "--debug")

◆ m_shortName

std::string cppassist::CommandLineSwitch::m_shortName
protected

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

◆ m_names

std::string cppassist::CommandLineSwitch::m_names
protected

String containing both the short and long name (e.g., "-d, --debug")

◆ m_description

std::string cppassist::CommandLineSwitch::m_description
protected

Description text.

◆ m_optional

OptionalState cppassist::CommandLineSwitch::m_optional
protected

Optional-state.

◆ m_activated

bool cppassist::CommandLineSwitch::m_activated
protected

true if activated, else false

◆ m_count

unsigned int cppassist::CommandLineSwitch::m_count
protected

Activation count.


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