Simplify error_code class

Remove "not an error" detection trait. Use fixed CellNotAnError class.
Use constructor overload to disable reporting it.
This commit is contained in:
Nekotekina 2021-05-19 00:32:15 +03:00
parent cd7253bac9
commit 8217840acc

View File

@ -14,32 +14,12 @@ public:
// Implementation must be provided independently
static s32 error_report(const fmt_type_info* sup, u64 arg, const fmt_type_info* sup2, u64 arg2);
// Helper type
enum class not_an_error : s32
{
__not_an_error // SFINAE marker
};
// __not_an_error tester
template<typename ET, typename = void>
struct is_error : std::integral_constant<bool, std::is_enum<ET>::value || std::is_integral<ET>::value>
{
};
template<typename ET>
struct is_error<ET, std::enable_if_t<sizeof(ET::__not_an_error) != 0>> : std::false_type
{
};
// Common constructor
template<typename ET>
error_code(const ET& value)
: value(static_cast<s32>(value))
{
if constexpr(is_error<ET>::value)
{
this->value = error_report(fmt::get_type_info<fmt_unveil_t<ET>>(), fmt_unveil<ET>::get(value), nullptr, 0);
}
this->value = error_report(fmt::get_type_info<fmt_unveil_t<ET>>(), fmt_unveil<ET>::get(value), nullptr, 0);
}
// Error constructor (2 args)
@ -55,11 +35,24 @@ public:
}
};
enum CellNotAnError : s32
{
CELL_OK = 0,
CELL_CANCEL = 1,
};
// Constructor specialization that doesn't trigger reporting
template <>
constexpr FORCE_INLINE error_code::error_code(const CellNotAnError& value)
: value(value)
{
}
// Helper function for error_code
template <typename T>
constexpr FORCE_INLINE error_code::not_an_error not_an_error(const T& value)
constexpr FORCE_INLINE CellNotAnError not_an_error(const T& value)
{
return static_cast<error_code::not_an_error>(static_cast<s32>(value));
return static_cast<CellNotAnError>(static_cast<s32>(value));
}
template <typename T, typename>
@ -79,15 +72,6 @@ struct ppu_gpr_cast_impl<error_code, void>
}
};
enum CellNotAnError : s32
{
CELL_OK = 0,
CELL_CANCEL = 1,
__not_an_error
};
enum CellError : u32
{
CELL_EAGAIN = 0x80010001, // The resource is temporarily unavailable