Skip to content

Commit

Permalink
Simplify error_code class
Browse files Browse the repository at this point in the history
Remove "not an error" detection trait. Use fixed CellNotAnError class.
Use constructor overload to disable reporting it.
  • Loading branch information
Nekotekina committed May 18, 2021
1 parent cd7253b commit d256378
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions rpcs3/Emu/Cell/ErrorCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,12 @@ class error_code
// 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)
Expand All @@ -55,11 +35,24 @@ class error_code
}
};

enum CellNotAnError : s32
{
CELL_OK = 0,
CELL_CANCEL = 1,
};

// Constructor specialization that doesn't trigger reporting
template <>
constexpr FORCE_INLINE error_code::error_code<CellNotAnError>(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>
Expand All @@ -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
Expand Down

0 comments on commit d256378

Please sign in to comment.