[ox/std] Replace ox::_error with ox::Error constructor
This commit is contained in:
parent
fe40b2e144
commit
b6c82c42f0
47
deps/ox/src/ox/std/error.hpp
vendored
47
deps/ox/src/ox/std/error.hpp
vendored
@ -13,7 +13,7 @@
|
|||||||
#include "typetraits.hpp"
|
#include "typetraits.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
#define OxError(...) ox::_error(__FILE__, __LINE__, __VA_ARGS__)
|
#define OxError(...) ox::Error(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
|
||||||
namespace ox {
|
namespace ox {
|
||||||
|
|
||||||
@ -21,41 +21,38 @@ struct [[nodiscard]] Error {
|
|||||||
const char *msg = nullptr;
|
const char *msg = nullptr;
|
||||||
const char *file = "";
|
const char *file = "";
|
||||||
uint16_t line = 0;
|
uint16_t line = 0;
|
||||||
uint64_t m_i = 0;
|
uint64_t errCode = 0;
|
||||||
|
|
||||||
explicit constexpr Error(uint64_t i = 0) {
|
constexpr Error() noexcept = default;
|
||||||
m_i = i;
|
|
||||||
|
explicit constexpr Error(const char *file, uint32_t line, uint64_t errCode, const char *msg = nullptr) noexcept {
|
||||||
|
this->file = file;
|
||||||
|
this->line = line;
|
||||||
|
this->msg = msg;
|
||||||
|
this->errCode = errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error(const Error &o) noexcept {
|
constexpr Error(const Error &o) noexcept {
|
||||||
msg = o.msg;
|
this->msg = o.msg;
|
||||||
file = o.file;
|
this->file = o.file;
|
||||||
line = o.line;
|
this->line = o.line;
|
||||||
m_i = o.m_i;
|
this->errCode = o.errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error &operator=(const Error &o) noexcept {
|
constexpr Error &operator=(const Error &o) noexcept {
|
||||||
msg = o.msg;
|
this->msg = o.msg;
|
||||||
file = o.file;
|
this->file = o.file;
|
||||||
line = o.line;
|
this->line = o.line;
|
||||||
m_i = o.m_i;
|
this->errCode = o.errCode;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr operator uint64_t() const noexcept {
|
constexpr operator uint64_t() const noexcept {
|
||||||
return m_i;
|
return errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr Error _error(const char *file, uint32_t line, uint64_t errCode, const char *msg = nullptr) {
|
|
||||||
auto err = static_cast<Error>(errCode);
|
|
||||||
err.file = file;
|
|
||||||
err.line = line;
|
|
||||||
err.msg = msg;
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct [[nodiscard]] Result {
|
struct [[nodiscard]] Result {
|
||||||
T value;
|
T value;
|
||||||
@ -90,7 +87,7 @@ struct [[nodiscard]] Result {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace error {
|
namespace detail {
|
||||||
|
|
||||||
constexpr Error toError(Error e) noexcept {
|
constexpr Error toError(Error e) noexcept {
|
||||||
return e;
|
return e;
|
||||||
@ -105,7 +102,7 @@ constexpr Error toError(const Result<T> &ve) noexcept {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void oxIgnoreError(ox::Error) {}
|
inline void oxIgnoreError(ox::Error) noexcept {}
|
||||||
#define oxReturnError(x) if (const auto _ox_error = ox::error::toError(x)) return _ox_error
|
#define oxReturnError(x) if (const auto _ox_error = ox::detail::toError(x)) return _ox_error
|
||||||
#define oxThrowError(x) if (const auto _ox_error = ox::error::toError(x)) throw _ox_error
|
#define oxThrowError(x) if (const auto _ox_error = ox::detail::toError(x)) throw _ox_error
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user