Move some fmt related code and allow formatting of std::filesystem::path

This commit is contained in:
Georg Hagen
2025-02-11 22:02:25 +01:00
parent af9de9c2af
commit 09195153e0
4 changed files with 79 additions and 63 deletions

View File

@@ -0,0 +1,45 @@
/*
* 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 <filesystem>
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);
}
};