Loading...
Searching...
No Matches
fourdst::config Namespace Reference

## Namespaces

namespace | exceptions
namespace | utils
namespace | validate

## Classes

class | Config
| Wrapper class for managing strongly-typed configuration structures. More...
struct | InspectType
struct | is_config_wrapper
| Type trait to determine if a type is a Config wrapper. More...
struct | is_config_wrapper< Config< T > >
| Specialization of `is_config_wrapper` for `Config<T>`. More...

## Concepts

concept | IsConfigSchema
| Concept ensuring a type is suitable for configuration schema.
concept | IsCLIApp
| Concept that defines the requirements for a CLI application class.

## Enumerations

enum class | RootNameLoadPolicy { FROM_FILE , KEEP_CURRENT }
| Policies for handling the root name during configuration loading. More...
enum class | ConfigState { DEFAULT , LOADED_FROM_FILE , MODIFIED }
| Represents the current state of a Config object. More...

## Functions

template<typename T, typename CliApp>
void | register_as_cli (T &config, CliApp &app, const std::string &prefix="")
| Registers configuration structure fields as CLI options.

## Enumeration Type Documentation

## ConfigState

enum class fourdst::config::ConfigState

strong

Represents the current state of a Config object.

Enumerator
DEFAULT | Configuration contains default values and has not been loaded from a file.
LOADED_FROM_FILE | Configuration has been successfully populated from a file.
MODIFIED |

## RootNameLoadPolicy

enum class fourdst::config::RootNameLoadPolicy

strong

Policies for handling the root name during configuration loading.

Enumerator
FROM_FILE | Updates the internal root name to match what is found in the file.
KEEP_CURRENT | Enforces the current internal root name; loading fails if the file's root name differs.

## Function Documentation

## register_as_cli()

template<typename T, typename CliApp>

void fourdst::config::register_as_cli | ( | T & | config,
|  | CliApp & | app,
|  | const std::string & | prefix = "" )

Registers configuration structure fields as CLI options.

This function iterates over the members of the provided configuration object using reflection and registers each member as a command-line option in the provided CLI application.

If the configuration object contains nested structures, field names are flattened using dot notation (e.g., `parent.child.field`).

If `T` is a `Config<U>` wrapper, it automatically unwraps the inner value and adds a footer note to the CLI application's help message indicating that options were auto-generated.

Template Parameters

  T | The type of the configuration object. Can be a raw struct or a `Config<Struct>` wrapper.
  CliApp | The type of the CLI application object. Must satisfy the `IsCLIApp` concept (e.g., `CLI::App`).

Parameters

  config | The configuration object to register.
  app | The CLI application instance to add options to.
  prefix | Optional prefix for option names. Used internally for recursion; usually omitted by the caller.

Examples
  Basic usage with CLI11:
  #include "CLI/CLI.hpp"
  #include "fourdst/config/config.h"
  struct MyOptions {
  int verbosity = 0;
  std::string input_file = "data.txt";
  };
  int main(int argc, char** argv) {
  fourdst::config::Config<MyOptions> cfg;
  CLI::App app{"My Application"};
  // Automatically adds flags: --verbosity, --input_file
  fourdst::config::register_as_cli(cfg, app);
  CLI11_PARSE(app, argc, argv);
  // cfg is now populated with values from CLI
  return 0;
  }
  fourdst::config::Config
  Wrapper class for managing strongly-typed configuration structures.
  Definition base.h:117
  config.h
  Main entry point for the fourdst::config library.
  fourdst::config::register_as_cli
  void register_as_cli(T &config, CliApp &app, const std::string &prefix="")
  Registers configuration structure fields as CLI options.
  Definition cli.h:114

Nested structures:

struct Server {
int port = 8080;
std::string host = "localhost";
};
struct AppConfig {
Server server;
bool dry_run = false;
};
// In main...
fourdst::config::Config<AppConfig> cfg;
// Registers: --server.port, --server.host, --dry_run
fourdst::config::register_as_cli(cfg, app);