|
cppfig 0.1.0
Modern C++20 compile-time type-safe configuration library
|
cppfig uses a pluggable serialization system. The flat .conf format is the default — zero extra dependencies. JSON, TOML, and other formats are available as opt-in features.
The built-in ConfSerializer uses a simple flat key-value format and requires no additional dependencies:
full.dot.path = value — what you see is exactly what you write in code.# are comments.true / false / yes / no / on / off → boolint64_tdoublestd::string"hello world") preserve literal content including spaces.Enable JSON support by adding the dependency and CMake option:
| Format | Header | CMake Option | vcpkg Feature | Status |
|---|---|---|---|---|
| Conf | <cppfig/cppfig.h> | *(always available)* | — | Built-in |
| JSON | <cppfig/json.h> | CPPFIG_ENABLE_JSON | json | Available |
| TOML | <cppfig/toml.h> | CPPFIG_ENABLE_TOML | toml | Planned |
| YAML | <cppfig/yaml.h> | CPPFIG_ENABLE_YAML | yaml | Planned |
To create a custom serializer, implement a struct that satisfies the Serializer concept:
A serializer must provide:
| Member | Signature | Purpose |
|---|---|---|
data_type | type alias (Value) | Internal data representation |
Parse | (std::istream&) → StatusOr<Value> | Parse from stream |
Stringify | (const Value&) → std::string | Convert to string |
Path navigation (GetAtPath, SetAtPath, HasPath) and merging are handled by cppfig::Value directly — serializers only need to convert between their file format and a Value tree.
cppfig provides helper functions for file operations:
Serializers work with ConfigTraits<T> for type conversion:
ConfigTraits<T> works with cppfig::Value (not any specific serializer format), so custom type traits are serializer-agnostic.