libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_result.hpp
1#ifndef GIMBAL_RESULT_HPP
2#define GIMBAL_RESULT_HPP
3
5#include "../core/gimbal_api_generators.hpp"
6
7namespace gbl {
8
9GBL_ENUM_TABLE_DECLARE_CPP_BEGIN(GBL_META_RESULT_TABLE)
10public:
11 enum class Type: uint8_t {
12 Success,
13 Partial,
14 Error,
15 Unknown,
16 Count
17 };
18
19 constexpr Result(bool success) noexcept: Result(success? GBL_RESULT_SUCCESS : GBL_RESULT_ERROR) {}
20
21 constexpr Type getType(void) const noexcept {
22 if(isSuccess()) return Type::Success;
23 else if(isPartial()) return Type::Partial;
24 else if(isError()) return Type::Error;
25 else if(isUnknown()) return Type::Unknown;
26 else GBL_ASSERT(false, "Not typed!");
27 return Type::Unknown;
28 }
29
30 constexpr bool isUnknown(void) const noexcept { return GBL_RESULT_UNKNOWN(getCode()); }
31 constexpr bool isSuccess(void) const noexcept { return GBL_RESULT_SUCCESS(getCode()); }
32 constexpr bool isPartial(void) const noexcept { return GBL_RESULT_PARTIAL(getCode()); }
33 constexpr bool isError(void) const noexcept { return GBL_RESULT_ERROR(getCode()); }
34 constexpr bool isUnavailable(void) const noexcept { return GBL_RESULT_UNAVAILABLE(getCode()); }
35 constexpr bool isType(Type type) const noexcept { return type == getType(); }
36
37 constexpr operator bool() const noexcept { return isSuccess(); }
38GBL_ENUM_TABLE_DECLARE_CPP_END(GBL_META_RESULT_TABLE)
39
40}
41
42#endif // GIMBAL_RESULT_HPP
#define GBL_ASSERT(...)
#define GBL_RESULT_UNAVAILABLE(value)
#define GBL_RESULT_PARTIAL(value)
#define GBL_RESULT_ERROR(value)
#define GBL_META_RESULT_TABLE
#define GBL_RESULT_SUCCESS(value)
#define GBL_RESULT_UNKNOWN(value)