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

Stores one configuration option (scalar or structured), including schema defaults and current value. More...

#include <goption.h>

Public Member Functions

 GOption (GVariable dv, std::string h)
 Constructor for a scalar option with a default value.
 
 GOption (std::string n, std::string desc, std::vector< GVariable > dv, std::string h)
 Constructor for a structured option schema (map/sequence).
 
void set_sub_option_value (const std::string &subkey, const std::string &subvalue)
 Updates a structured sub-option using dot-notation semantics.
 

Friends

class GOptions
 Grants GOptions : access to private members for parsing and serialization.
 

Detailed Description

GOption : encapsulates:

  • the option name and user-facing description,
  • a default YAML node constructed from the option definition,
  • a current YAML node holding the resolved configuration value(s),
  • structured schema metadata for printing detailed help.

Structured options are defined by a vector of GVariable : entries. If any schema entry uses goptions::NODFLT : as its default, that schema key becomes mandatory and the option becomes cumulative (expects a YAML sequence of maps).

GOptions : is a friend and drives parsing and saving.

Definition at line 104 of file goption.h.

Constructor & Destructor Documentation

◆ GOption() [1/2]

GOption::GOption ( GVariable dv,
std::string h )
inline

Builds YAML nodes of the form:

<name>: <default>

The constructed node is stored in both:

  • defaultValue (schema/default snapshot),
  • value (current resolved value), initially equal to the default.
Parameters
dvScalar option descriptor (name, default value, description).
hMulti-line help text shown in detailed help.

Definition at line 123 of file goption.h.

◆ GOption() [2/2]

GOption::GOption ( std::string n,
std::string desc,
std::vector< GVariable > dv,
std::string h )
inline

The schema is defined by dv, where each GVariable : entry corresponds to one key. The default value node is constructed as a sequence of single-entry maps:

optionName:
- key1: default1
- key2: default2

If any schema entry has value goptions::NODFLT : :

  • that key is added to mandatory_keys
  • the option is flagged cumulative (isCumulative = true)

For non-cumulative structured options, the current value is initialized to the default schema. For cumulative options, the current value is intentionally left unset until user values are provided, because mandatory keys require explicit user input.

Parameters
nOption name.
descOne-line description shown in summary help.
dvSchema entries (keys, defaults, descriptions).
hMulti-line help text shown in detailed help.

Definition at line 153 of file goption.h.

Member Function Documentation

◆ set_sub_option_value()

void GOption::set_sub_option_value ( const std::string & subkey,
const std::string & subvalue )

For a command-line payload like:

-verbosity.general=2

GOptions : locates the GOption : for "verbosity" and calls this method to update the "general" entry.

Update rules:

  • If the stored value is a YAML sequence of maps: every map entry that contains subkey is updated.
  • If the stored value is a YAML map: the map entry subkey is updated.
  • If subkey does not exist in the stored structured value, the program exits with EC__NOOPTIONFOUND .
Parameters
subkeyThe sub-option key to update.
subvalueThe new value expressed as a string; it is parsed as YAML.

Definition at line 270 of file goption.cc.

Friends And Related Symbol Documentation

◆ GOptions

friend class GOptions
friend

Definition at line 285 of file goption.h.


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