ddn.data.cdm.node

CDM node - the core data structure for the Configuration Data Model.

This module provides the CdmNode struct which represents a single node in a configuration document. CdmNode is a tagged union that can hold scalar values (bool, integer, float, string, binary, date, time, datetime, duration), containers (array, object, tag), and comments.

The key difference from the old DomNode is that CdmNode uses _members: CdmMember[] for object key-value pairs instead of parallel _keys: string[] + _children: DomNode[] arrays.

struct CdmNode

Types 1

structCdmNode

A tagged-union node for the Configuration Data Model.

CdmNode can represent any configuration value: scalars (bool, integer, float, string, binary, date/time types, duration), containers (array, object, tag), and comments. The type field determines which union field is active.

Objects use CdmMember[] internally, replacing the old parallel-array approach (_keys + _children) from DomNode. Each CdmMember stores a key, a heap-allocated value pointer, and roundtrip metadata.

Examples

auto n = CdmNode(42L);
assert(n.isInteger);
assert(n.as!long == 42);

auto obj = CdmNode.emptyObject();
obj["name"] = CdmNode("myapp");
assert(obj.hasKey("name"));
assert(obj["name"].as!string == "myapp");
Fields
Type typeThe discriminated type of this node.
CdmLocation locationSource location where this node originated.
CdmFormat formatFormatting metadata for roundtrip fidelity.
CdmComment[] leadingCommentsComments appearing before this node in source.
CdmComment[] trailingCommentsComments appearing after this node in source.
private ValueData _value
private CdmNode[] _childrenChild nodes for ARRAY and TAG types.
private CdmMember[] _membersKey-value members for OBJECT type (replaces old keys + children).
private string _tagNameTag name for TAG type.
private string _tagNamespaceTag namespace for TAG type.
private CdmAttribute[] _attributesAttributes for TAG type.
Methods
CdmNode makeNull(CdmLocation loc = CdmLocation.init) pure @safeCreates a NULL node.
CdmNode emptyArray(CdmLocation loc = CdmLocation.init) pure @safeCreates an empty ARRAY node.
CdmNode emptyObject(CdmLocation loc = CdmLocation.init) pure @safeCreates an empty OBJECT node.
CdmNode makeTag(string name, string ns = "", CdmLocation loc = CdmLocation.init) pure @safeCreates a TAG node with the given name and optional namespace.
CdmNode makeComment(string text, CdmComment.Style style, CdmLocation loc = CdmLocation.init) pure @safeCreates a COMMENT node with the given text and style.
CdmNode makeDuration(Duration value, CdmLocation loc = CdmLocation.init) pure @safeCreates a DURATION node from a Duration value.
bool isNull() const pure nothrow @nogc @safeReturns `true` if this node is null.
bool isBool() const pure nothrow @nogc @safeReturns `true` if this node holds a boolean.
bool isInteger() const pure nothrow @nogc @safeReturns `true` if this node holds an integer.
bool isFloat() const pure nothrow @nogc @safeReturns `true` if this node holds a float.
bool isNumber() const pure nothrow @nogc @safeReturns `true` if this node holds a number (integer or float).
bool isString() const pure nothrow @nogc @safeReturns `true` if this node holds a string.
bool isBinary() const pure nothrow @nogc @safeReturns `true` if this node holds binary data.
bool isDate() const pure nothrow @nogc @safeReturns `true` if this node holds a date.
bool isTime() const pure nothrow @nogc @safeReturns `true` if this node holds a time.
bool isDateTime() const pure nothrow @nogc @safeReturns `true` if this node holds a datetime.
bool isDuration() const pure nothrow @nogc @safeReturns `true` if this node holds a duration.
bool isArray() const pure nothrow @nogc @safeReturns `true` if this node is an array.
bool isObject() const pure nothrow @nogc @safeReturns `true` if this node is an object.
bool isTag() const pure nothrow @nogc @safeReturns `true` if this node is a tag.
bool isComment() const pure nothrow @nogc @safeReturns `true` if this node is a comment.
bool isValue() const pure nothrow @nogc @safeReturns `true` if this node holds a scalar value.
bool isContainer() const pure nothrow @nogc @safeReturns `true` if this node is a container (ARRAY, OBJECT, or TAG).
bool isObjectLike() const pure nothrow @nogc @safeReturns `true` if this node is object-like (OBJECT or TAG).
bool opEquals(const CdmNode other) const pure nothrow @trustedCompares two CdmNode values for structural equality.
size_t toHash() const pure nothrow @trustedComputes a hash value for this CdmNode.
T as(T)() const @safeRetrieves the scalar value of this node as the requested type.
inout(CdmNode)[] children() inout pure nothrow @nogc @safeReturns the child nodes for ARRAY and TAG types.
inout(CdmMember)[] members() inout pure nothrow @nogc @safeReturns the key-value members for OBJECT type.
string[] keys() const @safeComputes the keys of this OBJECT node's members.
size_t length() const pure nothrow @nogc @safeReturns the length of this node's content.
bool empty() const pure nothrow @nogc @safeReturns `true` if this node has no content.
inout(CdmNode)[] tagValues() inout pure nothrow @nogc @safeReturns the child values for TAG type.
CdmNode opIndex(string key) ref pure @safeLooks up or creates a member by key.
void opIndexAssign(CdmNode value, string key) pure @safeAssigns a value to the given key in this OBJECT.
void addMember(CdmMember member) pure @safeAdds a pre-built CdmMember to this OBJECT.
CdmMember * getMember(string key) pure nothrow @systemLooks up a member by key and returns a pointer to it.
bool hasKey(string key) const pure nothrow @safeChecks whether this OBJECT contains the given key.
inout(CdmNode) * tryGet(string key) inout pure nothrow @safeSafe read-only lookup by key without auto-creation.
T getOrDefault(T)(string key, T defaultValue) const @safeSafe read-only lookup with default value.
bool removeMember(string key) pure nothrow @safeRemoves a member by key from this OBJECT.
void setMembers(CdmMember[] newMembers) pure @safeSets the members of this OBJECT, replacing all existing members.
CdmNode opOpAssign(string op : "~")(CdmNode child) ref pure @safeAppends a child node to this ARRAY or TAG.
inout(CdmNode) opIndex(size_t index) ref inout pure @safeIndexes into this ARRAY or TAG's children by position.
void addValue(CdmNode value) pure @safeAppends a value node to this TAG's children.
string nodeName() const pure nothrow @nogc @safeReturns the tag name if this is a TAG node.
string nodeNamespace() const pure nothrow @nogc @safeReturns the tag namespace if this is a TAG node.
inout(CdmAttribute)[] attributes() inout pure nothrow @nogc @safeReturns the attributes of this TAG node.
CdmAttribute * getAttribute(string name) pure nothrow @systemLooks up a TAG attribute by name.
void addAttribute(string name, CdmNode value, string ns = "", CdmLocation loc = CdmLocation.init) pure @safeAdds an attribute to this TAG node.
CdmNode dup() const pure @safeCreates a deep copy of this node.
private CdmNode _dupImpl() const pure @trustedInternal recursive deep-copy implementation.
string toString() const @trustedReturns a debug string representation of this node.
Constructors
this(CdmLocation loc)Constructs a NULL node with the given location.
this(bool value, CdmLocation loc = CdmLocation.init)Constructs a BOOL node.
this(long value, CdmLocation loc = CdmLocation.init)Constructs an INTEGER node.
this(double value, CdmLocation loc = CdmLocation.init)Constructs a FLOAT node.
this(string value, CdmLocation loc = CdmLocation.init)Constructs a STRING node.
this(immutable(ubyte)[] value, CdmLocation loc = CdmLocation.init)Constructs a BINARY node.
this(Date value, CdmLocation loc = CdmLocation.init)Constructs a DATE node.
this(TimeOfDay value, CdmLocation loc = CdmLocation.init)Constructs a TIME node.
this(DateTime value, CdmLocation loc = CdmLocation.init)Constructs a DATETIME node.
this(Duration value, CdmLocation loc = CdmLocation.init)Constructs a DURATION node.
Nested Templates
TypeNode type discriminator.