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

@ -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";

View file

@ -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.