dyaml.node

Node of a YAML document. Used to read YAML data once it's loaded.

class NodeException: dyaml.exception.YAMLException;

Exception thrown at node related errors.

struct YAMLNull;

Null YAML type. Used in nodes with null values.

struct Node;

YAML node.

This is a pseudo-dynamic type that can store any YAML value, including sequence or a mapping of nodes. You can get data from a Node directly or iterate over it if it's a sequence or a mapping.

struct Pair;

Pair of YAML nodes, used in mappings.

Node key;

Key node.

Node value;

Value node.

bool equals(ref Pair rhs);

Test for equality with another Pair.

const @property bool isValid();

Is this node valid (initialized)?

const @property bool isScalar();

Is this node a scalar value?

const @property bool isSequence();

Is this node a sequence of nodes?

const @property bool isMapping();

Is this node a mapping of nodes?

const @property bool isUserType();

Is this node a user defined type?

bool opEquals(T)(ref T rhs);

Equality test.

If T is Node, recursively compare all subnodes and might be quite expensive if testing entire documents.
If T is not Node, convert the node to T and test equality with that.

Examples:
 //node is a Node that contains integer 42
 assert(node == 42);
 assert(node == "42");
 assert(node != "43");
Parameters:
rhs Variable to test equality with.
Returns:
true if equal, false otherwise.
T get(T)();

Get the value of the node as specified type.

If the specifed type does not match type in the node, conversion is attempted if possible.
Timestamps are stored as std.datetime.SysTime. Binary values are decoded and stored as ubyte[].

Mapping default values:

The '=' key can be used to denote the default value of a mapping. This can be used when a node is scalar in early versions of a program, but is replaced by a mapping later. Even if the node is a mapping, the get method can be used as if it was a scalar if it has a default value. This way, new YAML files where the node is a mapping can still be read by old versions of the program, which expects the node to be a scalar.

Examples:
Automatic type conversion:
 //node is a node that contains integer 42
 assert(node.get!int == 42);
 assert(node.get!string == "42");
 assert(node.get!double == 42.0);
Returns:
Value of the node as specified type.
Throws:
NodeException if unable to convert to specified type.
void getToVar(T)(out T target);

Write the value of the node to target.

If the type of target does not match type of the node, conversion is attempted, if possible.

Parameters:
target Variable to write to.
Throws:
NodeException if unable to convert to specified type.
@property size_t length();

If this is a sequence or a mapping, return its length.

Otherwise, throw NodeException.

Returns:
Number of elements in a sequence or key-value pairs in a mapping.
Throws:
NodeException if this is not a sequence nor a mapping.
Node opIndex(T)(in T index);

Get the element with specified index.

If the node is a sequence, index must be integral.
If the node is a mapping, return the value corresponding to the first key equal to index, even after conversion. I.e; node["12"] will return value of the first key that equals "12", even if it's an integer.

Parameters:
index Index to use.
Returns:
Value corresponding to the index.
Throws:
NodeException if the index could not be found.
int opApply(T)(int delegate(ref T) dg);

Iterate over a sequence, getting each element as T.

If T is Node, simply iterate over the nodes in the sequence. Otherwise, convert each node to T during iteration.

Throws:
NodeException if the node is not a sequence or an element could not be converted to specified type.
int opApply(K, V)(int delegate(ref K, ref V) dg);

Iterate over a mapping, getting each key/value as K/V.

If the K and/or V is Node, simply iterate over the nodes in the mapping. Otherwise, convert each key/value to T during iteration.

Throws:
NodeException if the node is not a mapping or an element could not be converted to specified type.
alias isInt;

Is the value an integer of some kind?

alias isFloat;

Is the value a floating point number of some kind?