|
| | Config ()=default |
| | Default constructor. Initializes the inner content with default values.
|
| |
| const T * | operator-> () const |
| | Access member of the underlying configuration struct.
|
| |
| T * | write () const |
| | Get a mutable pointer to the configuration content.
|
| |
| T & | operator* () |
| | Dereference operator to access the underlying configuration struct.
|
| |
| const T & | operator* () const |
| | Dereference operator to access the underlying configuration struct.
|
| |
| const T & | main () const |
| | Explicit accessor for the main configuration content.
|
| |
| void | save (std::string_view path) const |
| | Saves the current configuration to a TOML file.
|
| |
| void | set_root_name (const std::string_view name) |
| | Sets the root name/key used in the TOML file.
|
| |
| std::string_view | get_root_name () const |
| | Gets the current root name.
|
| |
| void | set_root_name_load_policy (const RootNameLoadPolicy policy) |
| | Sets the policy for handling root name mismatches during load.
|
| |
| RootNameLoadPolicy | get_root_name_load_policy () const |
| | Gets the current root name load policy.
|
| |
| std::string | describe_root_name_load_policy () const |
| | Returns a string description of the current root name load policy.
|
| |
| void | load (const std::string_view path) |
| | Loads configuration from a TOML file.
|
| |
| ConfigState | get_state () const |
| | Gets the current state of the configuration object.
|
| |
| std::string | describe_state () const |
| | Returns a string description of the current configuration state.
|
| |
template<IsConfigSchema T>
class fourdst::config::Config< T >
Wrapper class for managing strongly-typed configuration structures.
The Config class wraps a user-defined aggregate struct T and provides methods to save/load it to/from TOML files, as well as generate JSON schemas.
It uses reflect-cpp to automatically inspect the fields of T.
- Template Parameters
-
- Examples
- Defining a config struct and using
Config:
struct MySettings {
int threads = 4;
double timeout = 30.5;
};
std::cout << "Threads: " << cfg->threads << "\n";
cfg.
save(
"settings.toml");
cfg.
load(
"settings.toml");
return 0;
}
Wrapper class for managing strongly-typed configuration structures.
Definition base.h:113
const T & main() const
Explicit accessor for the main configuration content.
Definition base.h:148
void save(std::string_view path) const
Saves the current configuration to a TOML file.
Definition base.h:164
void load(const std::string_view path)
Loads configuration from a TOML file.
Definition base.h:249
static void save_schema(const std::string &path)
Generates and saves a JSON schema for the configuration structure.
Definition base.h:300
Main entry point for the fourdst::config library.