goptions
GOptions Class Reference

The GOptions class manages command-line options and switches. More...

#include <goptions.h>

Collaboration diagram for GOptions:
Collaboration graph

Public Member Functions

 GOptions ()
 Default constructor. More...
 
 GOptions (std::string name)
 Constructor for verbosity and debug options. More...
 
 GOptions (int argc, char *argv[], const GOptions &user_defined_options=GOptions())
 Library–based constructor. More...
 
 ~GOptions ()
 
void defineSwitch (const std::string &name, const std::string &description)
 Defines and adds a command–line switch. More...
 
void defineOption (const GVariable &gvar, const std::string &help)
 Defines and adds a scalar option. More...
 
void defineOption (const std::string &name, const std::string &description, const std::vector< GVariable > &gvars, const std::string &help)
 Defines and adds a structured (map/sequence) option. More...
 
int getScalarInt (const std::string &tag) const
 Retrieves the value of a scalar integer option. More...
 
double getScalarDouble (const std::string &tag) const
 Retrieves the value of a scalar double option. More...
 
std::string getScalarString (const std::string &tag) const
 Retrieves the value of a scalar string option. More...
 
bool getSwitch (const std::string &tag) const
 Retrieves the status of a switch. More...
 
YAML::Node getOptionNode (const std::string &tag) const
 Retrieves the YAML node for the specified option. More...
 
YAML::Node getOptionMapInNode (const std::string &option_name, const std::string &map_key) const
 Retrieves a map option’s value from within a YAML node. More...
 
int getVerbosityFor (const std::string &tag) const
 Retrieves the verbosity level for the specified tag. More...
 
int getDebugFor (const std::string &tag) const
 Retrieves the debug level for the specified tag. More...
 
const std::vector< GOption > & getOptions () const
 Returns the list of defined options. More...
 
const std::map< std::string, GSwitch > & getSwitches () const
 Returns the map of defined switches. More...
 
void addGOptions (const GOptions &goptions_to_add)
 Adds options from another GOptions object. More...
 
void addOptionTitle (const std::string &name)
 
template<typename T >
get_variable_in_option (const YAML::Node &node, const std::string &variable_name, const T &default_value)
 Retrieves a variable from a YAML node within an option. More...
 
std::vector< std::string > getYamlFiles () const
 Retrieves the list of YAML file paths. More...
 
bool doesOptionExist (const std::string &tag) const
 Checks if the specified option exists. More...
 

Data Fields

std::string option_verbosity_name {UNINITIALIZEDSTRINGQUANTITY}
 
std::vector< GVariableoption_verbosity_names
 

Detailed Description

This class provides methods to define, access, and manage configuration options and switches for command-line applications. Options can be scalar or sequence-based and are stored in YAML format.

Definition at line 24 of file goptions.h.

Constructor & Destructor Documentation

◆ GOptions() [1/3]

GOptions::GOptions ( )
inline

Creates an empty GOptions object, typically used for defining user–defined options.

Definition at line 31 of file goptions.h.

◆ GOptions() [2/3]

GOptions::GOptions ( std::string  name)
inlineexplicit
Parameters
nameverbosity and debug option name

Definition at line 39 of file goptions.h.

◆ GOptions() [3/3]

GOptions::GOptions ( int  argc,
char *  argv[],
const GOptions user_defined_options = GOptions() 
)

Constructs a GOptions object.

Constructs a GOptions object by initializing built–in options and switches, loading user-defined options, parsing YAML files, and processing command line arguments.

Parameters
argcNumber of command–line arguments.
argvArray of command–line argument strings.
user_defined_optionsA GOptions object containing user–defined options.

This constructor performs the following tasks:

  • Loads user-defined options.
  • Defines built-in options and switches.
  • Parses YAML configuration files.
  • Processes command-line arguments (supporting both YAML–style and dot–notation).
  • Saves the final configuration to a YAML file.
Parameters
argcNumber of command-line arguments.
argvArray of command-line argument strings.
user_defined_optionsA GOptions object containing user-defined options.

Definition at line 29 of file goptions.cc.

◆ ~GOptions()

GOptions::~GOptions ( )
inline

Definition at line 54 of file goptions.h.

Member Function Documentation

◆ addGOptions()

void GOptions::addGOptions ( const GOptions goptions_to_add)
inline
Parameters
goptions_to_addThe GOptions object to add.

Definition at line 170 of file goptions.h.

◆ addOptionTitle()

void GOptions::addOptionTitle ( const std::string &  name)
inline

Definition at line 179 of file goptions.h.

◆ defineOption() [1/2]

void GOptions::defineOption ( const GVariable gvar,
const std::string &  help 
)
Parameters
gvarA GVariable representing the option.
helpHelp text for the option.
gvarThe GVariable representing the option.
helpHelp text for the option.

Definition at line 181 of file goptions.cc.

◆ defineOption() [2/2]

void GOptions::defineOption ( const std::string &  name,
const std::string &  description,
const std::vector< GVariable > &  g_vars,
const std::string &  help 
)

Defines and adds a structured option.

Parameters
nameThe name of the option.
descriptionA summary description of the option.
gvarsA vector of GVariable objects representing the option elements.
helpHelp text for the option.
nameThe name of the option.
descriptionSummary description of the option.
g_varsVector of GVariable objects representing the option elements.
helpHelp text for the option.

Definition at line 199 of file goptions.cc.

◆ defineSwitch()

void GOptions::defineSwitch ( const std::string &  name,
const std::string &  description 
)

Defines and adds a command-line switch.

Parameters
nameThe name of the switch.
descriptionThe description of the switch.

Definition at line 165 of file goptions.cc.

◆ doesOptionExist()

bool GOptions::doesOptionExist ( const std::string &  tag) const
Parameters
tagThe name of the option.
Returns
True if the option exists; false otherwise.

Definition at line 301 of file goptions.cc.

◆ get_variable_in_option()

template<typename T >
template bool GOptions::get_variable_in_option< bool > ( const YAML::Node &  node,
const std::string &  variable_name,
const T &  default_value 
)

Template function to retrieve a variable from a YAML node.

Template Parameters
TThe type of the variable.
Parameters
nodeThe YAML node.
variable_nameThe name of the variable.
default_valueThe default value if the variable is not found.
Returns
The variable value.

Definition at line 444 of file goptions.cc.

◆ getDebugFor()

int GOptions::getDebugFor ( const std::string &  tag) const

Accepts values as either booleans ("true"/"false") or integers.

Parameters
tagThe name of the debug option.
Returns
The debug level as an integer.

Definition at line 484 of file goptions.cc.

◆ getOptionMapInNode()

YAML::Node GOptions::getOptionMapInNode ( const std::string &  option_name,
const std::string &  map_key 
) const
Parameters
option_nameThe name of the option.
map_keyThe key within the option.
Returns
The YAML::Node corresponding to the specified map key.
Parameters
option_nameThe name of the option.
map_keyThe key to look up within the option.
Returns
The YAML::Node corresponding to the specified map key.

Definition at line 420 of file goptions.cc.

◆ getOptionNode()

YAML::Node GOptions::getOptionNode ( const std::string &  tag) const
inline
Parameters
tagThe name of the option.
Returns
The YAML::Node containing the option's value.

Definition at line 121 of file goptions.h.

◆ getOptions()

const std::vector<GOption>& GOptions::getOptions ( ) const
inline
Returns
A vector of GOption objects.

Definition at line 158 of file goptions.h.

◆ getScalarDouble()

double GOptions::getScalarDouble ( const std::string &  tag) const
Parameters
tagThe name of the option.
Returns
The double value.

Definition at line 232 of file goptions.cc.

◆ getScalarInt()

int GOptions::getScalarInt ( const std::string &  tag) const
Parameters
tagThe name of the option.
Returns
The integer value.

Definition at line 216 of file goptions.cc.

◆ getScalarString()

string GOptions::getScalarString ( const std::string &  tag) const
Parameters
tagThe name of the option.
Returns
The string value.

Definition at line 248 of file goptions.cc.

◆ getSwitch()

bool GOptions::getSwitch ( const std::string &  tag) const

Retrieves the status of the specified switch.

Parameters
tagThe name of the switch.
Returns
True if the switch is on; false otherwise.

Definition at line 402 of file goptions.cc.

◆ getSwitches()

const std::map<std::string, GSwitch>& GOptions::getSwitches ( ) const
inline
Returns
A map of switches.

Definition at line 164 of file goptions.h.

◆ getVerbosityFor()

int GOptions::getVerbosityFor ( const std::string &  tag) const
Parameters
tagThe name of the verbosity option.
Returns
The verbosity level as an integer.

Definition at line 463 of file goptions.cc.

◆ getYamlFiles()

std::vector<std::string> GOptions::getYamlFiles ( ) const
inline
Returns
A vector of YAML file paths as strings.

Definition at line 199 of file goptions.h.

Field Documentation

◆ option_verbosity_name

std::string GOptions::option_verbosity_name {UNINITIALIZEDSTRINGQUANTITY}

Definition at line 176 of file goptions.h.

◆ option_verbosity_names

std::vector<GVariable> GOptions::option_verbosity_names

Definition at line 177 of file goptions.h.


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