goptions
Loading...
Searching...
No Matches
GSwitch Class Reference

Represents a boolean command-line switch with a description and a status. More...

#include <gswitch.h>

Public Member Functions

 GSwitch ()=default
 Default constructor.
 
 GSwitch (const std::string &d)
 Parameterized constructor.
 
void turnOn ()
 Turns the switch on.
 
void turnOff ()
 Turns the switch off.
 
bool getStatus () const
 Retrieves the current status of the switch.
 
const std::string & getDescription () const
 Retrieves the description of the switch.
 

Detailed Description

A switch is a presence-based boolean flag:

  • Default: off (false)
  • If specified on the command line (e.g., -gui), it becomes on (true).

Switches are stored by GOptions : and are typically used for enabling/disabling optional behaviors in an application (GUI, interactive mode, logging toggles, etc.).

Design intent:

  • Lightweight value type suitable for storage in associative containers.
  • Description text is meant for human-facing help output.
  • Status is intentionally binary: either present (on) or absent (off).

Definition at line 27 of file gswitch.h.

Constructor & Destructor Documentation

◆ GSwitch() [1/2]

GSwitch::GSwitch ( )
default

Constructs an empty GSwitch : with default-initialized members. This constructor is required for use in associative containers (e.g., std::map<std::string, GSwitch>), where default construction may occur during insertion/lookup.

◆ GSwitch() [2/2]

GSwitch::GSwitch ( const std::string & d)
inline

Initializes the switch description and forces the status to false (off). This guarantees that defining a switch never enables it implicitly; only parsing or explicit programmatic calls enable it.

Parameters
dHuman-readable description of what enabling this switch does.

Definition at line 50 of file gswitch.h.

Member Function Documentation

◆ getDescription()

const std::string & GSwitch::getDescription ( ) const
inline
Returns
A const reference to the switch's description string.

Definition at line 83 of file gswitch.h.

◆ getStatus()

bool GSwitch::getStatus ( ) const
inline
Returns
true if the switch is on; false otherwise.

Definition at line 76 of file gswitch.h.

◆ turnOff()

void GSwitch::turnOff ( )
inline

Sets the internal status to false. This is typically used programmatically (not by parsing) when a system wants to enforce a default or override state.

Definition at line 69 of file gswitch.h.

◆ turnOn()

void GSwitch::turnOn ( )
inline

Sets the internal status to true. In practice, GOptions : calls this when it encounters the switch name on the command line.

Definition at line 60 of file gswitch.h.


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