ezconfig
Create C++ Objects from Yaml and Json
Loading...
Searching...
No Matches
enum.hpp
1// Copyright (c) 2023 Petter Nilsson. MIT License. https://github.com/pettni/ezconfig
2
3#pragma once
4
5#include <magic_enum/magic_enum.hpp>
6#include <yaml-cpp/yaml.h>
7
8#include "enum_fwd.hpp"
9
10template<ezconfig::ScopedEnum T>
11bool YAML::convert<T>::decode(const Node & yaml, T & obj)
12{
13 auto maybe_val = magic_enum::enum_cast<T>(yaml.as<std::string>());
14 if (maybe_val.has_value()) {
15 obj = maybe_val.value();
16 return true;
17 }
18 return false;
19}