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.
Copyright
Types 1
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");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 _valueprivate 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.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 isNumber() const pure nothrow @nogc @safeReturns `true` if this node holds a number (integer or float).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.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.void opIndexAssign(CdmNode value, string key) pure @safeAssigns a value to the given key in this OBJECT.CdmMember * getMember(string key) pure nothrow @systemLooks up a member by key and returns a pointer to it.inout(CdmNode) * tryGet(string key) inout pure nothrow @safeSafe read-only lookup by key without auto-creation.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.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.void addAttribute(string name, CdmNode value, string ns = "",
CdmLocation loc = CdmLocation.init) pure @safeAdds an attribute to this TAG node.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.TypeNode type discriminator.