Representer.representMapping

Represent a mapping with specified _tag, representing children first.

This is used by representer functions that produce mappings.

class Representer
@trusted
representMapping

Parameters

pairs Node.Pair[]

Key-value _pairs of the mapping.

style CollectionStyle

Style of the mapping. If invalid, default _style will be used. If the node was loaded before, previous _style will always be used.

Return Value

Type: Node

The represented node.

Throws

RepresenterException if a child could not be represented.

Examples

struct MyStruct
{
    int x, y, z;

    //Any D:YAML type must have a custom opCmp operator.
    //This is used for ordering in mappings.
    const int opCmp(ref const MyStruct s)
    {
        if(x != s.x){return x - s.x;}
        if(y != s.y){return y - s.y;}
        if(z != s.z){return z - s.z;}
        return 0;
    }        
}

Node representMyStruct(ref Node node, Representer representer)
{ 
    auto value = node.as!MyStruct;
    auto pairs = [Node.Pair("x", value.x), 
                  Node.Pair("y", value.y), 
                  Node.Pair("z", value.z)];
    return representer.representMapping("!mystruct.tag", pairs);
}

Meta