196 lines
5.1 KiB
C++
196 lines
5.1 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
|
|
|
|
#if __has_include("fmt/format.h")
|
|
#include <fmt/format.h>
|
|
#elif __has_include("spdlog/fmt/fmt.h")
|
|
#include <spdlog/fmt/fmt.h>
|
|
#else
|
|
#error "Failed to find fmt include"
|
|
#endif
|
|
#include "Math/ByteSize.hpp"
|
|
#include "Math/Math.hpp"
|
|
#include "Math/Range.hpp"
|
|
#include "Base/UUID.hpp"
|
|
#include <filesystem>
|
|
#include <fmt/chrono.h>
|
|
|
|
template<> struct fmt::formatter<OpenVulkano::ByteSize>
|
|
{
|
|
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
|
{
|
|
return ctx.begin();
|
|
}
|
|
|
|
template<typename FormatContext> auto format(const OpenVulkano::ByteSize& bs, FormatContext& ctx) const
|
|
{
|
|
return fmt::format_to(ctx.out(), "{}", bs.Format());
|
|
}
|
|
};
|
|
|
|
template<> struct fmt::formatter<std::filesystem::path> : fmt::formatter<std::string>
|
|
{
|
|
template<typename PATH = std::filesystem::path>
|
|
auto format(const std::filesystem::path& path, format_context& ctx) const requires std::is_same_v<std::filesystem::path::value_type, char>
|
|
{
|
|
return formatter<std::string>::format(path.native(), ctx);
|
|
}
|
|
|
|
template<typename PATH = std::filesystem::path>
|
|
auto format(const std::filesystem::path& path, format_context& ctx) const requires std::is_same_v<std::filesystem::path::value_type, wchar_t>
|
|
{
|
|
return formatter<std::string>::format(path.string(), ctx);
|
|
}
|
|
};
|
|
|
|
template<typename T, glm::qualifier Q>
|
|
struct fmt::formatter<glm::vec<2, T, Q>>
|
|
{
|
|
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
|
{
|
|
return ctx.begin();
|
|
}
|
|
|
|
template<typename FormatContext>
|
|
auto format(const glm::vec<2, T, Q>& v, FormatContext& ctx) const
|
|
{
|
|
return fmt::format_to(ctx.out(), "({}, {})", v.x, v.y);
|
|
}
|
|
};
|
|
|
|
template<typename T, glm::qualifier Q>
|
|
struct fmt::formatter<glm::vec<3, T, Q>>
|
|
{
|
|
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
|
{
|
|
return ctx.begin();
|
|
}
|
|
|
|
template<typename FormatContext>
|
|
auto format(const glm::vec<3, T, Q>& v, FormatContext& ctx) const
|
|
{
|
|
return fmt::format_to(ctx.out(), "({}, {}, {})", v.x, v.y, v.z);
|
|
}
|
|
};
|
|
|
|
template<typename T, glm::qualifier Q>
|
|
struct fmt::formatter<glm::vec<4, T, Q>>
|
|
{
|
|
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
|
{
|
|
return ctx.begin();
|
|
}
|
|
|
|
template<typename FormatContext>
|
|
auto format(const glm::vec<4, T, Q>& v, FormatContext& ctx) const
|
|
{
|
|
return fmt::format_to(ctx.out(), "({}, {}, {}, {})", v.x, v.y, v.z, v.w);
|
|
}
|
|
};
|
|
|
|
template<typename T, glm::qualifier Q>
|
|
struct fmt::formatter<glm::mat<2, 2, T, Q>>
|
|
{
|
|
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
|
{
|
|
return ctx.begin();
|
|
}
|
|
|
|
template<typename FormatContext>
|
|
auto format(const glm::mat<2, 2, T, Q>& m, FormatContext& ctx) const
|
|
{
|
|
return fmt::format_to(ctx.out(), "[[{}, {}], [{}, {}]]",
|
|
m[0][0], m[1][0],
|
|
m[0][1], m[1][1]);
|
|
}
|
|
};
|
|
|
|
template<typename T, glm::qualifier Q>
|
|
struct fmt::formatter<glm::mat<3, 3, T, Q>>
|
|
{
|
|
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
|
{
|
|
return ctx.begin();
|
|
}
|
|
|
|
template<typename FormatContext>
|
|
auto format(const glm::mat<3, 3, T, Q>& m, FormatContext& ctx) const
|
|
{
|
|
return fmt::format_to(ctx.out(), "[[{}, {}, {}], [{}, {}, {}], [{}, {}, {}]]",
|
|
m[0][0], m[1][0], m[2][0],
|
|
m[0][1], m[1][1], m[2][1],
|
|
m[0][2], m[1][2], m[2][2]);
|
|
}
|
|
};
|
|
|
|
template<typename T, glm::qualifier Q>
|
|
struct fmt::formatter<glm::mat<4, 4, T, Q>>
|
|
{
|
|
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
|
{
|
|
return ctx.begin();
|
|
}
|
|
|
|
template<typename FormatContext>
|
|
auto format(const glm::mat<4, 4, T, Q>& m, FormatContext& ctx) const
|
|
{
|
|
return fmt::format_to(ctx.out(), "[[{}, {}, {}, {}], [{}, {}, {}, {}], [{}, {}, {}, {}], [{}, {}, {}, {}]]",
|
|
m[0][0], m[1][0], m[2][0], m[3][0],
|
|
m[0][1], m[1][1], m[2][1], m[3][1],
|
|
m[0][2], m[1][2], m[2][2], m[3][2],
|
|
m[0][3], m[1][3], m[2][3], m[3][3]);
|
|
}
|
|
};
|
|
|
|
template<typename T, glm::qualifier Q>
|
|
struct fmt::formatter<glm::qua<T, Q>>
|
|
{
|
|
template<typename ParseContext> constexpr auto parse(ParseContext& ctx)
|
|
{
|
|
return ctx.begin();
|
|
}
|
|
|
|
template<typename FormatContext>
|
|
auto format(const glm::qua<T, Q>& q, FormatContext& ctx) const
|
|
{
|
|
return fmt::format_to(ctx.out(), "({}, {}, {}, {})", q.w, q.x, q.y, q.z);
|
|
}
|
|
};
|
|
|
|
template<typename T>
|
|
struct fmt::formatter<OpenVulkano::Math::Range<T>> : fmt::formatter<std::string>
|
|
{
|
|
template<typename ParseContext>
|
|
constexpr auto parse(ParseContext& ctx)
|
|
{
|
|
return ctx.begin();
|
|
}
|
|
|
|
template<typename FormatContext>
|
|
auto format(const OpenVulkano::Math::Range<T>& range, FormatContext& ctx) const
|
|
{
|
|
return fmt::format_to(ctx.out(), "[{}, {}]", range.min, range.max);
|
|
}
|
|
};
|
|
|
|
template<>
|
|
struct fmt::formatter<OpenVulkano::UUID> : fmt::formatter<std::string>
|
|
{
|
|
template<typename ParseContext>
|
|
constexpr auto parse(ParseContext& ctx)
|
|
{
|
|
return ctx.begin();
|
|
}
|
|
|
|
template<typename FormatContext>
|
|
auto format(const OpenVulkano::UUID& uuid, FormatContext& ctx) const
|
|
{
|
|
return fmt::format_to(ctx.out(), "{}", uuid.string());
|
|
}
|
|
};
|