|
cppfig 0.1.0
Modern C++20 compile-time type-safe configuration library
|
Main configuration manager. More...
#include <configuration.h>
Public Types | |
| using | serializer_type = SerializerT |
| using | data_type = Value |
Public Types inherited from cppfig::IConfigurationProvider< Derived, Schema > | |
| using | schema_type = Schema |
Public Member Functions | |
| Configuration (std::string file_path) | |
| Creates a configuration manager with a file path. | |
| template<IsSetting S> requires (Schema::template has_setting<S>) | |
| auto | GetImpl () const -> typename S::value_type |
| Gets the value for a setting type. | |
| template<IsSetting S> requires (Schema::template has_setting<S>) | |
| auto | SetImpl (typename S::value_type value) -> Status |
| Sets the value for a setting type. | |
| auto | LoadImpl () -> Status |
| Loads configuration from the file. | |
| auto | SaveImpl () const -> Status |
| Saves the current configuration to the file. | |
| auto | DiffImpl () const -> ConfigDiff |
| Returns the diff between file values and defaults. | |
| auto | ValidateAllImpl () const -> Status |
| Validates all current values against their validators. | |
| auto | GetFilePathImpl () const -> std::string_view |
| Returns the file path. | |
| auto | GetFileValues () const -> const Value & |
| Returns the current file values. | |
| auto | GetDefaults () const -> const Value & |
| Returns the default values. | |
| auto | Load () -> Status override |
| Loads configuration from the file. | |
| auto | Save () const -> Status override |
| Saves the current configuration to the file. | |
| auto | GetFilePath () const -> std::string_view override |
| Returns the file path. | |
| auto | ValidateAll () const -> Status override |
| Validates all current values. | |
| auto | GetDiffString () const -> std::string override |
| Gets a string representation of the diff. | |
Public Member Functions inherited from cppfig::IConfigurationProvider< Derived, Schema > | |
| template<IsSetting S> requires (Schema::template has_setting<S>) | |
| auto | Get () const -> typename S::value_type |
| Gets the value for a setting type. | |
| template<IsSetting S> requires (Schema::template has_setting<S>) | |
| auto | Set (typename S::value_type value) -> Status |
| Sets the value for a setting type. | |
| auto | Load () -> Status |
| Loads configuration from the file. | |
| auto | Save () const -> Status |
| Saves the current configuration to the file. | |
| auto | Diff () const -> ConfigDiff |
| Returns the diff between file values and defaults. | |
| auto | ValidateAll () const -> Status |
| Validates all current values against their validators. | |
| auto | GetFilePath () const -> std::string_view |
| Returns the file path. | |
Public Member Functions inherited from cppfig::IConfigurationProviderVirtual | |
| virtual | ~IConfigurationProviderVirtual ()=default |
Additional Inherited Members | |
Protected Member Functions inherited from cppfig::IConfigurationProvider< Derived, Schema > | |
| IConfigurationProvider ()=default | |
| ~IConfigurationProvider ()=default | |
| IConfigurationProvider (const IConfigurationProvider &)=default | |
| IConfigurationProvider (IConfigurationProvider &&)=default | |
| auto | operator= (const IConfigurationProvider &) -> IConfigurationProvider &=default |
| auto | operator= (IConfigurationProvider &&) -> IConfigurationProvider &=default |
Protected Member Functions inherited from cppfig::IConfigurationProviderVirtual | |
| IConfigurationProviderVirtual ()=default | |
| IConfigurationProviderVirtual (const IConfigurationProviderVirtual &)=default | |
| IConfigurationProviderVirtual (IConfigurationProviderVirtual &&)=default | |
| auto | operator= (const IConfigurationProviderVirtual &) -> IConfigurationProviderVirtual &=default |
| auto | operator= (IConfigurationProviderVirtual &&) -> IConfigurationProviderVirtual &=default |
Main configuration manager.
This class manages configuration values with:
Thread Safety: By default, the class uses SingleThreadedPolicy (zero overhead). For concurrent access from multiple threads, specify MultiThreadedPolicy:
With MultiThreadedPolicy:
Get concurrently (shared/reader lock).Set, Load mutate internal state under an exclusive/writer lock.Save, Diff, ValidateAll acquire a shared/reader lock.Set is performed before acquiring the exclusive lock.Usage:
| Schema | The ConfigSchema type defining all settings. |
| SerializerT | The serializer to use (defaults to ConfSerializer). |
| ThreadPolicy | The threading policy (defaults to SingleThreadedPolicy). |
| using cppfig::Configuration< Schema, SerializerT, ThreadPolicy >::data_type = Value |
| using cppfig::Configuration< Schema, SerializerT, ThreadPolicy >::serializer_type = SerializerT |
|
inlineexplicit |
Creates a configuration manager with a file path.
| file_path | Path to the configuration file. |
|
inline |
Returns the diff between file values and defaults.
Thread safety: acquires a shared (reader) lock.
|
inline |
Returns the default values.
Thread safety: defaults_ is immutable after construction — safe to call concurrently without synchronization.
|
inlineoverridevirtual |
Gets a string representation of the diff.
Implements cppfig::IConfigurationProviderVirtual.
|
inlineoverridevirtual |
Returns the file path.
Implements cppfig::IConfigurationProviderVirtual.
|
inline |
Returns the file path.
Thread safety: file_path_ is immutable after construction — no lock needed.
|
inline |
Returns the current file values.
Get<Setting>() for safe access.
|
inline |
Gets the value for a setting type.
Resolution order:
Thread safety: acquires a shared (reader) lock when reading file values.
|
inlineoverridevirtual |
Loads configuration from the file.
Implements cppfig::IConfigurationProviderVirtual.
|
inline |
Loads configuration from the file.
Thread safety: acquires an exclusive (writer) lock for the entire operation because it mutates file_values_.
|
inlineoverridevirtual |
Saves the current configuration to the file.
Implements cppfig::IConfigurationProviderVirtual.
|
inline |
Saves the current configuration to the file.
Thread safety: acquires a shared (reader) lock because it only reads file_values_ (file I/O is serialized by the OS for the same path).
|
inline |
Sets the value for a setting type.
Thread safety: validation runs without holding any lock; the actual mutation of internal state acquires an exclusive (writer) lock.
|
inlineoverridevirtual |
Validates all current values.
Implements cppfig::IConfigurationProviderVirtual.
|
inline |
Validates all current values against their validators.
Thread safety: acquires a shared (reader) lock.