This commit is contained in:
parent
e6777b0ad7
commit
043475ab6d
28
deps/ox/src/ox/std/error.hpp
vendored
28
deps/ox/src/ox/std/error.hpp
vendored
@ -26,6 +26,7 @@ class exception {
|
||||
|
||||
#include "defines.hpp"
|
||||
#include "def.hpp"
|
||||
#include "source_location.hpp"
|
||||
#include "typetraits.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
@ -45,16 +46,35 @@ struct [[nodiscard]] Error {
|
||||
|
||||
constexpr Error() noexcept = default;
|
||||
|
||||
explicit constexpr Error(ErrorCode ec) noexcept: errCode(ec) {
|
||||
}
|
||||
|
||||
explicit constexpr Error(const char *file, uint32_t line, ErrorCode errCode, const char *msg = nullptr) noexcept {
|
||||
explicit constexpr Error(
|
||||
const char *file,
|
||||
uint32_t const line,
|
||||
ErrorCode const errCode,
|
||||
const char *msg = nullptr) noexcept {
|
||||
this->file = file;
|
||||
this->line = static_cast<uint16_t>(line);
|
||||
this->msg = msg;
|
||||
this->errCode = errCode;
|
||||
}
|
||||
|
||||
explicit constexpr Error(
|
||||
ErrorCode const errCode,
|
||||
std::source_location const&src = std::source_location::current()) noexcept {
|
||||
this->file = src.file_name();
|
||||
this->line = static_cast<uint16_t>(src.line());
|
||||
this->errCode = errCode;
|
||||
}
|
||||
|
||||
explicit constexpr Error(
|
||||
ErrorCode const errCode,
|
||||
const char *msg,
|
||||
std::source_location const&src = std::source_location::current()) noexcept {
|
||||
this->file = src.file_name();
|
||||
this->line = static_cast<uint16_t>(src.line());
|
||||
this->msg = msg;
|
||||
this->errCode = errCode;
|
||||
}
|
||||
|
||||
constexpr Error(const Error &o) noexcept {
|
||||
this->msg = o.msg;
|
||||
this->file = o.file;
|
||||
|
60
deps/ox/src/ox/std/source_location.hpp
vendored
Normal file
60
deps/ox/src/ox/std/source_location.hpp
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2015 - 2024 gary@drinkingtea.net
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if __has_include(<source_location>)
|
||||
|
||||
#include <source_location>
|
||||
|
||||
#else
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
namespace std {
|
||||
|
||||
class source_location {
|
||||
private:
|
||||
struct __impl {
|
||||
char const*_M_file_name{};
|
||||
char const*_M_function_name{};
|
||||
uint32_t _M_line{};
|
||||
uint32_t _M_column{};
|
||||
};
|
||||
__impl const*mData = nullptr;
|
||||
using Raw = decltype(__builtin_source_location());
|
||||
|
||||
public:
|
||||
constexpr source_location() noexcept = default;
|
||||
|
||||
static consteval source_location current(Raw const pSl = __builtin_source_location()) noexcept {
|
||||
source_location sl;
|
||||
sl.mData = static_cast<__impl const*>(pSl);
|
||||
return sl;
|
||||
}
|
||||
|
||||
constexpr uint32_t line() const noexcept {
|
||||
return mData != nullptr ? mData->_M_line : 0;
|
||||
}
|
||||
|
||||
constexpr uint32_t column() const noexcept {
|
||||
return mData != nullptr ? mData->_M_column : 0;
|
||||
}
|
||||
|
||||
constexpr ox::CString file_name() const noexcept {
|
||||
return mData != nullptr ? mData->_M_file_name : "";
|
||||
}
|
||||
|
||||
constexpr ox::CString function_name() const noexcept {
|
||||
return mData != nullptr ? mData->_M_function_name : "";
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user