rpcsx/orbis-kernel/include/orbis/error/SysResult.hpp

32 lines
732 B
C++
Raw Normal View History

2023-07-03 13:10:16 +02:00
#pragma once
#include <compare>
2023-07-03 13:10:16 +02:00
namespace orbis {
enum class ErrorCode : int;
class SysResult {
int mValue = 0;
public:
SysResult() = default;
2023-07-06 18:16:25 +02:00
SysResult(ErrorCode ec) : mValue(-static_cast<int>(ec)) {}
2023-07-03 13:10:16 +02:00
[[nodiscard]] static SysResult notAnError(ErrorCode ec) {
SysResult result;
result.mValue = static_cast<int>(ec);
return result;
}
[[nodiscard]] int value() const { return mValue < 0 ? -mValue : mValue; }
[[nodiscard]] bool isError() const { return mValue < 0; }
[[nodiscard]] auto operator<=>(ErrorCode ec) const {
return static_cast<ErrorCode>(value()) <=> ec;
}
[[nodiscard]] auto operator<=>(SysResult other) const {
return value() <=> other.value();
}
2023-07-03 13:10:16 +02:00
};
} // namespace orbis