Added a shortcut alias called "as" for Node.get(), and replaced

get() with as() all over the code, tutorials, examples and docs.
Fixed a bug in YAML benchmark makefile.
Fixed a bug in autoddoc configuration.
This commit is contained in:
Ferdinand Majerech 2011-10-22 17:06:32 +02:00
parent fb67e775e4
commit 13ea5f0c24
33 changed files with 236 additions and 215 deletions

View file

@ -116,7 +116,7 @@ into the file:</p>
<span class="p">{</span>
<span class="n">writeln</span><span class="p">(</span><span class="n">word</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">writeln</span><span class="p">(</span><span class="s">&quot;The answer is &quot;</span><span class="p">,</span> <span class="n">root</span><span class="p">[</span><span class="s">&quot;Answer&quot;</span><span class="p">].</span><span class="n">get</span><span class="p">!</span><span class="kt">int</span><span class="p">);</span>
<span class="n">writeln</span><span class="p">(</span><span class="s">&quot;The answer is &quot;</span><span class="p">,</span> <span class="n">root</span><span class="p">[</span><span class="s">&quot;Answer&quot;</span><span class="p">].</span><span class="n">as</span><span class="p">!</span><span class="kt">int</span><span class="p">);</span>
<span class="c1">//Dump the loaded document to output.yaml.</span>
<span class="n">Dumper</span><span class="p">(</span><span class="s">&quot;output.yaml&quot;</span><span class="p">).</span><span class="n">dump</span><span class="p">(</span><span class="n">root</span><span class="p">);</span>
@ -137,7 +137,7 @@ possible.</p>
mapping (associative array) or a scalar (value). Here the root node is a
mapping, and we use the index operator to get subnodes with keys &#8220;Hello World&#8221;
and &#8220;Answer&#8221;. We iterate over the first, as it is a sequence, and use the
<em>Node.get()</em> method on the second to get its value as an integer.</p>
<em>Node.as()</em> method on the second to read its value as an integer.</p>
<p>You can iterate over a mapping or sequence as if it was an associative or normal
array. If you try to iterate over a scalar, it will throw a <em>YAMLException</em>.</p>
<p>You can iterate over subnodes using <em>Node</em> as the iterated type, or specify
@ -147,9 +147,9 @@ so we iterate over the &#8220;Hello World&#8221; sequence as an array of strings
not possible to convert to iterated type, a <em>YAMLException</em> is thrown. For
instance, if we specified <em>int</em> here, we would get an error, as &#8220;Hello&#8221;
cannot be converted to an integer.</p>
<p>The <em>Node.get()</em> method is used to get value of a scalar node, allowing to
specify type. D:YAML will try to return the scalar as this type, converting if
needed, throwing <em>YAMLException</em> if not possible.</p>
<p>The <em>Node.as()</em> method is used to read value of a scalar node as specified type.
D:YAML will try to return the scalar as this type, converting if needed,
throwing <em>YAMLException</em> if not possible.</p>
<p>Finally we dump the document we just read to <tt class="docutils literal"><span class="pre">output.yaml</span></tt> with the
<em>Dumper.dump()</em> method. <em>Dumper</em> is a struct used to dump YAML documents.
The <em>dump()</em> method writes one or more documents to a file, throwing
@ -237,7 +237,7 @@ example in the <tt class="docutils literal"><span class="pre">example/getting_st
</div>
<div class="footer">
&copy; Copyright 2011, Ferdinand Majerech. Based on PyYAML http://www.pyyaml.org by Kirill Simonov.
Last updated on Oct 18, 2011.
Last updated on Oct 22, 2011.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
</div>
</body>