cppfig 0.1.0
Modern C++20 compile-time type-safe configuration library
Loading...
Searching...
No Matches
cppfig::ConfSerializer Struct Reference

Flat key-value .conf serializer — the default, zero-dependency serializer. More...

#include <conf.h>

Public Types

using data_type = Value
 

Static Public Member Functions

static auto Parse (std::istream &is) -> StatusOr< Value >
 Parses a .conf stream into a Value tree.
 
static auto ParseString (std::string_view str) -> StatusOr< Value >
 Parses a .conf string into a Value tree.
 
static auto Stringify (const Value &data) -> std::string
 Converts a Value tree to flat key = value lines.
 
static auto Merge (std::string_view existing, const Value &data) -> std::string
 Rewrites an existing .conf document, preserving its layout.
 

Detailed Description

Flat key-value .conf serializer — the default, zero-dependency serializer.

File format:

# Comment lines start with #
server.host = localhost
server.port = 8080
logging.enabled = true
logging.level = info

Keys are the full dot-separated setting paths. There are no sections or grouping — each line is simply path = value.

Type inference during parsing:

  • true/false/yes/no/on/off → bool
  • All-digit strings (optional leading -) → int64
  • Numeric with decimal point or exponent → double
  • Quoted strings ("...") → string (quotes stripped)
  • Everything else → string

Member Typedef Documentation

◆ data_type

Member Function Documentation

◆ Merge()

static auto cppfig::ConfSerializer::Merge ( std::string_view  existing,
const Value &  data 
) -> std::string
inlinestatic

Rewrites an existing .conf document, preserving its layout.

Regenerating the file from the Value tree sorts the keys and drops every comment the user wrote, which is user-hostile for a format whose whole point is being hand-editable. Merge instead walks the existing lines, updates the value of each key it recognises, leaves comments, blank lines and ordering alone, and appends the keys the file does not have yet.

Lines whose value is unchanged are emitted verbatim, so a save that changes nothing leaves the file byte-identical.

Parameters
existingThe current file contents.
dataThe Value tree to write.

◆ Parse()

static auto cppfig::ConfSerializer::Parse ( std::istream &  is) -> StatusOr<Value>
inlinestatic

Parses a .conf stream into a Value tree.

◆ ParseString()

static auto cppfig::ConfSerializer::ParseString ( std::string_view  str) -> StatusOr<Value>
inlinestatic

Parses a .conf string into a Value tree.

◆ Stringify()

static auto cppfig::ConfSerializer::Stringify ( const Value &  data) -> std::string
inlinestatic

Converts a Value tree to flat key = value lines.


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