Here is my current model:
in header:
struct Example
{
int x, y;
template<MemberMappingOp op, bool required, typename Node>
bool map(Node& node, const typename MemberMappingNodeKey<Node, Example>::type *key = 0, const Example *oldValue = 0);
https:/// Loads the example from YAML.
void load(const YAML::Node& node, std::string *key = 0);
https:/// Saves the example to YAML.
YAML::Node save(const std::string *key = 0, const Example *oldValue = 0) const;
};
cpp file:
template<MemberMappingOp op, bool required, typename Node>
bool Example::map(Node& node, const typename MemberMappingNodeKey<Node, Example>::type *key, const Example *oldValue)
{
bool result = true;
if (!MemberMapping<op, required>::map(*this, &Example::x, node, "x", original)) result = !required;
if (!MemberMapping<op, required>::map(*this, &Example::y, node, "y", original)) result = !required;
return result;
}
void Example::load(const YAML::Node& node, std::string *key)
{
map<MemberMappingOps::load, true, YAML::Node>(node, key);
}
YAML::Node Example::save(const std::string *key = 0, const Example *oldValue)
{
YAML::Node node;
map<MemberMappingOps::save, true, YAML::Node>(node, key, oldValue);
return node;
}