ddn.data.cdm.store

CDM ConfigStore — Lightweight config with format-preserving save.

This module provides a utility for applications that need:

  • Low memory usage during runtime (uses var)
  • Format preservation when saving (comments, indentation, etc.)

The pattern:

  1. Load: Parse file → convert to var → discard CDM
  2. Runtime: Use lightweight var for reads/writes
  3. Save: Re-parse file → merge changes → write back

Example:

auto config = ConfigStore.load("app.cf");

// Read values
string host = config["server"]["host"].as!string;

// Modify values
config["server"]["port"] = 9090;

// Save with formatting preserved
config.save();

Types 2

Lightweight configuration store with format-preserving save.

Holds configuration data as var during runtime for low memory usage, and merges changes back into the original file format on save, preserving comments, indentation, quote styles, and other formatting.

Fields
var dataThe configuration data (lightweight runtime representation)
string pathPath to the configuration file
CdmDocument.Format formatDetected or specified file format
private string[] _deletedPathsKeys that have been explicitly deleted (dot-separated paths)
string delegate(string path) @safe fileReaderCustom file reader (for testing or virtual filesystems)
void delegate(string path, string content) @safe fileWriterCustom file writer (for testing or virtual filesystems)
CdmDocument delegate(string content, string path) @safe parserCustom parser (for format detection override)
string delegate(CdmDocument doc) @safe writerCustom writer (for format detection override)
Methods
ConfigStore load(string filePath, CdmDocument.Format fmt = CdmDocument.Format.UNKNOWN) @safeLoad configuration from a file.
ConfigStore loadString(string content, CdmDocument.Format fmt, string sourcePath = "<string>") @safeLoad configuration from a string.
void save() @safeSave configuration back to the original file.
void saveAs(string filePath) @safeSave configuration to a different file.
void deleteKey(string keyPath) pure nothrow @safeMark a key path as deleted.
void undeleteKey(string keyPath) pure @safeClear a deletion marker.
var opIndex(string key) ref return @safeAccess configuration data by key.
bool hasKey(string key) const @safeCheck if a key exists in the configuration.
T get(T)(string key, T defaultValue = T.init) const @safeGet a value with a default fallback.
private CdmDocument parseContent(string content, string sourcePath) const @safe
private string writeContent(CdmDocument doc) const @safe
private CdmDocument.Format detectFormat(string filePath) @safe

Exception thrown when a CDM format parser/writer is not yet implemented.

Constructors
this(string msg, string file = __FILE__, size_t line = __LINE__)

Functions 13

private fnvoid mergeIntoCdm(ref CdmNode node, var data) @trustedRecursively merge var data into a CDM node.
private fnvoid addNewMember(ref CdmNode node, string key, var value) @safeAdd a new member with contextually-appropriate formatting.
private fnvoid updateMemberValue(CdmMember * member, var value) @safeUpdate an existing member's value while preserving its formatting.
private fnCdmNode varToCdmNode(var v) @trustedConvert a var to a CdmNode.
private fnvoid deleteFromCdm(ref CdmNode node, string keyPath) @trustedDelete a key path from a CDM node.
private fnbool removeMember(ref CdmNode node, string key) @safeRemove a member by key from an object node.
private fnbool needsQuoting(string key) pure nothrow @safeCheck if a key needs quoting.
private fnCdmDocument parseCf(string content, string path) @safeParse CF format content into a CdmDocument.
private fnCdmDocument parseJson5(string content, string path) @safeParse JSON5 format content into a CdmDocument.
private fnCdmDocument parseSdl(string content, string path) @safeParse SDL format content into a CdmDocument.
private fnstring toCf(CdmDocument doc) @safeWrite a CdmDocument to CF format.
private fnstring toJson5(CdmDocument doc) @safeWrite a CdmDocument to JSON5 format.
private fnstring toSdl(CdmDocument doc) @safeWrite a CdmDocument to SDL format.