cppfig 0.1.0
Modern C++20 compile-time type-safe configuration library
Loading...
Searching...
No Matches
cppfig::IConfigurationProvider< Derived, Schema > Class Template Reference

CRTP base class for configuration providers. More...

#include <interface.h>

Inheritance diagram for cppfig::IConfigurationProvider< Derived, Schema >:
[legend]

Public Types

using schema_type = Schema
 

Public Member Functions

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.
 

Protected Member Functions

 IConfigurationProvider ()=default
 
 ~IConfigurationProvider ()=default
 
 IConfigurationProvider (const IConfigurationProvider &)=default
 
 IConfigurationProvider (IConfigurationProvider &&)=default
 
auto operator= (const IConfigurationProvider &) -> IConfigurationProvider &=default
 
auto operator= (IConfigurationProvider &&) -> IConfigurationProvider &=default
 

Detailed Description

template<typename Derived, typename Schema>
class cppfig::IConfigurationProvider< Derived, Schema >

CRTP base class for configuration providers.

This class defines the interface that all configuration providers must implement. It uses CRTP to allow compile-time polymorphism while still being compatible with GMock for testing.

Template Parameters
DerivedThe derived configuration provider class.
SchemaThe ConfigSchema type.

Member Typedef Documentation

◆ schema_type

template<typename Derived , typename Schema >
using cppfig::IConfigurationProvider< Derived, Schema >::schema_type = Schema

Constructor & Destructor Documentation

◆ IConfigurationProvider() [1/3]

template<typename Derived , typename Schema >
cppfig::IConfigurationProvider< Derived, Schema >::IConfigurationProvider ( )
protecteddefault

◆ ~IConfigurationProvider()

template<typename Derived , typename Schema >
cppfig::IConfigurationProvider< Derived, Schema >::~IConfigurationProvider ( )
protecteddefault

◆ IConfigurationProvider() [2/3]

template<typename Derived , typename Schema >
cppfig::IConfigurationProvider< Derived, Schema >::IConfigurationProvider ( const IConfigurationProvider< Derived, Schema > &  )
protecteddefault

◆ IConfigurationProvider() [3/3]

template<typename Derived , typename Schema >
cppfig::IConfigurationProvider< Derived, Schema >::IConfigurationProvider ( IConfigurationProvider< Derived, Schema > &&  )
protecteddefault

Member Function Documentation

◆ Diff()

template<typename Derived , typename Schema >
auto cppfig::IConfigurationProvider< Derived, Schema >::Diff ( ) const -> ConfigDiff
inline

Returns the diff between file values and defaults.

◆ Get()

template<typename Derived , typename Schema >
template<IsSetting S>
requires (Schema::template has_setting<S>)
auto cppfig::IConfigurationProvider< Derived, Schema >::Get ( ) const -> typename S::value_type
inline

Gets the value for a setting type.

Resolution order:

  1. Environment variable (if configured)
  2. File value (if present)
  3. Default value

Usage: config.Get<MySettings::ServerPort>()

◆ GetFilePath()

template<typename Derived , typename Schema >
auto cppfig::IConfigurationProvider< Derived, Schema >::GetFilePath ( ) const -> std::string_view
inline

Returns the file path.

◆ Load()

template<typename Derived , typename Schema >
auto cppfig::IConfigurationProvider< Derived, Schema >::Load ( ) -> Status
inline

Loads configuration from the file.

If the file doesn't exist, it creates it with default values. If new settings were added to the schema, they are appended to the file.

◆ operator=() [1/2]

template<typename Derived , typename Schema >
auto cppfig::IConfigurationProvider< Derived, Schema >::operator= ( const IConfigurationProvider< Derived, Schema > &  ) -> IConfigurationProvider &=default
protecteddefault

◆ operator=() [2/2]

template<typename Derived , typename Schema >
auto cppfig::IConfigurationProvider< Derived, Schema >::operator= ( IConfigurationProvider< Derived, Schema > &&  ) -> IConfigurationProvider &=default
protecteddefault

◆ Save()

template<typename Derived , typename Schema >
auto cppfig::IConfigurationProvider< Derived, Schema >::Save ( ) const -> Status
inline

Saves the current configuration to the file.

◆ Set()

template<typename Derived , typename Schema >
template<IsSetting S>
requires (Schema::template has_setting<S>)
auto cppfig::IConfigurationProvider< Derived, Schema >::Set ( typename S::value_type  value) -> Status
inline

Sets the value for a setting type.

The value is validated before being set. Returns an error if validation fails.

Usage: config.Set<MySettings::ServerPort>(8080)

◆ ValidateAll()

template<typename Derived , typename Schema >
auto cppfig::IConfigurationProvider< Derived, Schema >::ValidateAll ( ) const -> Status
inline

Validates all current values against their validators.


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