[ox] Make Error use a strong int
This commit is contained in:
2
deps/ox/src/ox/std/bitops.hpp
vendored
2
deps/ox/src/ox/std/bitops.hpp
vendored
@@ -20,7 +20,7 @@ template<typename T>
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]] constexpr T onMask(int bits = sizeof(T) << 3 /* *8 */) noexcept {
|
||||
T out = 0;
|
||||
T out = T(0);
|
||||
for (auto i = 0; i < bits; i++) {
|
||||
out |= static_cast<T>(1) << i;
|
||||
}
|
||||
|
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 {
|
||||
|
21
deps/ox/src/ox/std/trace.cpp
vendored
21
deps/ox/src/ox/std/trace.cpp
vendored
@@ -15,6 +15,11 @@
|
||||
|
||||
#include "trace.hpp"
|
||||
|
||||
extern "C"
|
||||
void oxTraceHook([[maybe_unused]] const char *file, [[maybe_unused]] int line,
|
||||
[[maybe_unused]] const char *ch, [[maybe_unused]] const char *msg) {
|
||||
}
|
||||
|
||||
namespace ox::trace {
|
||||
|
||||
#if defined(OX_USE_STDLIB)
|
||||
@@ -23,18 +28,6 @@ static const auto OxPrintTrace = std::getenv("OXTRACE");
|
||||
constexpr auto OxPrintTrace = false;
|
||||
#endif
|
||||
|
||||
namespace gdblogger {
|
||||
|
||||
void captureLogFunc([[maybe_unused]] const char *file, [[maybe_unused]] int line,
|
||||
[[maybe_unused]] const char *ch, [[maybe_unused]] const char *msg) {
|
||||
}
|
||||
|
||||
void logFunc(const char *file, int line, const char *ch, const char *msg) {
|
||||
captureLogFunc(file, line, ch, msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
OutStream::OutStream(const char *file, int line, const char *ch, const char *msg) {
|
||||
m_msg.file = file;
|
||||
m_msg.line = line;
|
||||
@@ -43,7 +36,7 @@ OutStream::OutStream(const char *file, int line, const char *ch, const char *msg
|
||||
}
|
||||
|
||||
OutStream::~OutStream() {
|
||||
gdblogger::logFunc(m_msg.file.c_str(), m_msg.line, m_msg.ch.c_str(), m_msg.msg.c_str());
|
||||
oxTraceHook(m_msg.file.c_str(), m_msg.line, m_msg.ch.c_str(), m_msg.msg.c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +48,7 @@ StdOutStream::StdOutStream(const char *file, int line, const char *ch, const cha
|
||||
}
|
||||
|
||||
StdOutStream::~StdOutStream() {
|
||||
gdblogger::logFunc(m_msg.file.c_str(), m_msg.line, m_msg.ch.c_str(), m_msg.msg.c_str());
|
||||
oxTraceHook(m_msg.file.c_str(), m_msg.line, m_msg.ch.c_str(), m_msg.msg.c_str());
|
||||
#if defined(OX_USE_STDLIB)
|
||||
if (OxPrintTrace) {
|
||||
std::cout << std::setw(53) << std::left << m_msg.ch.c_str() << '|';
|
||||
|
Reference in New Issue
Block a user