Files
OpenVulkano/openVulkanoCpp/Extensions/YamlCppConverters.hpp
2024-10-17 18:57:41 +02:00

54 lines
1.2 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "Base/UUID.hpp"
#include "Math/AABB.hpp"
#include <yaml-cpp/yaml.h>
#include <fmt/format.h>
#include <c4/format.hpp>
namespace YAML
{
template<>
struct convert<OpenVulkano::UUID>
{
static Node encode(const OpenVulkano::UUID& uuid)
{
return Node(uuid.string());
}
static bool decode(const Node& node, OpenVulkano::UUID& uuid)
{
if (node.IsScalar())
{
uuid.assign(node.Scalar());
return true;
}
return false;
}
};
template<>
struct convert<OpenVulkano::Math::AABB>
{
static Node encode(const OpenVulkano::Math::AABB& bbox)
{
return Node(fmt::format("({},{},{}),({},{},{})", bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z));
}
static bool decode(const Node& node, OpenVulkano::Math::AABB& bbox)
{
if (node.IsScalar())
{
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar()), "({},{},{}),({},{},{})", bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z);
return ret != c4::csubstr::npos;
}
return false;
}
};
}