12#include <yaml-cpp/yaml.h>
29#define EZ_YAML_DEFINE(Base) \
30 EZ_FACTORY_DEFINE(Base, const YAML::Node &); \
31 template std::unique_ptr<Base> ezconfig::yaml::Create(const YAML::Node &); \
32 template struct YAML::convert<std::shared_ptr<Base>>; \
33 template struct YAML::convert<std::unique_ptr<Base>>
53#define EZ_YAML_REGISTER(Base, tag, Derived, ...) \
54 EZ_STATIC_INVOKE(&ezconfig::yaml::Add<Base, Derived __VA_OPT__(, ) __VA_ARGS__>, tag)
56namespace ezconfig::yaml {
61 {y.as<T>()} -> std::convertible_to<T>;
78template<
typename Base,
typename Derived,
typename Intermediate = Derived>
81 && std::is_constructible_v<Derived, Intermediate &&>)
82void Add(
const std::string & tag)
84 if (tag.size() < 2 || tag[0] !=
'!') {
throw std::logic_error(
"yaml tag must start with !"); }
85 auto creator = [](
const YAML::Node & y) {
return std::make_unique<Derived>(y.as<Intermediate>()); };
86 EZ_FACTORY_INSTANCE(Base,
const YAML::Node &).add(tag, std::move(creator));
89template<
typename Base>
90std::unique_ptr<Base> Create(
const YAML::Node & y)
92 return EZ_FACTORY_INSTANCE(Base,
const YAML::Node &).create(y.Tag(), y);
97template<ezconfig::yaml::Constructible Base>
100 ptr = ::ezconfig::yaml::Create<Base>(y);
104template<ezconfig::yaml::Constructible Base>
107 ptr = ::ezconfig::yaml::Create<Base>(y);
Yaml factory forward declarations.