From 13ea5f0c24a106612ce96a9b96ffdaf771105ae2 Mon Sep 17 00:00:00 2001
From: Ferdinand Majerech
Date: Sat, 22 Oct 2011 17:06:32 +0200
Subject: [PATCH] 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.
---
autoddoc.cfg | 2 +-
doc/doctrees/environment.pickle | Bin 12705 -> 12705 bytes
doc/doctrees/tutorials/custom_types.doctree | Bin 47211 -> 46981 bytes
.../tutorials/getting_started.doctree | Bin 35418 -> 35392 bytes
doc/html/_sources/tutorials/custom_types.txt | 22 ++--
.../_sources/tutorials/getting_started.txt | 10 +-
doc/html/api/dyaml.constructor.html | 6 +-
doc/html/api/dyaml.dumper.html | 4 +-
doc/html/api/dyaml.loader.html | 6 ++
doc/html/api/dyaml.node.html | 16 ++-
doc/html/api/dyaml.representer.html | 12 +--
doc/html/articles/spec_differences.html | 2 +-
doc/html/index.html | 2 +-
doc/html/search.html | 2 +-
doc/html/searchindex.js | 2 +-
doc/html/tutorials/custom_types.html | 24 ++---
doc/html/tutorials/getting_started.html | 12 +--
doc/html/tutorials/yaml_syntax.html | 2 +-
docsrc/tutorials/custom_types.rst | 22 ++--
docsrc/tutorials/getting_started.rst | 10 +-
dyaml/constructor.d | 42 ++++----
dyaml/node.d | 95 +++++++++---------
dyaml/representer.d | 40 ++++----
dyaml/serializer.d | 6 +-
examples/constructor/main.d | 16 +--
examples/getting_started/main.d | 2 +-
examples/representer/main.d | 2 +-
examples/resolver/main.d | 16 +--
examples/yaml_bench/Makefile | 2 +-
examples/yaml_bench/yaml_bench.d | 14 +--
examples/yaml_gen/yaml_gen.d | 48 ++++-----
test/src/constructor.d | 8 +-
test/src/inputoutput.d | 4 +-
33 files changed, 236 insertions(+), 215 deletions(-)
diff --git a/autoddoc.cfg b/autoddoc.cfg
index e21ffe1..7498db8 100644
--- a/autoddoc.cfg
+++ b/autoddoc.cfg
@@ -29,7 +29,7 @@ links = ../index.html Documentation home
# Source files or patterns to ignore. Supports regexp syntax.
# E.g; To ignore main.d and all source files in the test/ directory,
# you would use: "main.d test/*"
-ignore = test/*, examples/*, docsrc/*, autoddoc/*, yaml.d, unittest.d, cdc.d, dyaml/composer.d, dyaml/event.d, dyaml/parser.d, dyaml/reader.d, dyaml/scanner.d, dyaml/token.d, dyaml/util.d, dyaml/anchor.d, dyaml/emitter.d, dyaml/flags.d, dyaml/serializer.d, dyaml/sharedobject.d, dyaml/tag.d, dyaml/tagdirectives.d
+ignore = test/*, examples/*, docsrc/*, autoddoc/*, yaml.d, unittest.d, cdc.d, dyaml/composer.d, dyaml/event.d, dyaml/parser.d, dyaml/reader.d, dyaml/scanner.d, dyaml/token.d, dyaml/util.d, dyaml/anchor.d, dyaml/emitter.d, dyaml/flags.d, dyaml/serializer.d, dyaml/sharedobject.d, dyaml/tag.d, dyaml/tagdirectives.d, dyaml/queue.d
[DDOC]
# Command to use to generate the documentation.
diff --git a/doc/doctrees/environment.pickle b/doc/doctrees/environment.pickle
index adc89ed267d0966fe9809cbeb3c05d371d4a4d41..ecb58beed1a56d66ba151f19a3f3b1d6ec8e357a 100644
GIT binary patch
delta 63
zcmZ3OyfAq~tG>~SZ5KG^7H25CJ6>L~?fkzxw=;CW%nK|ppJkXrm`sKrGVCA<{+~13
Jyj}klBLE=vA)5dI
delta 63
zcmZ3OyfAq~tG?0l(yJm>4>OeA9WMi!+|3^|bRbN@<{KHN5GKF-)C@Zalc(v*=I#2g
F7y-pa9!&rM
diff --git a/doc/doctrees/tutorials/custom_types.doctree b/doc/doctrees/tutorials/custom_types.doctree
index 056c1d896bb84b32a26a8c2bb72bf7e834d53998..98e74fb473f18793e3ccd1f5db4ce3324cce3fda 100644
GIT binary patch
delta 3074
zcma)8Yj6}*7S4ppV-jWvnY@UEJRpEVfG9@s5u*aiMuI4<@e$je={xBjdb-Ec-H@nb
zL`4kdJ--k}OZ}kU!{pr$YX66$|>vM~|u8E)8UPi-@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z_WS~`5J$dJfKPJN?1Nbxb}PIKSP}9k;_X)GwKjq^f#08)zm|X-CB(CKe#PDj&F7x9_*;!b)2P+5oPJa-zfUvbHkT=$`%G6G=L(RN03TVJoh>M?QP|
z{DFczN-n+2f5iR}{7JrYRq_9s`+va}|6kY9|J7gRmbtdTYiJ3<>)0v8FM#J6c%7)N-UlnE*3YLNz@S`vN>Fgl@}xvuPnn-l$w|_d84}Y
z=9$W7%sku-3=CR+`6;P-K7FQOM6zD9K1wC{9hz
z&r4A#$yb1yB{{iTU5v2G%^TGhacdn08W;jJ1!k*;rWVZn%wmPo;#7pm_f5q`6cURS
ziVIScGt)9bGL;3XdR&t?7&~w(wh3VE5rVSH>8S^$z6c%7)PEReF94Zz!nNidcNoaGZ7%MMWE=E}fOs`j$-aK8|
zjG32*fq_BGFFz$!52W>`njQ}qPy{X@q^`qgI@w+wqAOlqAHmzaUVRa_;Ax=hkc?CX
zgc*s(Vqh!eO~qw&6cTfC^2;;x(iKYbxrz%?lQYvQ6-p`#QuP!jdzm_La^gA+0pEOFaTDjgXI7K
diff --git a/doc/html/_sources/tutorials/custom_types.txt b/doc/html/_sources/tutorials/custom_types.txt
index 389abdc..35d48e0 100644
--- a/doc/html/_sources/tutorials/custom_types.txt
+++ b/doc/html/_sources/tutorials/custom_types.txt
@@ -54,7 +54,7 @@ of these functions:
Color constructColorScalar(Mark start, Mark end, ref Node node)
{
- string value = node.get!string;
+ string value = node.as!string;
if(value.length != 6)
{
@@ -93,9 +93,9 @@ of these functions:
//Might throw if a value is missing is not an integer, or is out of range.
try
{
- r = node["r"].get!ubyte;
- g = node["g"].get!ubyte;
- b = node["b"].get!ubyte;
+ r = node["r"].as!ubyte;
+ g = node["g"].as!ubyte;
+ b = node["b"].as!ubyte;
}
catch(NodeException e)
{
@@ -143,10 +143,10 @@ Finally, the code to put it all together:
auto root = loader.load();
- if(root["scalar-red"].get!Color == red &&
- root["mapping-red"].get!Color == red &&
- root["scalar-orange"].get!Color == orange &&
- root["mapping-orange"].get!Color == orange)
+ if(root["scalar-red"].as!Color == red &&
+ root["mapping-red"].as!Color == red &&
+ root["scalar-orange"].as!Color == orange &&
+ root["mapping-orange"].as!Color == orange)
{
writeln("SUCCESS");
return;
@@ -162,8 +162,8 @@ Finally, the code to put it all together:
First, we create a *Constructor* and pass functions to handle the ``!color``
and ``!color-mapping`` tag. We construct a *Loader* and pass the *Constructor*
-to it. We then load the YAML document, and finally, read the colors using
-*get()* method to test if they were loaded as expected.
+to it. We then load the YAML document, and finally, read the colors to test if
+they were loaded as expected.
You can find the source code for what we've done so far in the
``examples/constructor`` directory in the D:YAML package.
@@ -256,7 +256,7 @@ With the following code, we will add support for dumping the our Color type.
Node representColor(ref Node node, Representer representer)
{
//The node is guaranteed to be Color as we add representer for Color.
- Color color = node.get!Color;
+ Color color = node.as!Color;
static immutable hex = "0123456789ABCDEF";
diff --git a/doc/html/_sources/tutorials/getting_started.txt b/doc/html/_sources/tutorials/getting_started.txt
index 8e4c7cd..55c451b 100644
--- a/doc/html/_sources/tutorials/getting_started.txt
+++ b/doc/html/_sources/tutorials/getting_started.txt
@@ -90,7 +90,7 @@ into the file:
{
writeln(word);
}
- writeln("The answer is ", root["Answer"].get!int);
+ writeln("The answer is ", root["Answer"].as!int);
//Dump the loaded document to output.yaml.
Dumper("output.yaml").dump(root);
@@ -115,7 +115,7 @@ possible.
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 "Hello World"
and "Answer". We iterate over the first, as it is a sequence, and use the
-*Node.get()* method on the second to get its value as an integer.
+*Node.as()* method on the second to read its value as an integer.
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 *YAMLException*.
@@ -128,9 +128,9 @@ not possible to convert to iterated type, a *YAMLException* is thrown. For
instance, if we specified *int* here, we would get an error, as "Hello"
cannot be converted to an integer.
-The *Node.get()* 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 *YAMLException* if not possible.
+The *Node.as()* 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 *YAMLException* if not possible.
Finally we dump the document we just read to ``output.yaml`` with the
*Dumper.dump()* method. *Dumper* is a struct used to dump YAML documents.
diff --git a/doc/html/api/dyaml.constructor.html b/doc/html/api/dyaml.constructor.html
index 117a4b3..63d0eca 100644
--- a/doc/html/api/dyaml.constructor.html
+++ b/doc/html/api/dyaml.constructor.html
@@ -127,7 +127,7 @@
{
auto parts = node.get!string().split(":");
+ auto parts = node.as!string().split(":");
try
{
return MyStruct(to!int(parts[0]), to!int(parts[1]), to!int(parts[2]));
@@ -174,7 +174,7 @@
try
{
- return MyStruct(node[0].get!int, node[1].get!int, node[2].get!int);
+ return MyStruct(node[0].as!int, node[1].as!int, node[2].as!int);
}
catch(NodeException e)
{
@@ -218,7 +218,7 @@
try
{
- return MyStruct(node["x"].get!int, node["y"].get!int, node["z"].get!int);
+ return MyStruct(node["x"].as!int, node["y"].as!int, node["z"].as!int);
}
catch(NodeException e)
{
diff --git a/doc/html/api/dyaml.dumper.html b/doc/html/api/dyaml.dumper.html
index 403281d..2ccf744 100644
--- a/doc/html/api/dyaml.dumper.html
+++ b/doc/html/api/dyaml.dumper.html
@@ -189,9 +189,11 @@
Example:
Dumper dumper = Dumper("file.yaml");
+ string[string] directives;
+ directives["!short!"] = "tag:long.org,2011:";
dumper.tags("short", "tag:long.org,2011:");
+ dumper.tagDirectives(directives);
dumper.dump(Node("foo"));
diff --git a/doc/html/api/dyaml.loader.html b/doc/html/api/dyaml.loader.html
index 89af805..1223a95 100644
--- a/doc/html/api/dyaml.loader.html
+++ b/doc/html/api/dyaml.loader.html
@@ -149,6 +149,12 @@
Node[] loadAll();
Load all YAML documents.
+
+This is just a shortcut that iterates over all documents and returns
+ them all at once. Calling loadAll after iterating over the node or
+ vice versa will not return any documents, as they have all been parsed
+ already.
+
Returns:Array of root nodes of all documents in the file/stream.
diff --git a/doc/html/api/dyaml.node.html b/doc/html/api/dyaml.node.html
index d90e293..825532d 100644
--- a/doc/html/api/dyaml.node.html
+++ b/doc/html/api/dyaml.node.html
@@ -246,6 +246,11 @@
Is this node a user defined type?
+
+
const @property string tag();
+
+
Return tag of the node.
+
bool opEquals(T)(ref T rhs);
@@ -271,6 +276,11 @@
Returns:true if equal, false otherwise.
+
+alias as;
+
+Shortcut for get().
+
T get(T)();
@@ -303,9 +313,9 @@
Examples:Automatic type conversion:
auto node = Node(42);
- assert(node.get!int == 42);
- assert(node.get!string == "42");
- assert(node.get!double == 42.0);
+ assert(node.as!int == 42);
+ assert(node.as!string == "42");
+ assert(node.as!double == 42.0);
diff --git a/doc/html/api/dyaml.representer.html b/doc/html/api/dyaml.representer.html
index b1dfb6a..4326e3f 100644
--- a/doc/html/api/dyaml.representer.html
+++ b/doc/html/api/dyaml.representer.html
@@ -95,7 +95,7 @@
Node representMyStruct(ref Node node, Representer representer)
{
auto value = node.get!MyStruct;
+ auto value = node.as!MyStruct;
auto scalar = format(value.x, ":", value.y, ":", value.z);
auto value = node.as!MyClass;
auto scalar = format(value.x, ":", value.y, ":", value.z);