2011-08-16 12:53:13 +00:00
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
|
|
|
"http://www.w3.org/TR/html4/strict.dtd">
|
|
|
|
|
|
|
|
<html lang='en'>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8" >
|
2012-01-23 17:40:05 +00:00
|
|
|
<title>dyaml.loader - D:YAML 0.4 API documentation</title>
|
2011-08-16 12:53:13 +00:00
|
|
|
<link rel="stylesheet" type="text/css" href="css/style.css">
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body><div id="top">
|
|
|
|
<div id="header">
|
2012-01-23 17:40:05 +00:00
|
|
|
<img id="logo" alt="D:YAML logo" src="images/logo.png"><a id="main-heading" href="index.html">D:YAML 0.4 API documentation</a>
|
2011-08-16 12:53:13 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="navigation">
|
|
|
|
<div class="navblock">
|
|
|
|
<div id="toctop">
|
|
|
|
<ul><li><a href="../index.html">Documentation home</a></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="navblock">
|
|
|
|
<ul><li><a href="index.html">Main page</a></li>
|
|
|
|
<li><a href="dyaml.constructor.html">dyaml.constructor</a></li>
|
2011-10-14 08:34:53 +00:00
|
|
|
<li><a href="dyaml.dumper.html">dyaml.dumper</a></li>
|
|
|
|
<li><a href="dyaml.encoding.html">dyaml.encoding</a></li>
|
2011-08-16 12:53:13 +00:00
|
|
|
<li><a href="dyaml.exception.html">dyaml.exception</a></li>
|
2014-05-19 17:54:48 +00:00
|
|
|
<li><a href="dyaml.hacks.html">dyaml.hacks</a></li>
|
2011-10-14 08:34:53 +00:00
|
|
|
<li><a href="dyaml.linebreak.html">dyaml.linebreak</a></li>
|
2011-08-16 12:53:13 +00:00
|
|
|
<li><a href="dyaml.loader.html">dyaml.loader</a></li>
|
|
|
|
<li><a href="dyaml.node.html">dyaml.node</a></li>
|
2011-10-14 08:34:53 +00:00
|
|
|
<li><a href="dyaml.representer.html">dyaml.representer</a></li>
|
2011-08-16 12:53:13 +00:00
|
|
|
<li><a href="dyaml.resolver.html">dyaml.resolver</a></li>
|
2011-10-29 18:43:30 +00:00
|
|
|
<li><a href="dyaml.style.html">dyaml.style</a></li>
|
2011-08-16 12:53:13 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="content">
|
|
|
|
<h1>dyaml.loader</h1>
|
|
|
|
<!-- Generated by Ddoc from dyaml/loader.d -->
|
2011-10-14 08:34:53 +00:00
|
|
|
<p>Class used to load YAML documents.</p>
|
2011-08-16 12:53:13 +00:00
|
|
|
|
2013-12-17 14:19:01 +00:00
|
|
|
<dl><dt class="d_decl"><a name="Loader"></a>struct <a name="Loader"></a><span class="ddoc_psymbol">Loader</span>;
|
2011-08-16 12:53:13 +00:00
|
|
|
</dt>
|
2011-10-14 08:34:53 +00:00
|
|
|
<dd><p>Loads YAML documents from files or streams.
|
2011-08-16 12:53:13 +00:00
|
|
|
</p>
|
2011-10-14 08:34:53 +00:00
|
|
|
<p>User specified Constructor and/or Resolver can be used to support new
|
|
|
|
tags / data types.
|
2011-08-16 12:53:13 +00:00
|
|
|
|
|
|
|
</p>
|
2011-10-14 08:34:53 +00:00
|
|
|
<b>Examples:</b><div class="pbr">Load single YAML document from a file:
|
2013-12-17 14:19:01 +00:00
|
|
|
<pre class="d_code"><span class="d_keyword">auto</span> rootNode = <span class="d_psymbol">Loader</span>(<span class="d_string">"file.yaml"</span>).load();
|
|
|
|
...
|
2011-10-14 08:34:53 +00:00
|
|
|
</pre>
|
2013-12-17 14:19:01 +00:00
|
|
|
<br>
|
2011-08-16 12:53:13 +00:00
|
|
|
|
2011-10-14 08:34:53 +00:00
|
|
|
Load all YAML documents from a file:
|
2013-12-17 14:19:01 +00:00
|
|
|
<pre class="d_code"><span class="d_keyword">auto</span> nodes = <span class="d_psymbol">Loader</span>(<span class="d_string">"file.yaml"</span>).loadAll();
|
|
|
|
...
|
2011-10-14 08:34:53 +00:00
|
|
|
</pre>
|
2013-12-17 14:19:01 +00:00
|
|
|
<br>
|
2011-08-16 12:53:13 +00:00
|
|
|
|
2011-10-14 08:34:53 +00:00
|
|
|
Iterate over YAML documents in a file, lazily loading them:
|
2013-12-17 14:19:01 +00:00
|
|
|
<pre class="d_code"><span class="d_keyword">auto</span> loader = <span class="d_psymbol">Loader</span>(<span class="d_string">"file.yaml"</span>);
|
2011-08-16 12:53:13 +00:00
|
|
|
|
2013-12-17 14:19:01 +00:00
|
|
|
<span class="d_keyword">foreach</span>(<span class="d_keyword">ref</span> node; loader)
|
|
|
|
{
|
|
|
|
...
|
|
|
|
}
|
2011-10-14 08:34:53 +00:00
|
|
|
</pre>
|
2013-12-17 14:19:01 +00:00
|
|
|
<br>
|
2011-08-16 12:53:13 +00:00
|
|
|
|
2011-10-14 08:34:53 +00:00
|
|
|
Load YAML from memory:
|
2013-12-17 14:19:01 +00:00
|
|
|
<pre class="d_code"><span class="d_keyword">import</span> std.stream;
|
|
|
|
<span class="d_keyword">import</span> std.stdio;
|
2011-08-16 12:53:13 +00:00
|
|
|
|
2013-12-17 14:19:01 +00:00
|
|
|
string yaml_input = <span class="d_string">"red: '#ff0000'\n"</span>
|
|
|
|
<span class="d_string">"green: '#00ff00'\n"</span>
|
|
|
|
<span class="d_string">"blue: '#0000ff'"</span>;
|
2011-08-16 12:53:13 +00:00
|
|
|
|
2013-12-17 14:19:01 +00:00
|
|
|
<span class="d_keyword">auto</span> colors = <span class="d_psymbol">Loader</span>.fromString(yaml_input).load();
|
2011-08-16 12:53:13 +00:00
|
|
|
|
2013-12-17 14:19:01 +00:00
|
|
|
<span class="d_keyword">foreach</span>(string color, string value; colors)
|
|
|
|
{
|
|
|
|
writeln(color, <span class="d_string">" is "</span>, value, <span class="d_string">" in HTML/CSS"</span>);
|
|
|
|
}
|
2011-08-16 12:53:13 +00:00
|
|
|
</pre>
|
2013-12-17 14:19:01 +00:00
|
|
|
<br>
|
2011-10-14 08:34:53 +00:00
|
|
|
|
|
|
|
Use a custom constructor/resolver to support custom data types and/or implicit tags:
|
2013-12-17 14:19:01 +00:00
|
|
|
<pre class="d_code"><span class="d_keyword">auto</span> constructor = <span class="d_keyword">new</span> Constructor();
|
|
|
|
<span class="d_keyword">auto</span> resolver = <span class="d_keyword">new</span> Resolver();
|
2011-10-14 08:34:53 +00:00
|
|
|
|
2013-12-17 14:19:01 +00:00
|
|
|
<span class="d_comment">//Add constructor functions / resolver expressions here...
|
2011-10-14 08:34:53 +00:00
|
|
|
</span>
|
2013-12-17 14:19:01 +00:00
|
|
|
<span class="d_keyword">auto</span> loader = <span class="d_psymbol">Loader</span>(<span class="d_string">"file.yaml"</span>);
|
|
|
|
loader.constructor = constructor;
|
|
|
|
loader.resolver = resolver;
|
|
|
|
<span class="d_keyword">auto</span> rootNode = loader.load(node);
|
2011-10-14 08:34:53 +00:00
|
|
|
</pre>
|
2011-08-16 12:53:13 +00:00
|
|
|
</div>
|
|
|
|
|
2013-12-17 14:19:01 +00:00
|
|
|
<dl><dt class="d_decl"><a name="Loader.this"></a>@trusted this(string <b>filename</b>);
|
2011-08-16 12:53:13 +00:00
|
|
|
</dt>
|
2011-10-14 08:34:53 +00:00
|
|
|
<dd><p>Construct a Loader to load YAML from a file.
|
2011-08-16 12:53:13 +00:00
|
|
|
</p>
|
2011-11-16 02:10:29 +00:00
|
|
|
<b>Parameters:</b><div class="pbr"><table class=parms><tr><td valign=top>string <b>filename</b></td>
|
2011-08-16 12:53:13 +00:00
|
|
|
<td valign=top>Name of the file to load from.</td></tr>
|
|
|
|
</table></div>
|
2011-10-18 14:12:22 +00:00
|
|
|
<b>Throws:</b><div class="pbr">YAMLException if the file could not be opened or read.</div>
|
2011-08-16 12:53:13 +00:00
|
|
|
|
|
|
|
</dd>
|
2013-12-17 14:19:01 +00:00
|
|
|
<dt class="d_decl"><a name="Loader.fromString"></a>static Loader <a name="fromString"></a><span class="ddoc_psymbol">fromString</span>(string <b>data</b>);
|
|
|
|
</dt>
|
|
|
|
<dd><p>Construct a Loader to load YAML from a string.
|
|
|
|
</p>
|
|
|
|
<b>Parameters:</b><div class="pbr"><table class=parms><tr><td valign=top>string <b>data</b></td>
|
|
|
|
<td valign=top>String to load YAML from.</td></tr>
|
|
|
|
</table></div>
|
|
|
|
<b>Returns:</b><div class="pbr">Loader loading YAML from given string.</div>
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
<dt class="d_decl"><a name="Loader.this"></a>@safe this(Stream <b>stream</b>);
|
2011-08-16 12:53:13 +00:00
|
|
|
</dt>
|
2011-10-14 08:34:53 +00:00
|
|
|
<dd><p>Construct a Loader to load YAML from a stream.
|
2011-08-16 12:53:13 +00:00
|
|
|
</p>
|
2011-10-14 08:34:53 +00:00
|
|
|
<b>Parameters:</b><div class="pbr"><table class=parms><tr><td valign=top>Stream <b>stream</b></td>
|
2011-10-27 21:13:14 +00:00
|
|
|
<td valign=top>Stream to read from. Must be readable and seekable.</td></tr>
|
2011-08-16 12:53:13 +00:00
|
|
|
</table></div>
|
2011-10-18 14:12:22 +00:00
|
|
|
<b>Throws:</b><div class="pbr">YAMLException if <b>stream</b> could not be read.</div>
|
2011-08-16 12:53:13 +00:00
|
|
|
|
|
|
|
</dd>
|
2013-12-17 14:19:01 +00:00
|
|
|
<dt class="d_decl"><a name="Loader.name"></a>pure nothrow @property @safe void <a name="name"></a><span class="ddoc_psymbol">name</span>(string <a name="name"></a><span class="ddoc_psymbol">name</span>);
|
2011-08-16 12:53:13 +00:00
|
|
|
</dt>
|
2011-10-14 08:34:53 +00:00
|
|
|
<dd><p>Set stream name. Used in debugging messages.</p>
|
2011-08-16 12:53:13 +00:00
|
|
|
|
|
|
|
</dd>
|
2013-12-17 14:19:01 +00:00
|
|
|
<dt class="d_decl"><a name="Loader.resolver"></a>pure nothrow @property @safe void <a name="resolver"></a><span class="ddoc_psymbol">resolver</span>(Resolver <a name="resolver"></a><span class="ddoc_psymbol">resolver</span>);
|
2011-08-16 12:53:13 +00:00
|
|
|
</dt>
|
2011-10-14 08:34:53 +00:00
|
|
|
<dd><p>Specify custom Resolver to use.</p>
|
2011-08-16 12:53:13 +00:00
|
|
|
|
|
|
|
</dd>
|
2013-12-17 14:19:01 +00:00
|
|
|
<dt class="d_decl"><a name="Loader.constructor"></a>pure nothrow @property @safe void <a name="constructor"></a><span class="ddoc_psymbol">constructor</span>(Constructor <a name="constructor"></a><span class="ddoc_psymbol">constructor</span>);
|
2011-08-16 12:53:13 +00:00
|
|
|
</dt>
|
2011-10-14 08:34:53 +00:00
|
|
|
<dd><p>Specify custom Constructor to use.</p>
|
2011-08-16 12:53:13 +00:00
|
|
|
|
|
|
|
</dd>
|
2013-12-17 14:19:01 +00:00
|
|
|
<dt class="d_decl"><a name="Loader.load"></a>@safe Node <a name="load"></a><span class="ddoc_psymbol">load</span>();
|
2011-08-16 12:53:13 +00:00
|
|
|
</dt>
|
|
|
|
<dd><p>Load single YAML document.
|
|
|
|
</p>
|
2011-10-18 14:12:22 +00:00
|
|
|
<p>If none or more than one YAML document is found, this throws a YAMLException.
|
2011-11-16 02:10:29 +00:00
|
|
|
<br>
|
|
|
|
|
|
|
|
This can only be called once; this is enforced by contract.
|
2011-08-16 12:53:13 +00:00
|
|
|
|
|
|
|
</p>
|
|
|
|
<b>Returns:</b><div class="pbr">Root node of the document.
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<b>Throws:</b><div class="pbr">YAMLException if there wasn't exactly one document
|
|
|
|
or on a YAML parsing error.</div>
|
|
|
|
|
2011-10-14 08:34:53 +00:00
|
|
|
</dd>
|
2013-12-17 14:19:01 +00:00
|
|
|
<dt class="d_decl"><a name="Loader.loadAll"></a>@safe Node[] <a name="loadAll"></a><span class="ddoc_psymbol">loadAll</span>();
|
2011-10-14 08:34:53 +00:00
|
|
|
</dt>
|
|
|
|
<dd><p>Load all YAML documents.
|
2011-10-22 15:06:32 +00:00
|
|
|
</p>
|
|
|
|
<p>This is just a shortcut that iterates over all documents and returns
|
|
|
|
them all at once. Calling <a name="loadAll"></a><span class="ddoc_psymbol">loadAll</span> after iterating over the node or
|
|
|
|
vice versa will not return any documents, as they have all been parsed
|
|
|
|
already.
|
2011-11-16 02:10:29 +00:00
|
|
|
<br>
|
|
|
|
|
|
|
|
This can only be called once; this is enforced by contract.
|
2011-10-22 15:06:32 +00:00
|
|
|
|
2011-10-14 08:34:53 +00:00
|
|
|
</p>
|
|
|
|
<b>Returns:</b><div class="pbr">Array of root nodes of all documents in the file/stream.
|
|
|
|
|
|
|
|
</div>
|
2011-10-18 14:12:22 +00:00
|
|
|
<b>Throws:</b><div class="pbr">YAMLException on a parsing error.</div>
|
2011-10-14 08:34:53 +00:00
|
|
|
|
2011-08-16 12:53:13 +00:00
|
|
|
</dd>
|
2013-12-17 14:19:01 +00:00
|
|
|
<dt class="d_decl"><a name="Loader.opApply"></a>@trusted int <a name="opApply"></a><span class="ddoc_psymbol">opApply</span>(int delegate(ref Node) <b>dg</b>);
|
2011-08-16 12:53:13 +00:00
|
|
|
</dt>
|
|
|
|
<dd><p>Foreach over YAML documents.
|
|
|
|
</p>
|
2011-10-14 08:34:53 +00:00
|
|
|
<p>Parses documents lazily, when they are needed.
|
2011-11-16 02:10:29 +00:00
|
|
|
<br>
|
|
|
|
|
|
|
|
Foreach over a Loader can only be used once; this is enforced by contract.
|
2011-08-16 12:53:13 +00:00
|
|
|
|
|
|
|
</p>
|
|
|
|
<b>Throws:</b><div class="pbr">YAMLException on a parsing error.</div>
|
|
|
|
|
|
|
|
</dd>
|
|
|
|
</dl>
|
|
|
|
</dd>
|
|
|
|
</dl>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="copyright">
|
|
|
|
Copyright © Ferdinand Majerech 2011. Based on <a href="http://www.pyyaml.org">PyYAML</a> by Kirill Simonov. |
|
2012-01-23 14:57:26 +00:00
|
|
|
Page generated by AutoDDoc and <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>.
|
2011-08-16 12:53:13 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|