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
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) static @safeLoad configuration from a file.
ConfigStore loadString(string content, CdmDocument.Format fmt, string sourcePath = "<string>") static @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) nothrow @safeMark a key path as deleted and remove it from the runtime data.
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.

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

Constructors
this(string msg, string file = __FILE__, size_t line = __LINE__)Construct the exception.