YamlCppConverters for various pieces of math + tests
This commit is contained in:
@@ -9,6 +9,13 @@
|
||||
#include "Base/UUID.hpp"
|
||||
#include "Math/AABB.hpp"
|
||||
#include "Math/Pose.hpp"
|
||||
#include "Math/DenseVector3i.hpp"
|
||||
#include "Math/Int24.hpp"
|
||||
#include "Math/Range.hpp"
|
||||
#include "Math/RGB10A2.hpp"
|
||||
#include "Math/RGB565.hpp"
|
||||
#include "Math/RGBA5551.hpp"
|
||||
#include "Math/Timestamp.hpp"
|
||||
#include <yaml-cpp/yaml.h>
|
||||
#include <fmt/format.h>
|
||||
#include <c4/format.hpp>
|
||||
@@ -246,4 +253,159 @@ namespace YAML
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T, bool REDUCE_Y_RESOLUTION, bool ASSERT_INPUT_VALUES, int BITS_PER_COMPONENT>
|
||||
struct convert<OpenVulkano::Math::DenseVector3i<T, REDUCE_Y_RESOLUTION, ASSERT_INPUT_VALUES, BITS_PER_COMPONENT>>
|
||||
{
|
||||
static Node encode(const OpenVulkano::Math::DenseVector3i<T, REDUCE_Y_RESOLUTION, ASSERT_INPUT_VALUES, BITS_PER_COMPONENT>& v)
|
||||
{
|
||||
return Node(fmt::format("({},{},{})", v.X(), v.Y(), v.Z()));
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, OpenVulkano::Math::DenseVector3i<T, REDUCE_Y_RESOLUTION, ASSERT_INPUT_VALUES, BITS_PER_COMPONENT>& v)
|
||||
{
|
||||
if (node.IsScalar())
|
||||
{
|
||||
int x, y, z;
|
||||
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "({},{},{})", x, y, z);
|
||||
v = OpenVulkano::Math::DenseVector3i<T, REDUCE_Y_RESOLUTION, ASSERT_INPUT_VALUES, BITS_PER_COMPONENT>(x, y, z);
|
||||
return ret != c4::csubstr::npos;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct convert<OpenVulkano::int24>
|
||||
{
|
||||
static Node encode(const OpenVulkano::int24& v)
|
||||
{
|
||||
return Node(fmt::format("{}", static_cast<int>(v)));
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, OpenVulkano::int24& v)
|
||||
{
|
||||
if (node.IsScalar())
|
||||
{
|
||||
int value;
|
||||
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "{}", value);
|
||||
v = value;
|
||||
return ret != c4::csubstr::npos;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct convert<OpenVulkano::Math::Range<T>>
|
||||
{
|
||||
static Node encode(const OpenVulkano::Math::Range<T>& r)
|
||||
{
|
||||
return Node(fmt::format("[{},{}]", r.GetMin(), r.GetMax()));
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, OpenVulkano::Math::Range<T>& r)
|
||||
{
|
||||
if (node.IsScalar())
|
||||
{
|
||||
T minVal, maxVal;
|
||||
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "[{},{}]", minVal, maxVal);
|
||||
r = OpenVulkano::Math::Range<T>(minVal, maxVal);
|
||||
return ret != c4::csubstr::npos;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct convert<OpenVulkano::Math::RGB10A2<T>>
|
||||
{
|
||||
static Node encode(const OpenVulkano::Math::RGB10A2<T>& c)
|
||||
{
|
||||
return Node(fmt::format("[{},{},{},{}]", c.r, c.g, c.b, c.a));
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, OpenVulkano::Math::RGB10A2<T>& c)
|
||||
{
|
||||
if (node.IsScalar())
|
||||
{
|
||||
T r, g, b, a;
|
||||
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "[{},{},{},{}]", r, g, b, a);
|
||||
c.r = r;
|
||||
c.g = g;
|
||||
c.b = b;
|
||||
c.a = a;
|
||||
return ret != c4::csubstr::npos;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct convert<OpenVulkano::Math::RGB565>
|
||||
{
|
||||
static Node encode(const OpenVulkano::Math::RGB565& c)
|
||||
{
|
||||
return Node(fmt::format("[{},{},{}]", c.r, c.g, c.b));
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, OpenVulkano::Math::RGB565& c)
|
||||
{
|
||||
if (node.IsScalar())
|
||||
{
|
||||
int r, g, b;
|
||||
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "[{},{},{}]", r, g, b);
|
||||
c.r = r;
|
||||
c.g = g;
|
||||
c.b = b;
|
||||
return ret != c4::csubstr::npos;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct convert<OpenVulkano::Math::RGBA5551>
|
||||
{
|
||||
static Node encode(const OpenVulkano::Math::RGBA5551& c)
|
||||
{
|
||||
return Node(fmt::format("[{},{},{},{}]", c.r, c.g, c.b, c.a));
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, OpenVulkano::Math::RGBA5551& c)
|
||||
{
|
||||
if (node.IsScalar())
|
||||
{
|
||||
int r, g, b, a;
|
||||
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "[{},{},{},{}]", r, g, b, a);
|
||||
c.r = r;
|
||||
c.g = g;
|
||||
c.b = b;
|
||||
c.a = a;
|
||||
return ret != c4::csubstr::npos;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct convert<OpenVulkano::Math::Timestamp>
|
||||
{
|
||||
static Node encode(const OpenVulkano::Math::Timestamp& ts)
|
||||
{
|
||||
return Node(fmt::format("{}", ts.GetNanos()));
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, OpenVulkano::Math::Timestamp& ts)
|
||||
{
|
||||
if (node.IsScalar())
|
||||
{
|
||||
uint64_t nanos;
|
||||
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "{}", nanos);
|
||||
ts = OpenVulkano::Math::Timestamp(nanos);
|
||||
return ret != c4::csubstr::npos;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user