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
|
|
|
|
{
|
2019-02-07 07:48:50 +00:00
|
|
|
auto dumper = dumper();
|
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)]);
|
|
|
|
|
2019-02-07 07:48:50 +00:00
|
|
|
dumper.dump(File("output.yaml", "w").lockingTextWriter, document);
|
2011-10-15 14:31:23 +00:00
|
|
|
}
|
|
|
|
catch(YAMLException e)
|
|
|
|
{
|
|
|
|
writeln(e.msg);
|
|
|
|
}
|
|
|
|
}
|