[ox] Make Error use a strong int
This commit is contained in:
11
deps/ox/src/ox/std/error.hpp
vendored
11
deps/ox/src/ox/std/error.hpp
vendored
@ -8,6 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "strongint.hpp"
|
||||
#include "typetraits.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
@ -21,7 +22,7 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
using Error = uint64_t;
|
||||
using Error = Uint64;
|
||||
|
||||
constexpr Error errCode(Error err) {
|
||||
return (err >> 59) & onMask<Error>(5);
|
||||
@ -30,12 +31,12 @@ constexpr Error errCode(Error err) {
|
||||
struct ErrorInfo {
|
||||
const char *file = nullptr;
|
||||
int line = -1;
|
||||
Error errCode = 0;
|
||||
Error errCode = Error(0);
|
||||
|
||||
ErrorInfo() = default;
|
||||
|
||||
ErrorInfo(Error err) {
|
||||
this->file = reinterpret_cast<const char*>(err & onMask<Error>(48));
|
||||
this->file = reinterpret_cast<const char*>(static_cast<uint64_t>(err & onMask<Error>(48)));
|
||||
this->line = static_cast<int>((err >> 48) & onMask<Error>(11));
|
||||
this->errCode = ox::errCode(err);
|
||||
}
|
||||
@ -50,7 +51,7 @@ static constexpr Error _errorTags(Error line, Error errCode) {
|
||||
}
|
||||
|
||||
static constexpr Error _error(const char *file, uint32_t line, Error errCode) {
|
||||
return errCode ? reinterpret_cast<uint64_t>(file) | _errorTags(line, errCode) : 0;
|
||||
return Error(errCode ? reinterpret_cast<uint64_t>(file) | _errorTags(Error(line), errCode) : 0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@ -60,7 +61,7 @@ struct ValErr {
|
||||
|
||||
inline constexpr ValErr() = default;
|
||||
|
||||
inline constexpr ValErr(T value, Error error = 0): value(ox::move(value)), error(error) {
|
||||
inline constexpr ValErr(T value, Error error = OxError(0)): value(ox::move(value)), error(error) {
|
||||
}
|
||||
|
||||
inline constexpr operator const T&() const {
|
||||
|
Reference in New Issue
Block a user