diff options
| author | 2022-05-02 03:15:10 -0400 | |
|---|---|---|
| committer | 2022-05-02 18:17:39 -0400 | |
| commit | 08bddd7d79f76573fad12a35a35cafcb86c2c1b0 (patch) | |
| tree | 7b44567a381b361d7dc50a18ec6e3f861900ea12 /src | |
| parent | Merge pull request #8293 from Docteh/translate_network (diff) | |
| download | yuzu-08bddd7d79f76573fad12a35a35cafcb86c2c1b0.tar.gz yuzu-08bddd7d79f76573fad12a35a35cafcb86c2c1b0.tar.xz yuzu-08bddd7d79f76573fad12a35a35cafcb86c2c1b0.zip | |
hle/result: Implement ResultRange
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.
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); | |||
| 154 | constexpr ResultCode ResultUnknown(UINT32_MAX); | 154 | constexpr ResultCode ResultUnknown(UINT32_MAX); |
| 155 | 155 | ||
| 156 | /** | 156 | /** |
| 157 | * A ResultRange defines an inclusive range of error descriptions within an error module. | ||
| 158 | * This can be used to check whether the description of a given ResultCode falls within the range. | ||
| 159 | * The conversion function returns a ResultCode with its description set to description_start. | ||
| 160 | * | ||
| 161 | * An example of how it could be used: | ||
| 162 | * \code | ||
| 163 | * constexpr ResultRange ResultCommonError{ErrorModule::Common, 0, 9999}; | ||
| 164 | * | ||
| 165 | * ResultCode Example(int value) { | ||
| 166 | * const ResultCode result = OtherExample(value); | ||
| 167 | * | ||
| 168 | * // This will only evaluate to true if result.module is ErrorModule::Common and | ||
| 169 | * // result.description is in between 0 and 9999 inclusive. | ||
| 170 | * if (ResultCommonError.Includes(result)) { | ||
| 171 | * // This returns ResultCode{ErrorModule::Common, 0}; | ||
| 172 | * return ResultCommonError; | ||
| 173 | * } | ||
| 174 | * | ||
| 175 | * return ResultSuccess; | ||
| 176 | * } | ||
| 177 | * \endcode | ||
| 178 | */ | ||
| 179 | class ResultRange { | ||
| 180 | public: | ||
| 181 | consteval ResultRange(ErrorModule module, u32 description_start, u32 description_end_) | ||
| 182 | : code{module, description_start}, description_end{description_end_} {} | ||
| 183 | |||
| 184 | [[nodiscard]] consteval operator ResultCode() const { | ||
| 185 | return code; | ||
| 186 | } | ||
| 187 | |||
| 188 | [[nodiscard]] constexpr bool Includes(ResultCode other) const { | ||
| 189 | return code.module == other.module && code.description <= other.description && | ||
| 190 | other.description <= description_end; | ||
| 191 | } | ||
| 192 | |||
| 193 | private: | ||
| 194 | ResultCode code; | ||
| 195 | u32 description_end; | ||
| 196 | }; | ||
| 197 | |||
| 198 | /** | ||
| 157 | * This is an optional value type. It holds a `ResultCode` and, if that code is ResultSuccess, it | 199 | * This is an optional value type. It holds a `ResultCode` and, if that code is ResultSuccess, it |
| 158 | * also holds a result of type `T`. If the code is an error code (not ResultSuccess), then trying | 200 | * also holds a result of type `T`. If the code is an error code (not ResultSuccess), then trying |
| 159 | * to access the inner value with operator* is undefined behavior and will assert with Unwrap(). | 201 | * to access the inner value with operator* is undefined behavior and will assert with Unwrap(). |