Hubris Engine Dev
A Project to learn and get into Game Engine developement.
 
Loading...
Searching...
No Matches
Error.h
Go to the documentation of this file.
1#pragma once
2#include <type_traits>
3
4namespace Hubris{
5
6 enum class ErrorCode : uint32_t {
7 OK = 0,
10 UNSUPPORTED = 1 << 2,
12 NO_MEMORY = 1 << 4,
13 OUT_OF_RANGE = 1 << 5,
15 NOT_AVAILABLE = 1 << 7,
16 NO_PERMISSION = 1 << 8,
17 FATAL_ERROR = 1 << 9,
18 NON_FATAL_ERROR = 1 << 10,
19 RUNTIME_ERROR = 1 << 11,
21 CORE_ERROR = 1 << 13,
22 INTERNAL_ERROR = 1 << 14,
23 UNKNOWN = 1 << 15,
24 FAILED = 1 << 16
25 };
26
27 // Enable bitwise operators for ErrorCode
28 constexpr ErrorCode operator|(ErrorCode lhs, ErrorCode rhs) {
29 return static_cast<ErrorCode>(
30 static_cast<std::underlying_type<ErrorCode>::type>(lhs) |
31 static_cast<std::underlying_type<ErrorCode>::type>(rhs)
32 );
33 }
34
35 constexpr ErrorCode& operator|=(ErrorCode& lhs, ErrorCode rhs) {
36 lhs = lhs | rhs;
37 return lhs;
38 }
39
40 constexpr ErrorCode operator&(ErrorCode lhs, ErrorCode rhs) {
41 return static_cast<ErrorCode>(
42 static_cast<std::underlying_type<ErrorCode>::type>(lhs) &
43 static_cast<std::underlying_type<ErrorCode>::type>(rhs)
44 );
45 }
46
47 constexpr ErrorCode& operator&=(ErrorCode& lhs, ErrorCode rhs) {
48 lhs = lhs & rhs;
49 return lhs;
50 }
51
52 constexpr bool operator!(ErrorCode e) {
53 return e == ErrorCode::OK;
54 }
55
56 constexpr bool HasError(ErrorCode combined, ErrorCode specific) {
57 return (combined & specific) == specific;
58}
59}
The Hubris Engine main namespace.
Definition EventBus.h:4
constexpr bool operator!(ErrorCode e)
Definition Error.h:52
constexpr ErrorCode operator&(ErrorCode lhs, ErrorCode rhs)
Definition Error.h:40
constexpr ErrorCode & operator|=(ErrorCode &lhs, ErrorCode rhs)
Definition Error.h:35
constexpr ErrorCode & operator&=(ErrorCode &lhs, ErrorCode rhs)
Definition Error.h:47
ErrorCode
Definition Error.h:6
@ INVALID_OPERATION
Definition Error.h:9
constexpr bool HasError(ErrorCode combined, ErrorCode specific)
Definition Error.h:56
constexpr ErrorCode operator|(ErrorCode lhs, ErrorCode rhs)
Definition Error.h:28