mirror of
https://github.com/Vita3K/Vita3K.git
synced 2026-07-25 00:14:33 +02:00
util: use Boost.Describe to enum to string conversion for log and tracy
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
|
||||
TRACY_MODULE_NAME(SceAudiodecUser);
|
||||
|
||||
BOOST_DESCRIBE_ENUM(SceAudiodecCodec, SCE_AUDIODEC_TYPE_AT9, SCE_AUDIODEC_TYPE_MP3, SCE_AUDIODEC_TYPE_AAC, SCE_AUDIODEC_TYPE_CELP)
|
||||
|
||||
enum {
|
||||
SCE_AUDIODEC_ERROR_API_FAIL = 0x807F0000,
|
||||
SCE_AUDIODEC_ERROR_NOT_INITIALIZED = 0x807F0005,
|
||||
@@ -194,12 +196,12 @@ static int create_decoder(EmuEnvState &emuenv, SceAudiodecCtrl *ctrl, SceAudiode
|
||||
ctrl->pcm_size_max = info.channels * SCE_AUDIODEC_MP3_V2_MAX_PCM_SIZE;
|
||||
return 0;
|
||||
default:
|
||||
LOG_ERROR("Invalid MPEG version {}.", to_debug_str(emuenv.mem, info.version));
|
||||
LOG_ERROR("Invalid MPEG version {}.", info.version);
|
||||
return SCE_AUDIODEC_MP3_ERROR_INVALID_MPEG_VERSION;
|
||||
}
|
||||
}
|
||||
default: {
|
||||
LOG_ERROR("Unimplemented audio decoder {}.", to_debug_str(emuenv.mem, codec));
|
||||
LOG_ERROR("Unimplemented audio decoder {}.", codec);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ enum SceJpegColorSpace : int {
|
||||
SCE_JPEG_COLORSPACE_YUV411 = 0x20401,
|
||||
};
|
||||
|
||||
BOOST_DESCRIBE_ENUM(SceJpegColorSpace, SCE_JPEG_COLORSPACE_UNKNOWN, SCE_JPEG_COLORSPACE_GRAYSCALE, SCE_JPEG_COLORSPACE_YUV, SCE_JPEG_COLORSPACE_YUV444, SCE_JPEG_COLORSPACE_YUV440, SCE_JPEG_COLORSPACE_YUV441, SCE_JPEG_COLORSPACE_YUV422, SCE_JPEG_COLORSPACE_YUV420, SCE_JPEG_COLORSPACE_YUV411)
|
||||
enum SceJpegDHTMode : int {
|
||||
SCE_JPEG_MJPEG_WITH_DHT,
|
||||
SCE_JPEG_MJPEG_WITHOUT_DHT,
|
||||
@@ -59,6 +60,8 @@ enum SceJpegDHTMode : int {
|
||||
SCE_JPEG_MJPEG_ANY_SAMPLING
|
||||
};
|
||||
|
||||
BOOST_DESCRIBE_ENUM(SceJpegDHTMode, SCE_JPEG_MJPEG_WITH_DHT, SCE_JPEG_MJPEG_WITHOUT_DHT, SCE_JPEG_MJPEG_ANY_SAMPLING_WITHOUT_DHT, SCE_JPEG_MJPEG_ANY_SAMPLING)
|
||||
|
||||
enum SceJpegDownscaleMode : int {
|
||||
SCE_JPEG_MJPEG_DOWNSCALE_1_2 = 1 << 4,
|
||||
SCE_JPEG_MJPEG_DOWNSCALE_1_4 = 1 << 5,
|
||||
@@ -66,6 +69,8 @@ enum SceJpegDownscaleMode : int {
|
||||
SCE_JPEG_MJPEG_DOWNSCALE_ANY = 0b111 << 4
|
||||
};
|
||||
|
||||
BOOST_DESCRIBE_ENUM(SceJpegDownscaleMode, SCE_JPEG_MJPEG_DOWNSCALE_1_2, SCE_JPEG_MJPEG_DOWNSCALE_1_4, SCE_JPEG_MJPEG_DOWNSCALE_1_8, SCE_JPEG_MJPEG_DOWNSCALE_ANY)
|
||||
|
||||
enum SceJpegFormat : int {
|
||||
// YUV format
|
||||
SCE_JPEG_NO_CSC_OUTPUT = -1,
|
||||
@@ -73,11 +78,15 @@ enum SceJpegFormat : int {
|
||||
SCE_JPEG_PIXEL_BGRA8888 = 4
|
||||
};
|
||||
|
||||
BOOST_DESCRIBE_ENUM(SceJpegFormat, SCE_JPEG_NO_CSC_OUTPUT, SCE_JPEG_PIXEL_RGBA8888, SCE_JPEG_PIXEL_BGRA8888)
|
||||
|
||||
enum SceJpegColorConversion : int {
|
||||
SCE_JPEG_COLORSPACE_JFIF = 0,
|
||||
SCE_JPEG_COLORSPACE_BT601 = 0x10
|
||||
};
|
||||
|
||||
BOOST_DESCRIBE_ENUM(SceJpegColorConversion, SCE_JPEG_COLORSPACE_JFIF, SCE_JPEG_COLORSPACE_BT601);
|
||||
|
||||
struct SceJpegOutputInfo {
|
||||
SceJpegColorSpace color_space;
|
||||
uint16_t width;
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
|
||||
|
||||
#include <boost/core/demangle.hpp>
|
||||
#include <boost/describe/enum.hpp>
|
||||
#include <boost/describe/enum_to_string.hpp>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <util/exit_code.h>
|
||||
#include <util/fs.h>
|
||||
@@ -119,4 +122,20 @@ public:
|
||||
basic_string_view<Char>(log_hex_full(p.address())));
|
||||
}
|
||||
};
|
||||
template <typename T, typename Char>
|
||||
requires(boost::describe::has_describe_enumerators<T>::value)
|
||||
struct formatter<T, Char> : formatter<string_view, Char> {
|
||||
public:
|
||||
template <typename FormatContext>
|
||||
auto format(const T e, FormatContext &ctx) const {
|
||||
auto name = boost::describe::enum_to_string(e, "");
|
||||
if (name && *name != '\0') {
|
||||
return detail::write(ctx.out(), name);
|
||||
} else {
|
||||
auto enum_as_uint = static_cast<std::make_unsigned_t<T>>(e);
|
||||
auto enum_as_string = fmt::format("{}(0x{:0{}X})", boost::core::demangle(typeid(T).name()), enum_as_uint, sizeof(enum_as_uint) * 2);
|
||||
return detail::write(ctx.out(), basic_string_view<Char>(enum_as_string));
|
||||
}
|
||||
}
|
||||
};
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <util/log.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
|
||||
// universal to string converters for module specific types (usually enums)
|
||||
template <typename T>
|
||||
@@ -67,6 +68,12 @@ inline std::string to_debug_str<std::string>(const MemState &mem, std::string ty
|
||||
return type;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires(boost::describe::has_describe_enumerators<T>::value)
|
||||
inline std::string to_debug_str(const MemState &mem, T type) {
|
||||
return fmt::format("{}", type);
|
||||
}
|
||||
|
||||
inline std::string to_debug_str(const MemState &mem) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user