mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-04 23:35:12 +01:00
Add a ResultValue helper class to simplify result handling
This is a very common usecase for result handling and allows much cleaner code.
This commit is contained in:
parent
e90dd672af
commit
def9f96b02
@ -71,15 +71,53 @@ namespace skyline {
|
||||
/**
|
||||
* @note Success is 0, it's the only result that's not specific to a module
|
||||
*/
|
||||
Result() = default;
|
||||
constexpr Result() = default;
|
||||
|
||||
constexpr Result(u16 module, u16 id) : module(module), id(id) {}
|
||||
constexpr explicit Result(u16 module, u16 id) : module(module), id(id) {}
|
||||
|
||||
constexpr operator u32() const {
|
||||
return raw;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A wrapper around std::optional that also stores a HOS result code
|
||||
* @tparam T The object type to hold
|
||||
*/
|
||||
template<typename T>
|
||||
class ResultValue {
|
||||
static_assert(!std::is_same<T, Result>::value);
|
||||
|
||||
private:
|
||||
std::optional<T> value;
|
||||
|
||||
public:
|
||||
Result result;
|
||||
|
||||
constexpr ResultValue(T value) : value(value) {};
|
||||
|
||||
constexpr ResultValue(Result result) : result(result) {};
|
||||
|
||||
template<typename G>
|
||||
constexpr ResultValue(ResultValue<G> result) : result(result) {};
|
||||
|
||||
constexpr operator Result() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
explicit constexpr operator bool() const {
|
||||
return value.has_value();
|
||||
}
|
||||
|
||||
constexpr T& operator*() {
|
||||
return *value;
|
||||
}
|
||||
|
||||
constexpr T* operator->() {
|
||||
return &*value;
|
||||
}
|
||||
};
|
||||
|
||||
namespace constant {
|
||||
// Display
|
||||
constexpr u16 HandheldResolutionW{1280}; //!< The width component of the handheld resolution
|
||||
|
Loading…
Reference in New Issue
Block a user