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 (int argc, char *argv[], const GOptions &user_defined_options)
 
void defineSwitch (const std::string &name, const std::string &description)
 Defines and adds a command-line switch to the map of switches. More...
 
void defineOption (const GVariable &gvar, const std::string &help)
 Defines and adds a scalar option to the map of options. 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 option to the map of options. More...
 
int getScalarInt (const std::string &tag) const
 Retrieves the value of a scalar integer option. More...
 
float getScalarFloat (const std::string &tag) const
 Retrieves the value of a scalar float 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...
 
const YAML::Node getOptionNode (const std::string &tag) const
 Retrieves the YAML::Node of the specified option. More...
 
YAML::Node getOptionMapInNode (string option_name, string map_key)
 Retrieves a map option within a YAML::Node. More...
 
int getVerbosityFor (const std::string &tag) const
 Retrieves the verbosity level for a given tag. More...
 
const std::vector< GOption > & getOptions () const
 Returns the list of all defined options. More...
 
const std::map< std::string, GSwitch > & getSwitches () const
 Returns the map of all defined switches. More...
 
void addGOptions (const GOptions &goptions_to_add)
 Adds a set of GOptions to the current options. More...
 
template<typename T >
get_variable_in_option (const YAML::Node &node, const string &variable_name, const T &default_value)
 Retrieves a variable from a YAML::Node. More...
 
std::vector< std::string > getYamlFiles () const
 Retrieves the list of YAML files. More...
 

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 22 of file goptions.h.

Constructor & Destructor Documentation

◆ GOptions() [1/2]

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/2]

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

Library based constructor: each library can define its own options,

Parameters
argcnumber of arguments, passed from "main"
argvargument arrays of *chars, passed from main
user_defined_optionsvector of user options, usually returned by a defineOptions() function

Definition at line 21 of file goptions.cc.

Member Function Documentation

◆ addGOptions()

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

Definition at line 158 of file goptions.h.

◆ defineOption() [1/2]

void GOptions::defineOption ( const GVariable gvar,
const std::string &  help 
)
Parameters
gvarThe GVariable object representing the scalar option.
helpThe help message for the option.

Definition at line 182 of file goptions.cc.

◆ defineOption() [2/2]

void GOptions::defineOption ( const std::string &  name,
const std::string &  description,
const std::vector< GVariable > &  gvars,
const std::string &  help 
)
Parameters
nameThe name of the option.
descriptionThe description of the option.
gvarsA vector of GVariable objects representing the structured option.
helpThe help message for the option.

Definition at line 193 of file goptions.cc.

◆ defineSwitch()

void GOptions::defineSwitch ( const std::string &  name,
const std::string &  description 
)
Parameters
nameThe name of the switch.
descriptionThe description of the switch.

Definition at line 172 of file goptions.cc.

◆ get_variable_in_option()

template<typename T >
template bool GOptions::get_variable_in_option< bool > ( const YAML::Node &  node,
const string &  variable_name,
const T &  default_value 
)
Parameters
nodeThe YAML::Node containing the variable.
variable_nameThe name of the variable.
default_valueThe default value to return if the variable is not found.
Returns
The value of the variable.

Definition at line 408 of file goptions.cc.

◆ getOptionMapInNode()

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

Definition at line 388 of file goptions.cc.

◆ getOptionNode()

const 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 113 of file goptions.h.

◆ getOptions()

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

Definition at line 144 of file goptions.h.

◆ getScalarDouble()

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

Definition at line 227 of file goptions.cc.

◆ getScalarFloat()

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

Definition at line 215 of file goptions.cc.

◆ getScalarInt()

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

Definition at line 203 of file goptions.cc.

◆ getScalarString()

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

Definition at line 239 of file goptions.cc.

◆ getSwitch()

bool GOptions::getSwitch ( const std::string &  tag) const
Parameters
tagThe name of the switch.
Returns
The boolean status of the switch.

Definition at line 374 of file goptions.cc.

◆ getSwitches()

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

Definition at line 151 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 426 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 183 of file goptions.h.


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