libconfig v2.1.0
Reflection based C++ configuration library
Loading...
Searching...
No Matches
fourdst::config Namespace Reference

Namespaces

namespace  exceptions
 

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 }
 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.

◆ RootNameLoadPolicy

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
TThe type of the configuration object. Can be a raw struct or a Config<Struct> wrapper.
CliAppThe type of the CLI application object. Must satisfy the IsCLIApp concept (e.g., CLI::App).
Parameters
configThe configuration object to register.
appThe CLI application instance to add options to.
prefixOptional prefix for option names. Used internally for recursion; usually omitted by the caller.
Examples
Basic usage with CLI11:
#include "CLI/CLI.hpp"
struct MyOptions {
int verbosity = 0;
std::string input_file = "data.txt";
};
int main(int argc, char** argv) {
CLI::App app{"My Application"};
// Automatically adds flags: --verbosity, --input_file
CLI11_PARSE(app, argc, argv);
// cfg is now populated with values from CLI
return 0;
}
Wrapper class for managing strongly-typed configuration structures.
Definition base.h:113
Main entry point for the fourdst::config library.
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...
// Registers: --server.port, --server.host, --dry_run