diff options
author | Tony Wasserka <neobrainx@gmail.com> | 2015-01-30 15:00:17 +0100 |
---|---|---|
committer | Tony Wasserka <neobrainx@gmail.com> | 2015-01-30 15:00:17 +0100 |
commit | 28702cbfeb1fe21109f8b1efa189785594319b78 (patch) | |
tree | 64e4b1ec43b7699fe1a6ab1be1c688b6d63c0d75 /src/core/hle/result.h | |
parent | Merge pull request #412 from purpasmart96/svc_table_cleanup (diff) | |
parent | Kernel: Mark all appropriate kernel objects as "final" (diff) | |
download | yuzu-28702cbfeb1fe21109f8b1efa189785594319b78.tar yuzu-28702cbfeb1fe21109f8b1efa189785594319b78.tar.gz yuzu-28702cbfeb1fe21109f8b1efa189785594319b78.tar.bz2 yuzu-28702cbfeb1fe21109f8b1efa189785594319b78.tar.lz yuzu-28702cbfeb1fe21109f8b1efa189785594319b78.tar.xz yuzu-28702cbfeb1fe21109f8b1efa189785594319b78.tar.zst yuzu-28702cbfeb1fe21109f8b1efa189785594319b78.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/result.h | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/core/hle/result.h b/src/core/hle/result.h index 82dcf5bba..948b9e38e 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h @@ -9,8 +9,9 @@ #include <type_traits> #include <utility> -#include "common/common_types.h" #include "common/bit_field.h" +#include "common/common_funcs.h" +#include "common/common_types.h" // All the constants in this file come from http://3dbrew.org/wiki/Error_codes @@ -226,11 +227,6 @@ inline ResultCode UnimplementedFunction(ErrorModule module) { return ResultCode(ErrorDescription::NotImplemented, module, ErrorSummary::NotSupported, ErrorLevel::Permanent); } -/// Returned when a function is passed an invalid handle. -inline ResultCode InvalidHandle(ErrorModule module) { - return ResultCode(ErrorDescription::InvalidHandle, module, - ErrorSummary::InvalidArgument, ErrorLevel::Permanent); -} /** * This is an optional value type. It holds a `ResultCode` and, if that code is a success code, @@ -364,6 +360,17 @@ public: return !empty() ? *GetPointer() : std::move(value); } + /// Asserts that the result succeeded and returns a reference to it. + T& Unwrap() { + // TODO(yuriks): Should be a release assert + _assert_msg_(Common, Succeeded(), "Tried to Unwrap empty ResultVal"); + return **this; + } + + T&& MoveFrom() { + return std::move(Unwrap()); + } + private: typedef typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type StorageType; @@ -400,3 +407,15 @@ template <typename T, typename... Args> ResultVal<T> MakeResult(Args&&... args) { return ResultVal<T>::WithCode(RESULT_SUCCESS, std::forward<Args>(args)...); } + +/** + * Check for the success of `source` (which must evaluate to a ResultVal). If it succeeds, unwraps + * the contained value and assigns it to `target`, which can be either an l-value expression or a + * variable declaration. If it fails the return code is returned from the current function. Thus it + * can be used to cascade errors out, achieving something akin to exception handling. + */ +#define CASCADE_RESULT(target, source) \ + auto CONCAT2(check_result_L, __LINE__) = source; \ + if (CONCAT2(check_result_L, __LINE__).Failed()) \ + return CONCAT2(check_result_L, __LINE__).Code(); \ + target = std::move(*CONCAT2(check_result_L, __LINE__)) |