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:
parent
fb67e775e4
commit
13ea5f0c24
33 changed files with 236 additions and 215 deletions
|
@ -12,7 +12,7 @@ struct Color
|
|||
|
||||
Color constructColorScalar(Mark start, Mark end, ref Node node)
|
||||
{
|
||||
string value = node.get!string;
|
||||
string value = node.as!string;
|
||||
|
||||
if(value.length != 6)
|
||||
{
|
||||
|
@ -51,9 +51,9 @@ Color constructColorMapping(Mark start, Mark end, ref Node node)
|
|||
//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)
|
||||
{
|
||||
|
@ -80,10 +80,10 @@ void main()
|
|||
|
||||
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;
|
||||
|
|
|
@ -11,7 +11,7 @@ void main()
|
|||
{
|
||||
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);
|
||||
|
|
|
@ -11,7 +11,7 @@ struct Color
|
|||
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";
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ struct Color
|
|||
|
||||
Color constructColorScalar(Mark start, Mark end, ref Node node)
|
||||
{
|
||||
string value = node.get!string;
|
||||
string value = node.as!string;
|
||||
|
||||
if(value.length != 6)
|
||||
{
|
||||
|
@ -51,9 +51,9 @@ Color constructColorMapping(Mark start, Mark end, ref Node node)
|
|||
//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)
|
||||
{
|
||||
|
@ -85,10 +85,10 @@ void main()
|
|||
|
||||
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;
|
||||
|
|
|
@ -2,4 +2,4 @@ main:
|
|||
dmd -w -I../../ -L-L../../ -L-ldyaml yaml_bench.d
|
||||
|
||||
clean:
|
||||
rm yaml_stats yaml_bench.o
|
||||
rm yaml_bench yaml_bench.o
|
||||
|
|
|
@ -29,13 +29,13 @@ void extract(ref Node document)
|
|||
{
|
||||
if(root.isScalar) switch(root.tag)
|
||||
{
|
||||
case "tag:yaml.org,2002:null": auto value = root.get!YAMLNull; break;
|
||||
case "tag:yaml.org,2002:bool": auto value = root.get!bool; break;
|
||||
case "tag:yaml.org,2002:int": auto value = root.get!long; break;
|
||||
case "tag:yaml.org,2002:float": auto value = root.get!real; break;
|
||||
case "tag:yaml.org,2002:binary": auto value = root.get!(ubyte[]); break;
|
||||
case "tag:yaml.org,2002:timestamp": auto value = root.get!SysTime; break;
|
||||
case "tag:yaml.org,2002:str": auto value = root.get!string; break;
|
||||
case "tag:yaml.org,2002:null": auto value = root.as!YAMLNull; break;
|
||||
case "tag:yaml.org,2002:bool": auto value = root.as!bool; break;
|
||||
case "tag:yaml.org,2002:int": auto value = root.as!long; break;
|
||||
case "tag:yaml.org,2002:float": auto value = root.as!real; break;
|
||||
case "tag:yaml.org,2002:binary": auto value = root.as!(ubyte[]); break;
|
||||
case "tag:yaml.org,2002:timestamp": auto value = root.as!SysTime; break;
|
||||
case "tag:yaml.org,2002:str": auto value = root.as!string; break;
|
||||
default: writeln("Unrecognozed tag: ", root.tag);
|
||||
}
|
||||
else if(root.isSequence) foreach(ref Node node; root)
|
||||
|
|
|
@ -75,7 +75,7 @@ string randomType(string[] types)
|
|||
auto probabilities = new uint[types.length];
|
||||
foreach(index, type; types)
|
||||
{
|
||||
probabilities[index] = config[type]["probability"].get!uint;
|
||||
probabilities[index] = config[type]["probability"].as!uint;
|
||||
}
|
||||
return types[dice(probabilities)];
|
||||
}
|
||||
|
@ -84,8 +84,8 @@ Node genString(bool root = false)
|
|||
{
|
||||
auto range = config["string"]["range"];
|
||||
|
||||
const chars = randomLong(range["min"].get!uint, range["max"].get!uint,
|
||||
range["dist"].get!string);
|
||||
const chars = randomLong(range["min"].as!uint, range["max"].as!uint,
|
||||
range["dist"].as!string);
|
||||
|
||||
char[] result = new char[chars];
|
||||
result[0] = randomChar(alphabet);
|
||||
|
@ -101,8 +101,8 @@ Node genInt(bool root = false)
|
|||
{
|
||||
auto range = config["int"]["range"];
|
||||
|
||||
const result = randomLong(range["min"].get!int, range["max"].get!int,
|
||||
range["dist"].get!string);
|
||||
const result = randomLong(range["min"].as!int, range["max"].as!int,
|
||||
range["dist"].as!string);
|
||||
|
||||
return Node(result);
|
||||
}
|
||||
|
@ -111,8 +111,8 @@ Node genFloat(bool root = false)
|
|||
{
|
||||
auto range = config["float"]["range"];
|
||||
|
||||
const result = randomReal(range["min"].get!real, range["max"].get!real,
|
||||
range["dist"].get!string);
|
||||
const result = randomReal(range["min"].as!real, range["max"].as!real,
|
||||
range["dist"].as!string);
|
||||
|
||||
return Node(result);
|
||||
}
|
||||
|
@ -126,10 +126,10 @@ Node genTimestamp(bool root = false)
|
|||
{
|
||||
auto range = config["timestamp"]["range"];
|
||||
|
||||
auto hnsecs = randomLong(range["min"].get!ulong, range["max"].get!ulong,
|
||||
range["dist"].get!string);
|
||||
auto hnsecs = randomLong(range["min"].as!ulong, range["max"].as!ulong,
|
||||
range["dist"].as!string);
|
||||
|
||||
if(randomNormalized() <= config["timestamp"]["round-chance"].get!real)
|
||||
if(randomNormalized() <= config["timestamp"]["round-chance"].as!real)
|
||||
{
|
||||
hnsecs -= hnsecs % 10000000;
|
||||
}
|
||||
|
@ -141,8 +141,8 @@ Node genBinary(bool root = false)
|
|||
{
|
||||
auto range = config["binary"]["range"];
|
||||
|
||||
const bytes = randomLong(range["min"].get!uint, range["max"].get!uint,
|
||||
range["dist"].get!string);
|
||||
const bytes = randomLong(range["min"].as!uint, range["max"].as!uint,
|
||||
range["dist"].as!string);
|
||||
|
||||
ubyte[] result = new ubyte[bytes];
|
||||
foreach(i; 0 .. bytes)
|
||||
|
@ -167,8 +167,8 @@ Node nodes(in bool root, Node range, in string tag, in bool set = false)
|
|||
}
|
||||
else
|
||||
{
|
||||
const elems = randomLong(range["min"].get!uint, range["max"].get!uint,
|
||||
range["dist"].get!string);
|
||||
const elems = randomLong(range["min"].as!uint, range["max"].as!uint,
|
||||
range["dist"].as!string);
|
||||
|
||||
nodes = new Node[elems];
|
||||
foreach(i; 0 .. elems)
|
||||
|
@ -204,8 +204,8 @@ Node pairs(bool root, bool complex, Node range, string tag)
|
|||
}
|
||||
else
|
||||
{
|
||||
const pairs = randomLong(range["min"].get!uint, range["max"].get!uint,
|
||||
range["dist"].get!string);
|
||||
const pairs = randomLong(range["min"].as!uint, range["max"].as!uint,
|
||||
range["dist"].as!string);
|
||||
|
||||
keys = new Node[pairs];
|
||||
values = new Node[pairs];
|
||||
|
@ -222,7 +222,7 @@ Node pairs(bool root, bool complex, Node range, string tag)
|
|||
Node genMap(bool root = false)
|
||||
{
|
||||
Node range = config["map"]["range"];
|
||||
const complex = config["complex-keys"].get!bool;
|
||||
const complex = config["complex-keys"].as!bool;
|
||||
|
||||
return pairs(root, complex, range, "tag:yaml.org,2002:map");
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ Node genMap(bool root = false)
|
|||
Node genOmap(bool root = false)
|
||||
{
|
||||
Node range = config["omap"]["range"];
|
||||
const complex = config["complex-keys"].get!bool;
|
||||
const complex = config["complex-keys"].as!bool;
|
||||
|
||||
return pairs(root, complex, range, "tag:yaml.org,2002:omap");
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ Node genOmap(bool root = false)
|
|||
Node genPairs(bool root = false)
|
||||
{
|
||||
Node range = config["pairs"]["range"];
|
||||
const complex = config["complex-keys"].get!bool;
|
||||
const complex = config["complex-keys"].as!bool;
|
||||
|
||||
return pairs(root, complex, range, "tag:yaml.org,2002:pairs");
|
||||
}
|
||||
|
@ -253,12 +253,12 @@ Node[] generate(in string configFileName)
|
|||
{
|
||||
config = Loader(configFileName).load();
|
||||
|
||||
minNodesDocument = config["min-nodes-per-document"].get!long;
|
||||
minNodesDocument = config["min-nodes-per-document"].as!long;
|
||||
|
||||
Node[] result;
|
||||
foreach(i; 0 .. config["documents"].get!uint)
|
||||
foreach(i; 0 .. config["documents"].as!uint)
|
||||
{
|
||||
result ~= generateNode(config["root-type"].get!string, true);
|
||||
result ~= generateNode(config["root-type"].as!string, true);
|
||||
totalNodes = 0;
|
||||
}
|
||||
|
||||
|
@ -290,8 +290,8 @@ void main(string[] args)
|
|||
encoding == "utf-32" ? Encoding.UTF_32:
|
||||
Encoding.UTF_8;
|
||||
|
||||
dumper.indent = config["indent"].get!uint;
|
||||
dumper.textWidth = config["text-width"].get!uint;
|
||||
dumper.indent = config["indent"].as!uint;
|
||||
dumper.textWidth = config["text-width"].as!uint;
|
||||
dumper.dump(generated);
|
||||
}
|
||||
catch(YAMLException e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue