2011-10-15 14:31:23 +00:00
|
|
|
import std.stdio;
|
2018-04-27 03:17:09 +00:00
|
|
|
import dyaml;
|
2011-10-15 14:31:23 +00:00
|
|
|
|
|
|
|
struct Color
|
|
|
|
{
|
|
|
|
ubyte red;
|
|
|
|
ubyte green;
|
|
|
|
ubyte blue;
|
2012-01-23 14:57:26 +00:00
|
|
|
|
2019-01-15 07:37:50 +00:00
|
|
|
Node opCast(T: Node)() const
|
2012-01-23 14:57:26 +00:00
|
|
|
{
|
2019-01-15 07:37:50 +00:00
|
|
|
static immutable hex = "0123456789ABCDEF";
|
|
|
|
|
|
|
|
//Using the color format from the Constructor example.
|
|
|
|
string scalar;
|
|
|
|
foreach(channel; [red, green, blue])
|
|
|
|
{
|
|
|
|
scalar ~= hex[channel / 16];
|
|
|
|
scalar ~= hex[channel % 16];
|
|
|
|
}
|
|
|
|
|
|
|
|
//Representing as a scalar, with custom tag to specify this data type.
|
|
|
|
return Node(scalar, "!color");
|
2012-01-23 14:57:26 +00:00
|
|
|
}
|
2011-10-15 14:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-06-22 03:59:10 +00:00
|
|
|
auto dumper = dumper(File("output.yaml", "w").lockingTextWriter);
|
2011-10-15 14:31:23 +00:00
|
|
|
|
2014-08-01 15:09:05 +00:00
|
|
|
auto document = Node([Color(255, 0, 0),
|
|
|
|
Color(0, 255, 0),
|
2011-10-15 14:31:23 +00:00
|
|
|
Color(0, 0, 255)]);
|
|
|
|
|
|
|
|
dumper.dump(document);
|
|
|
|
}
|
|
|
|
catch(YAMLException e)
|
|
|
|
{
|
|
|
|
writeln(e.msg);
|
|
|
|
}
|
|
|
|
}
|