Red-Black Trees are now used for duplicate detection, and planned
to be used for unordered map storage. This is because AAs still don't work correctly and even if they did, require the user to define both toHash and opCmp/opEquals for every YAML struct/class. Now only opCmp needs to be defined. Documentation/tutorials/examples have been updated accordingly.
This commit is contained in:
parent
07eadc9403
commit
9596806644
34 changed files with 623 additions and 250 deletions
|
@ -190,7 +190,7 @@ div#content
|
|||
border: 0.6em solid #cccccc;
|
||||
background-color: #f6f6f6;
|
||||
font-size: 0.875em;
|
||||
line-height: 1.4em;
|
||||
line-height: 1.3em;
|
||||
}
|
||||
|
||||
div#content li{padding-bottom: .7ex;}
|
||||
|
|
|
@ -72,6 +72,8 @@
|
|||
<p>Each YAML scalar, sequence or mapping has a tag specifying its data type.
|
||||
<a name="Constructor"></a><span class="ddoc_psymbol">Constructor</span> uses user-specifyable functions to create a node of desired
|
||||
data type from a scalar, sequence or mapping.
|
||||
<br>
|
||||
|
||||
<br>
|
||||
|
||||
Each of these functions is associated with a tag, and can process either
|
||||
|
@ -82,7 +84,7 @@
|
|||
|
||||
If a tag is detected with no known constructor function, it is considered an error.</p>
|
||||
|
||||
<dl><dt class="d_decl">this(in const(bool) <b>defaultConstructors</b> = true);
|
||||
<dl><dt class="d_decl">this(const(bool) <b>defaultConstructors</b> = true);
|
||||
</dt>
|
||||
<dd><p>Construct a Constructor.
|
||||
</p>
|
||||
|
@ -107,12 +109,24 @@
|
|||
Any exception thrown by this function will be caught by D:YAML and
|
||||
its message will be added to a YAMLException that will also tell the
|
||||
user which type failed to construct, and position in the file.
|
||||
<br>
|
||||
|
||||
<br>
|
||||
|
||||
The value returned by this function will be stored in the resulting node.
|
||||
<br>
|
||||
|
||||
Only one constructor function can be set for one tag.
|
||||
<br>
|
||||
|
||||
<br>
|
||||
|
||||
Structs and classes must implement the <span class="d_inlinecode">opCmp()</span> operator for D:YAML
|
||||
support. The signature of the operator that must be implemented
|
||||
is <span class="d_inlinecode">const int opCmp(ref const MyStruct s)</span> for structs where
|
||||
<i>MyStruct</i> is the struct type, and <span class="d_inlinecode">int opCmp(Object o)</span> for
|
||||
classes. Note that the class <span class="d_inlinecode">opCmp()</span> should not alter the compared
|
||||
values - it is not const for compatibility reasons.
|
||||
|
||||
</p>
|
||||
<b>Parameters:</b><div class="pbr"><table class=parms><tr><td valign=top>tag</td>
|
||||
|
@ -128,6 +142,16 @@
|
|||
<span class="d_keyword">struct</span> MyStruct
|
||||
{
|
||||
<span class="d_keyword">int</span> x, y, z;
|
||||
|
||||
<span class="d_comment">//Any D:YAML type must have a custom opCmp operator.
|
||||
</span> <span class="d_comment">//This is used for ordering in mappings.
|
||||
</span> <span class="d_keyword">const</span> <span class="d_keyword">int</span> opCmp(<span class="d_keyword">ref</span> <span class="d_keyword">const</span> MyStruct s)
|
||||
{
|
||||
<span class="d_keyword">if</span>(x != s.x){<span class="d_keyword">return</span> x - s.x;}
|
||||
<span class="d_keyword">if</span>(y != s.y){<span class="d_keyword">return</span> y - s.y;}
|
||||
<span class="d_keyword">if</span>(z != s.z){<span class="d_keyword">return</span> z - s.z;}
|
||||
<span class="d_keyword">return</span> 0;
|
||||
}
|
||||
}
|
||||
|
||||
MyStruct constructMyStructScalar(<span class="d_keyword">ref</span> Node node)
|
||||
|
@ -166,6 +190,16 @@
|
|||
<span class="d_keyword">struct</span> MyStruct
|
||||
{
|
||||
<span class="d_keyword">int</span> x, y, z;
|
||||
|
||||
<span class="d_comment">//Any D:YAML type must have a custom opCmp operator.
|
||||
</span> <span class="d_comment">//This is used for ordering in mappings.
|
||||
</span> <span class="d_keyword">const</span> <span class="d_keyword">int</span> opCmp(<span class="d_keyword">ref</span> <span class="d_keyword">const</span> MyStruct s)
|
||||
{
|
||||
<span class="d_keyword">if</span>(x != s.x){<span class="d_keyword">return</span> x - s.x;}
|
||||
<span class="d_keyword">if</span>(y != s.y){<span class="d_keyword">return</span> y - s.y;}
|
||||
<span class="d_keyword">if</span>(z != s.z){<span class="d_keyword">return</span> z - s.z;}
|
||||
<span class="d_keyword">return</span> 0;
|
||||
}
|
||||
}
|
||||
|
||||
MyStruct constructMyStructSequence(<span class="d_keyword">ref</span> Node node)
|
||||
|
@ -202,6 +236,16 @@
|
|||
<span class="d_keyword">struct</span> MyStruct
|
||||
{
|
||||
<span class="d_keyword">int</span> x, y, z;
|
||||
|
||||
<span class="d_comment">//Any D:YAML type must have a custom opCmp operator.
|
||||
</span> <span class="d_comment">//This is used for ordering in mappings.
|
||||
</span> <span class="d_keyword">const</span> <span class="d_keyword">int</span> opCmp(<span class="d_keyword">ref</span> <span class="d_keyword">const</span> MyStruct s)
|
||||
{
|
||||
<span class="d_keyword">if</span>(x != s.x){<span class="d_keyword">return</span> x - s.x;}
|
||||
<span class="d_keyword">if</span>(y != s.y){<span class="d_keyword">return</span> y - s.y;}
|
||||
<span class="d_keyword">if</span>(z != s.z){<span class="d_keyword">return</span> z - s.z;}
|
||||
<span class="d_keyword">return</span> 0;
|
||||
}
|
||||
}
|
||||
|
||||
MyStruct constructMyStructMapping(<span class="d_keyword">ref</span> Node node)
|
||||
|
@ -227,42 +271,42 @@
|
|||
</dd>
|
||||
<dt class="d_decl">YAMLNull <a name="constructNull"></a><span class="ddoc_psymbol">constructNull</span>(ref Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Construct a <b>null</b> <b>node</b>.</p>
|
||||
<dd><p>Construct a null node.</p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">YAMLMerge <a name="constructMerge"></a><span class="ddoc_psymbol">constructMerge</span>(ref Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Construct a merge <b>node</b> - a <b>node</b> that merges another <b>node</b> into a mapping.</p>
|
||||
<dd><p>Construct a merge node - a node that merges another node into a mapping.</p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">bool <a name="constructBool"></a><span class="ddoc_psymbol">constructBool</span>(ref Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Construct a boolean <b>node</b>.</p>
|
||||
<dd><p>Construct a boolean node.</p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">long <a name="constructLong"></a><span class="ddoc_psymbol">constructLong</span>(ref Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Construct an integer (long) <b>node</b>.</p>
|
||||
<dd><p>Construct an integer (long) node.</p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">real <a name="constructReal"></a><span class="ddoc_psymbol">constructReal</span>(ref Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Construct a floating point (real) <b>node</b>.</p>
|
||||
<dd><p>Construct a floating point (real) node.</p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">ubyte[] <a name="constructBinary"></a><span class="ddoc_psymbol">constructBinary</span>(ref Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Construct a binary (base64) <b>node</b>.</p>
|
||||
<dd><p>Construct a binary (base64) node.</p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">SysTime <a name="constructTimestamp"></a><span class="ddoc_psymbol">constructTimestamp</span>(ref Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Construct a timestamp (SysTime) <b>node</b>.</p>
|
||||
<dd><p>Construct a timestamp (SysTime) node.</p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">string <a name="constructString"></a><span class="ddoc_psymbol">constructString</span>(ref Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Construct a string <b>node</b>.</p>
|
||||
<dd><p>Construct a string node.</p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">Pair[] <a name="getPairs"></a><span class="ddoc_psymbol">getPairs</span>(string <b>type</b>, Node[] <b>nodes</b>);
|
||||
|
@ -272,27 +316,27 @@
|
|||
</dd>
|
||||
<dt class="d_decl">Pair[] <a name="constructOrderedMap"></a><span class="ddoc_psymbol">constructOrderedMap</span>(ref Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Construct an ordered map (ordered sequence of key:value pairs without duplicates) <b>node</b>.</p>
|
||||
<dd><p>Construct an ordered map (ordered sequence of key:value pairs without duplicates) node.</p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">Pair[] <a name="constructPairs"></a><span class="ddoc_psymbol">constructPairs</span>(ref Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Construct a pairs (ordered sequence of key: value pairs allowing duplicates) <b>node</b>.</p>
|
||||
<dd><p>Construct a pairs (ordered sequence of key: value pairs allowing duplicates) node.</p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">Node[] <a name="constructSet"></a><span class="ddoc_psymbol">constructSet</span>(ref Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Construct a set <b>node</b>.</p>
|
||||
<dd><p>Construct a set node.</p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">Node[] <a name="constructSequence"></a><span class="ddoc_psymbol">constructSequence</span>(ref Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Construct a sequence (array) <b>node</b>.</p>
|
||||
<dd><p>Construct a sequence (array) node.</p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">Pair[] <a name="constructMap"></a><span class="ddoc_psymbol">constructMap</span>(ref Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Construct an unordered map (unordered set of key: value pairs without duplicates) <b>node</b>.</p>
|
||||
<dd><p>Construct an unordered map (unordered set of key:value pairs without duplicates) node.</p>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
@ -301,7 +345,7 @@
|
|||
|
||||
<div id="copyright">
|
||||
Copyright © Ferdinand Majerech 2011. Based on <a href="http://www.pyyaml.org">PyYAML</a> by Kirill Simonov. |
|
||||
Page generated by Autodoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
Page generated by AutoDDoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -224,7 +224,7 @@
|
|||
|
||||
<div id="copyright">
|
||||
Copyright © Ferdinand Majerech 2011. Based on <a href="http://www.pyyaml.org">PyYAML</a> by Kirill Simonov. |
|
||||
Page generated by Autodoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
Page generated by AutoDDoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
|
||||
<div id="copyright">
|
||||
Copyright © Ferdinand Majerech 2011. Based on <a href="http://www.pyyaml.org">PyYAML</a> by Kirill Simonov. |
|
||||
Page generated by Autodoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
Page generated by AutoDDoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
</dt>
|
||||
<dd><p>Position in a YAML stream, used for error messages.</p>
|
||||
|
||||
<dl><dt class="d_decl">this(in const(uint) <b>line</b>, in const(uint) <b>column</b>);
|
||||
<dl><dt class="d_decl">this(const(uint) <b>line</b>, const(uint) <b>column</b>);
|
||||
</dt>
|
||||
<dd><p>Construct a Mark with specified <b>line</b> and <b>column</b> in the file.</p>
|
||||
|
||||
|
@ -75,7 +75,7 @@
|
|||
|
||||
<div id="copyright">
|
||||
Copyright © Ferdinand Majerech 2011. Based on <a href="http://www.pyyaml.org">PyYAML</a> by Kirill Simonov. |
|
||||
Page generated by Autodoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
Page generated by AutoDDoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
|
||||
<div id="copyright">
|
||||
Copyright © Ferdinand Majerech 2011. Based on <a href="http://www.pyyaml.org">PyYAML</a> by Kirill Simonov. |
|
||||
Page generated by Autodoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
Page generated by AutoDDoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -190,7 +190,7 @@
|
|||
|
||||
<div id="copyright">
|
||||
Copyright © Ferdinand Majerech 2011. Based on <a href="http://www.pyyaml.org">PyYAML</a> by Kirill Simonov. |
|
||||
Page generated by Autodoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
Page generated by AutoDDoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -400,7 +400,7 @@
|
|||
</dd>
|
||||
<dt class="d_decl">int <a name="opApply"></a><span class="ddoc_psymbol">opApply</span>(T)(int delegate(ref T) <b>dg</b>);
|
||||
</dt>
|
||||
<dd><p>Iterate over a sequence, getting each element as T.
|
||||
<dd><p>Foreach over a sequence, getting each element as T.
|
||||
</p>
|
||||
<p>If T is Node, simply iterate over the nodes in the sequence.
|
||||
Otherwise, convert each node to T during iteration.
|
||||
|
@ -412,7 +412,7 @@
|
|||
</dd>
|
||||
<dt class="d_decl">int <a name="opApply"></a><span class="ddoc_psymbol">opApply</span>(K, V)(int delegate(ref K, ref V) <b>dg</b>);
|
||||
</dt>
|
||||
<dd><p>Iterate over a mapping, getting each key/value as K/V.
|
||||
<dd><p>Foreach over a mapping, getting each key/value as K/V.
|
||||
</p>
|
||||
<p>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.
|
||||
|
@ -512,6 +512,11 @@
|
|||
<b>Throws:</b><div class="pbr">NodeException if the node is not a collection, index is out
|
||||
of range or if a non-integral index is used on a sequence node.</div>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">const const int <a name="opCmp"></a><span class="ddoc_psymbol">opCmp</span>(ref const Node <b>node</b>);
|
||||
</dt>
|
||||
<dd><p>Compare with another node.</p>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
|
@ -521,7 +526,7 @@
|
|||
|
||||
<div id="copyright">
|
||||
Copyright © Ferdinand Majerech 2011. Based on <a href="http://www.pyyaml.org">PyYAML</a> by Kirill Simonov. |
|
||||
Page generated by Autodoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
Page generated by AutoDDoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
</dd>
|
||||
<dt class="d_decl">class <a name="Representer"></a><span class="ddoc_psymbol">Representer</span>;
|
||||
</dt>
|
||||
<dd><p>Represents YAML nodes of various data types as scalar, sequence and mapping nodes ready for output.
|
||||
<dd><p>Represents YAML nodes as scalar, sequence and mapping nodes ready for output.
|
||||
</p>
|
||||
<p>This class is used to add support for dumping of custom data types.
|
||||
<br>
|
||||
|
@ -73,26 +73,38 @@
|
|||
</dd>
|
||||
<dt class="d_decl">@property void <a name="defaultScalarStyle"></a><span class="ddoc_psymbol">defaultScalarStyle</span>(ScalarStyle <b>style</b>);
|
||||
</dt>
|
||||
<dd><p>Set default style for scalars. Invalid means the style is chosen automatically.</p>
|
||||
<dd><p>Set default style for scalars. If <b>style</b> is <span class="d_inlinecode">ScalarStyle.Invalid</span>, the style is chosen automatically.</p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">@property void <a name="defaultCollectionStyle"></a><span class="ddoc_psymbol">defaultCollectionStyle</span>(CollectionStyle <b>style</b>);
|
||||
</dt>
|
||||
<dd><p>Set default style for collections. Invalid means the style is chosen automatically. </p>
|
||||
<dd><p>Set default style for collections. If <b>style</b> is <span class="d_inlinecode">CollectionStyle.Invalid</span>, the style is chosen automatically. </p>
|
||||
|
||||
</dd>
|
||||
<dt class="d_decl">void <a name="addRepresenter"></a><span class="ddoc_psymbol">addRepresenter</span>(T)(Node function(ref Node, Representer) <b>representer</b>);
|
||||
</dt>
|
||||
<dd><p>Add a function to represent nodes with a specific data type.
|
||||
</p>
|
||||
<p>The representer function takes references to a Node storing the data
|
||||
type and to the Representer. It returns the represented node and may
|
||||
throw a RepresenterException. See the example for more information.
|
||||
<p>The representer function takes references to a <span class="d_inlinecode">Node</span> storing the data
|
||||
type and to the <span class="d_inlinecode">Representer</span>. It returns the represented node and may
|
||||
throw a <span class="d_inlinecode">RepresenterException</span>. See the example for more information.
|
||||
<br>
|
||||
|
||||
<br>
|
||||
|
||||
Only one function may be specified for one data type. Default data
|
||||
types already have representer functions unless disabled in the
|
||||
Representer constructor.
|
||||
<span class="d_inlinecode">Representer</span> constructor.
|
||||
<br>
|
||||
|
||||
<br>
|
||||
|
||||
Structs and classes must implement the <span class="d_inlinecode">opCmp()</span> operator for D:YAML
|
||||
support. The signature of the operator that must be implemented
|
||||
is <span class="d_inlinecode">const int opCmp(ref const MyStruct s)</span> for structs where
|
||||
<i>MyStruct</i> is the struct type, and <span class="d_inlinecode">int opCmp(Object o)</span> for
|
||||
classes. Note that the class <span class="d_inlinecode">opCmp()</span> should not alter the compared
|
||||
values - it is not const for compatibility reasons.
|
||||
|
||||
</p>
|
||||
<b>Parameters:</b><div class="pbr"><table class=parms><tr><td valign=top>representer</td>
|
||||
|
@ -106,6 +118,16 @@
|
|||
<span class="d_keyword">struct</span> MyStruct
|
||||
{
|
||||
<span class="d_keyword">int</span> x, y, z;
|
||||
|
||||
<span class="d_comment">//Any D:YAML type must have a custom opCmp operator.
|
||||
</span> <span class="d_comment">//This is used for ordering in mappings.
|
||||
</span> <span class="d_keyword">const</span> <span class="d_keyword">int</span> opCmp(<span class="d_keyword">ref</span> <span class="d_keyword">const</span> MyStruct s)
|
||||
{
|
||||
<span class="d_keyword">if</span>(x != s.x){<span class="d_keyword">return</span> x - s.x;}
|
||||
<span class="d_keyword">if</span>(y != s.y){<span class="d_keyword">return</span> y - s.y;}
|
||||
<span class="d_keyword">if</span>(z != s.z){<span class="d_keyword">return</span> z - s.z;}
|
||||
<span class="d_keyword">return</span> 0;
|
||||
}
|
||||
}
|
||||
|
||||
Node representMyStruct(<span class="d_keyword">ref</span> Node node, Representer representer)
|
||||
|
@ -144,12 +166,16 @@
|
|||
<span class="d_keyword">this</span>.z = z;
|
||||
}
|
||||
|
||||
<span class="d_comment">///We need custom opEquals for node equality, as default opEquals compares references.
|
||||
</span> <span class="d_keyword">override</span> <span class="d_keyword">bool</span> opEquals(Object rhs)
|
||||
<span class="d_comment">//Any D:YAML type must have a custom opCmp operator.
|
||||
</span> <span class="d_comment">//This is used for ordering in mappings.
|
||||
</span> <span class="d_keyword">override</span> <span class="d_keyword">int</span> opCmp(Object o)
|
||||
{
|
||||
<span class="d_keyword">if</span>(<span class="d_keyword">typeid</span>(rhs) != <span class="d_keyword">typeid</span>(MyClass)){<span class="d_keyword">return</span> <span class="d_keyword">false</span>;}
|
||||
<span class="d_keyword">auto</span> t = <span class="d_keyword">cast</span>(MyClass)rhs;
|
||||
<span class="d_keyword">return</span> x == t.x && y == t.y && z == t.z;
|
||||
MyClass s = <span class="d_keyword">cast</span>(MyClass)o;
|
||||
<span class="d_keyword">if</span>(s <span class="d_keyword">is</span> <span class="d_keyword">null</span>){<span class="d_keyword">return</span> -1;}
|
||||
<span class="d_keyword">if</span>(x != s.x){<span class="d_keyword">return</span> x - s.x;}
|
||||
<span class="d_keyword">if</span>(y != s.y){<span class="d_keyword">return</span> y - s.y;}
|
||||
<span class="d_keyword">if</span>(z != s.z){<span class="d_keyword">return</span> z - s.z;}
|
||||
<span class="d_keyword">return</span> 0;
|
||||
}
|
||||
|
||||
<span class="d_comment">///Useful for Node.as!string .
|
||||
|
@ -204,6 +230,16 @@
|
|||
<pre class="d_code"> <span class="d_keyword">struct</span> MyStruct
|
||||
{
|
||||
<span class="d_keyword">int</span> x, y, z;
|
||||
|
||||
<span class="d_comment">//Any D:YAML type must have a custom opCmp operator.
|
||||
</span> <span class="d_comment">//This is used for ordering in mappings.
|
||||
</span> <span class="d_keyword">const</span> <span class="d_keyword">int</span> opCmp(<span class="d_keyword">ref</span> <span class="d_keyword">const</span> MyStruct s)
|
||||
{
|
||||
<span class="d_keyword">if</span>(x != s.x){<span class="d_keyword">return</span> x - s.x;}
|
||||
<span class="d_keyword">if</span>(y != s.y){<span class="d_keyword">return</span> y - s.y;}
|
||||
<span class="d_keyword">if</span>(z != s.z){<span class="d_keyword">return</span> z - s.z;}
|
||||
<span class="d_keyword">return</span> 0;
|
||||
}
|
||||
}
|
||||
|
||||
Node representMyStruct(<span class="d_keyword">ref</span> Node node, Representer representer)
|
||||
|
@ -211,7 +247,6 @@
|
|||
<span class="d_keyword">auto</span> value = node.as!MyStruct;
|
||||
<span class="d_keyword">auto</span> <span class="d_param">scalar</span> = format(value.x, <span class="d_string">":"</span>, value.y, <span class="d_string">":"</span>, value.z);
|
||||
<span class="d_keyword">return</span> representer.<span class="d_psymbol">representScalar</span>(<span class="d_string">"!mystruct.tag"</span>, <span class="d_param">scalar</span>);
|
||||
|
||||
}
|
||||
</pre>
|
||||
</p>
|
||||
|
@ -225,7 +260,7 @@
|
|||
|
||||
</p>
|
||||
<b>Parameters:</b><div class="pbr"><table class=parms><tr><td valign=top>string <b>tag</b></td>
|
||||
<td valign=top>Tag of the <b>sequence</b>.</td></tr>
|
||||
<td valign=top>Tag of the sequence.</td></tr>
|
||||
<tr><td valign=top>Node[] <b>sequence</b></td>
|
||||
<td valign=top>Sequence of nodes.</td></tr>
|
||||
<tr><td valign=top>CollectionStyle <b>style</b></td>
|
||||
|
@ -235,13 +270,23 @@
|
|||
<b>Returns:</b><div class="pbr">The represented node.
|
||||
|
||||
</div>
|
||||
<b>Throws:</b><div class="pbr">RepresenterException if a child could not be represented.
|
||||
<b>Throws:</b><div class="pbr"><span class="d_inlinecode">RepresenterException</span> if a child could not be represented.
|
||||
|
||||
</div>
|
||||
<p><b>Example:</b><br>
|
||||
<pre class="d_code"> <span class="d_keyword">struct</span> MyStruct
|
||||
{
|
||||
<span class="d_keyword">int</span> x, y, z;
|
||||
|
||||
<span class="d_comment">//Any D:YAML type must have a custom opCmp operator.
|
||||
</span> <span class="d_comment">//This is used for ordering in mappings.
|
||||
</span> <span class="d_keyword">const</span> <span class="d_keyword">int</span> opCmp(<span class="d_keyword">ref</span> <span class="d_keyword">const</span> MyStruct s)
|
||||
{
|
||||
<span class="d_keyword">if</span>(x != s.x){<span class="d_keyword">return</span> x - s.x;}
|
||||
<span class="d_keyword">if</span>(y != s.y){<span class="d_keyword">return</span> y - s.y;}
|
||||
<span class="d_keyword">if</span>(z != s.z){<span class="d_keyword">return</span> z - s.z;}
|
||||
<span class="d_keyword">return</span> 0;
|
||||
}
|
||||
}
|
||||
|
||||
Node representMyStruct(<span class="d_keyword">ref</span> Node node, Representer representer)
|
||||
|
@ -274,13 +319,23 @@
|
|||
<b>Returns:</b><div class="pbr">The represented node.
|
||||
|
||||
</div>
|
||||
<b>Throws:</b><div class="pbr">RepresenterException if a child could not be represented.
|
||||
<b>Throws:</b><div class="pbr"><span class="d_inlinecode">RepresenterException</span> if a child could not be represented.
|
||||
|
||||
</div>
|
||||
<p><b>Example:</b><br>
|
||||
<pre class="d_code"> <span class="d_keyword">struct</span> MyStruct
|
||||
{
|
||||
<span class="d_keyword">int</span> x, y, z;
|
||||
|
||||
<span class="d_comment">//Any D:YAML type must have a custom opCmp operator.
|
||||
</span> <span class="d_comment">//This is used for ordering in mappings.
|
||||
</span> <span class="d_keyword">const</span> <span class="d_keyword">int</span> opCmp(<span class="d_keyword">ref</span> <span class="d_keyword">const</span> MyStruct s)
|
||||
{
|
||||
<span class="d_keyword">if</span>(x != s.x){<span class="d_keyword">return</span> x - s.x;}
|
||||
<span class="d_keyword">if</span>(y != s.y){<span class="d_keyword">return</span> y - s.y;}
|
||||
<span class="d_keyword">if</span>(z != s.z){<span class="d_keyword">return</span> z - s.z;}
|
||||
<span class="d_keyword">return</span> 0;
|
||||
}
|
||||
}
|
||||
|
||||
Node representMyStruct(<span class="d_keyword">ref</span> Node node, Representer representer)
|
||||
|
@ -348,7 +403,7 @@
|
|||
|
||||
<div id="copyright">
|
||||
Copyright © Ferdinand Majerech 2011. Based on <a href="http://www.pyyaml.org">PyYAML</a> by Kirill Simonov. |
|
||||
Page generated by Autodoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
Page generated by AutoDDoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -133,7 +133,7 @@
|
|||
|
||||
<div id="copyright">
|
||||
Copyright © Ferdinand Majerech 2011. Based on <a href="http://www.pyyaml.org">PyYAML</a> by Kirill Simonov. |
|
||||
Page generated by Autodoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
Page generated by AutoDDoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -96,7 +96,7 @@
|
|||
|
||||
<div id="copyright">
|
||||
Copyright © Ferdinand Majerech 2011. Based on <a href="http://www.pyyaml.org">PyYAML</a> by Kirill Simonov. |
|
||||
Page generated by Autodoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
Page generated by AutoDDoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -59,7 +59,7 @@ import the <i>yaml</i> module, which will import all needed modules.
|
|||
|
||||
<div id="copyright">
|
||||
Copyright © Ferdinand Majerech 2011. Based on <a href="http://www.pyyaml.org">PyYAML</a> by Kirill Simonov. |
|
||||
Page generated by Autodoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
Page generated by AutoDDoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue