Command line switch.
More...
#include <cppassist/include/cppassist/cmdline/CommandLineSwitch.h>
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]
"--debug", "-d",
"Enabled debug mode",
◆ OptionalState
State whether or not a switch is optional.
Enumerator |
---|
NonOptional | |
Optional | |
◆ CommandLineSwitch()
cppassist::CommandLineSwitch::CommandLineSwitch |
( |
const std::string & |
longName, |
|
|
const std::string & |
shortName, |
|
|
const std::string & |
description, |
|
|
OptionalState |
optional = Optional |
|
) |
| |
Constructor.
- Parameters
-
[in] | longName | Long name (e.g., "--debug") |
[in] | shortName | Short name (e.g., "-d") |
[in] | description | Description text |
[in] | optional | Optional-state |
◆ ~CommandLineSwitch()
cppassist::CommandLineSwitch::~CommandLineSwitch |
( |
| ) |
|
◆ 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] | longName | Long 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] | shortName | Short 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] | description | Description text |
◆ isOptional()
bool cppassist::CommandLineSwitch::isOptional |
( |
| ) |
const |
Check optional-flag.
- Returns
true
if optional, else false
◆ optional()
Check optional-flag.
- Returns
- Optional-state
◆ setOptional()
void cppassist::CommandLineSwitch::setOptional |
( |
OptionalState |
optional | ) |
|
Set optional-flag.
- Parameters
-
[in] | optional | Optional-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] | activated | true 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] | count | Activation count |
◆ updateNames()
void cppassist::CommandLineSwitch::updateNames |
( |
| ) |
|
|
protected |
◆ m_longName
std::string cppassist::CommandLineSwitch::m_longName |
|
protected |
Long name (e.g., "--debug")
◆ m_shortName
std::string cppassist::CommandLineSwitch::m_shortName |
|
protected |
◆ 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 |
◆ m_optional
◆ m_activated
bool cppassist::CommandLineSwitch::m_activated |
|
protected |
true
if activated, else false
◆ m_count
unsigned int cppassist::CommandLineSwitch::m_count |
|
protected |
The documentation for this class was generated from the following file: