diff options
author | Morph <39850852+Morph1984@users.noreply.github.com> | 2022-05-02 09:15:10 +0200 |
---|---|---|
committer | Morph <39850852+Morph1984@users.noreply.github.com> | 2022-05-03 00:17:39 +0200 |
commit | 08bddd7d79f76573fad12a35a35cafcb86c2c1b0 (patch) | |
tree | 7b44567a381b361d7dc50a18ec6e3f861900ea12 /src | |
parent | Merge pull request #8293 from Docteh/translate_network (diff) | |
download | yuzu-08bddd7d79f76573fad12a35a35cafcb86c2c1b0.tar yuzu-08bddd7d79f76573fad12a35a35cafcb86c2c1b0.tar.gz yuzu-08bddd7d79f76573fad12a35a35cafcb86c2c1b0.tar.bz2 yuzu-08bddd7d79f76573fad12a35a35cafcb86c2c1b0.tar.lz yuzu-08bddd7d79f76573fad12a35a35cafcb86c2c1b0.tar.xz yuzu-08bddd7d79f76573fad12a35a35cafcb86c2c1b0.tar.zst yuzu-08bddd7d79f76573fad12a35a35cafcb86c2c1b0.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/core/hle/result.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/core/hle/result.h b/src/core/hle/result.h index 3807b9aa8..8d38d0030 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h @@ -154,6 +154,48 @@ constexpr ResultCode ResultSuccess(0); constexpr ResultCode ResultUnknown(UINT32_MAX); /** + * A ResultRange defines an inclusive range of error descriptions within an error module. + * This can be used to check whether the description of a given ResultCode falls within the range. + * The conversion function returns a ResultCode with its description set to description_start. + * + * An example of how it could be used: + * \code + * constexpr ResultRange ResultCommonError{ErrorModule::Common, 0, 9999}; + * + * ResultCode Example(int value) { + * const ResultCode result = OtherExample(value); + * + * // This will only evaluate to true if result.module is ErrorModule::Common and + * // result.description is in between 0 and 9999 inclusive. + * if (ResultCommonError.Includes(result)) { + * // This returns ResultCode{ErrorModule::Common, 0}; + * return ResultCommonError; + * } + * + * return ResultSuccess; + * } + * \endcode + */ +class ResultRange { +public: + consteval ResultRange(ErrorModule module, u32 description_start, u32 description_end_) + : code{module, description_start}, description_end{description_end_} {} + + [[nodiscard]] consteval operator ResultCode() const { + return code; + } + + [[nodiscard]] constexpr bool Includes(ResultCode other) const { + return code.module == other.module && code.description <= other.description && + other.description <= description_end; + } + +private: + ResultCode code; + u32 description_end; +}; + +/** * This is an optional value type. It holds a `ResultCode` and, if that code is ResultSuccess, it * also holds a result of type `T`. If the code is an error code (not ResultSuccess), then trying * to access the inner value with operator* is undefined behavior and will assert with Unwrap(). |