Squashed 'deps/nostalgia/' changes from 161640fa..a75c4a11
a75c4a11 [nfde] Address CMake warning, remove unwanted logging 347a1657 [sample_project] Update type descriptors fd64bfae [keel] Fix a use after free, cleanup aaeec20a [nostalgia/player] Fix build 37030f9c [keel] Cleanup pack tool 462f2bca [nostalgia,olympic] Change macro names to comply with broader conventions dc72500b [glutils] Change macro names to comply with broader conventions 962fe8bc [ox] Change macro names to comply with broader conventions 305eb626 [studio] Fix build 4754359a [ox/std] Cleanup Vec2 dc07f3d5 [studio] Change FilePicker consturctor to take StringParams fcdcfd10 [ox/std] Run liccor b74f6a7a [studio,turbine] Run liccor ac7e5be1 [ox] Remove OxException ed910c0b [nostalgia/core/studio/tilesheeteditor] Fix access overflow on out of bounds Fill command 345fb038 [ox] Remove OxError 9881253f [glutils] Cleanup OxError 96d27eec [nostalgia,olympic] Cleanup 28ebe93b [ox/std] Make source_location::current only init if valid e849e7a3 [ox/std] Add source_location e6777b0a [cityhash] Add install rule c488c336 [turbine/glfw] Fix mandatoryRefreshPeriodEnd tracking 003f9720 [turbine/glfw] Move MandatoryRefreshPeriod to config.hpp d85a10af [nostalgia/core/studio] Cleanup ff05d860 [turbine/glfw] Replace uninterruptedRefreshes with mandatoryRefreshPeriodEnd 76794037 [turbine] Add init wrapper that takes FS path c51a45e1 [olympic] Cleanup a6e24ff2 [ox/std] Add CString type alias e0ec9e0c [nostalgia,olympic] Move olympic::run to global namespace 9a42a9b9 [nfde] Fix Windows warnings 03a05c51 Merge commit '4ccdfc3a6e5bd501968903a01f7d8141b6f88375' bd91137d [nostalgia,olympic] Fix pack tool build for Windows 2b7d1294 [nostalgia/core/studio] Fix MSVC build git-subtree-dir: deps/nostalgia git-subtree-split: a75c4a11d3c555f4d3bed1ea1f70bb29fe49e99c
This commit is contained in:
4
deps/ox/src/ox/std/assert.hpp
vendored
4
deps/ox/src/ox/std/assert.hpp
vendored
@@ -22,9 +22,9 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
void panic(StringViewCR file, int line, StringViewCR panicMsg, const Error &err = OxError(0)) noexcept;
|
||||
void panic(StringViewCR file, int line, StringViewCR panicMsg, const Error &err = ox::Error(0)) noexcept;
|
||||
|
||||
constexpr void constexprPanic(StringViewCR file, int line, StringViewCR panicMsg, const Error &err = OxError(0)) noexcept {
|
||||
constexpr void constexprPanic(StringViewCR file, int line, StringViewCR panicMsg, const Error &err = ox::Error(0)) noexcept {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
panic(file, line, panicMsg, err);
|
||||
} else {
|
||||
|
10
deps/ox/src/ox/std/bounds.hpp
vendored
10
deps/ox/src/ox/std/bounds.hpp
vendored
@@ -126,11 +126,11 @@ constexpr void Bounds::set(const Point &pt1, const Point &pt2) noexcept {
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *io, ox::CommonPtrWith<Bounds> auto *obj) noexcept {
|
||||
oxReturnError(io->template setTypeInfo<Bounds>());
|
||||
oxReturnError(io->field("x", &obj->x));
|
||||
oxReturnError(io->field("y", &obj->y));
|
||||
oxReturnError(io->field("width", &obj->width));
|
||||
oxReturnError(io->field("height", &obj->height));
|
||||
OX_RETURN_ERROR(io->template setTypeInfo<Bounds>());
|
||||
OX_RETURN_ERROR(io->field("x", &obj->x));
|
||||
OX_RETURN_ERROR(io->field("y", &obj->y));
|
||||
OX_RETURN_ERROR(io->field("width", &obj->width));
|
||||
OX_RETURN_ERROR(io->field("height", &obj->height));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
18
deps/ox/src/ox/std/buffer.hpp
vendored
18
deps/ox/src/ox/std/buffer.hpp
vendored
@@ -53,7 +53,7 @@ class BufferWriter {
|
||||
base = static_cast<ox::Signed<std::size_t>>(m_it);
|
||||
break;
|
||||
default:
|
||||
return OxError(1, "Invalid seekdir");
|
||||
return ox::Error(1, "Invalid seekdir");
|
||||
}
|
||||
m_it = static_cast<std::size_t>(base + off);
|
||||
return {};
|
||||
@@ -125,7 +125,7 @@ class CharBuffWriter {
|
||||
base = static_cast<ox::Signed<std::size_t>>(m_it);
|
||||
break;
|
||||
default:
|
||||
return OxError(1, "Invalid seekdir");
|
||||
return ox::Error(1, "Invalid seekdir");
|
||||
}
|
||||
m_it = static_cast<std::size_t>(base + off);
|
||||
return {};
|
||||
@@ -138,7 +138,7 @@ class CharBuffWriter {
|
||||
|
||||
constexpr ox::Error put(char val) noexcept {
|
||||
if (m_it >= m_cap) [[unlikely]] {
|
||||
return OxError(1, "Buffer overrun");
|
||||
return ox::Error(1, "Buffer overrun");
|
||||
}
|
||||
m_buff[m_it] = val;
|
||||
++m_it;
|
||||
@@ -149,7 +149,7 @@ class CharBuffWriter {
|
||||
constexpr ox::Error write(const char *buff, std::size_t cnt) noexcept {
|
||||
const auto end = m_it + cnt;
|
||||
if (end > m_cap) [[unlikely]] {
|
||||
return OxError(1, "Buffer overrun");
|
||||
return ox::Error(1, "Buffer overrun");
|
||||
}
|
||||
if (buff) {
|
||||
for (auto i = 0u; i < cnt; ++i) {
|
||||
@@ -179,7 +179,7 @@ class BufferReader {
|
||||
|
||||
constexpr ox::Result<char> peek() const noexcept {
|
||||
if (m_it >= m_size) [[unlikely]] {
|
||||
return OxError(1, "Peek failed: buffer overrun");
|
||||
return ox::Error(1, "Peek failed: buffer overrun");
|
||||
}
|
||||
return m_buff[m_it];
|
||||
}
|
||||
@@ -187,7 +187,7 @@ class BufferReader {
|
||||
constexpr ox::Result<std::size_t> read(void *v, std::size_t sz) noexcept {
|
||||
sz = ox::min(sz, m_size - m_it);
|
||||
if (m_it + sz > m_size) [[unlikely]] {
|
||||
return OxError(1, "Read failed: Buffer overrun");
|
||||
return ox::Error(1, "Read failed: Buffer overrun");
|
||||
}
|
||||
ox::memcpy(v, &m_buff[m_it], sz);
|
||||
m_it += sz;
|
||||
@@ -196,7 +196,7 @@ class BufferReader {
|
||||
|
||||
constexpr ox::Error seekg(std::size_t p) noexcept {
|
||||
if (p > m_size) [[unlikely]] {
|
||||
return OxError(1, "Seek failed: Buffer overrun");
|
||||
return ox::Error(1, "Seek failed: Buffer overrun");
|
||||
}
|
||||
m_it = p;
|
||||
return {};
|
||||
@@ -215,11 +215,11 @@ class BufferReader {
|
||||
base = static_cast<ox::Signed<std::size_t>>(m_it);
|
||||
break;
|
||||
default:
|
||||
return OxError(1, "Invalid seekdir");
|
||||
return ox::Error(1, "Invalid seekdir");
|
||||
}
|
||||
auto const newIt = static_cast<std::size_t>(base + off);
|
||||
if (newIt > m_size) [[unlikely]] {
|
||||
return OxError(1, "Seek failed: Buffer overrun");
|
||||
return ox::Error(1, "Seek failed: Buffer overrun");
|
||||
}
|
||||
m_it = newIt;
|
||||
return {};
|
||||
|
12
deps/ox/src/ox/std/def.hpp
vendored
12
deps/ox/src/ox/std/def.hpp
vendored
@@ -37,13 +37,13 @@
|
||||
|
||||
// Error handling
|
||||
|
||||
#define oxReturnError(x) { if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] return _ox_error; } (void) 0
|
||||
#define oxThrowError(x) { if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] throw ox::Exception(_ox_error); } (void) 0
|
||||
#define oxConcatImpl(a, b) a##b
|
||||
#define oxConcat(a, b) oxConcatImpl(a, b)
|
||||
#define OX_RETURN_ERROR(x) { if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] return _ox_error; } (void) 0
|
||||
#define OX_THROW_ERROR(x) { if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] throw ox::Exception(_ox_error); } (void) 0
|
||||
#define OX_CONCAT_IMPL(a, b) a##b
|
||||
#define OX_CONCAT(a, b) OX_CONCAT_IMPL(a, b)
|
||||
// oxRequire Mutable
|
||||
#define oxRequireM(out, x) auto [out, oxConcat(oxRequire_err_, __LINE__)] = x; oxReturnError(oxConcat(oxRequire_err_, __LINE__))
|
||||
#define oxRequire(out, x) const oxRequireM(out, x)
|
||||
#define OX_REQUIRE_M(out, x) auto [out, OX_CONCAT(oxRequire_err_, __LINE__)] = x; OX_RETURN_ERROR(OX_CONCAT(oxRequire_err_, __LINE__))
|
||||
#define OX_REQUIRE(out, x) const OX_REQUIRE_M(out, x)
|
||||
|
||||
|
||||
// Asserts
|
||||
|
2
deps/ox/src/ox/std/defer.hpp
vendored
2
deps/ox/src/ox/std/defer.hpp
vendored
@@ -31,4 +31,4 @@ class Defer {
|
||||
|
||||
}
|
||||
|
||||
#define oxDefer ox::Defer const oxConcat(oxDefer_, __LINE__) =
|
||||
#define OX_DEFER ox::Defer const OX_CONCAT(oxDefer_, __LINE__) =
|
||||
|
124
deps/ox/src/ox/std/error.hpp
vendored
124
deps/ox/src/ox/std/error.hpp
vendored
@@ -17,7 +17,7 @@ class exception {
|
||||
virtual ~exception() = default;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual const char *what() const noexcept {
|
||||
virtual char const*what() const noexcept {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
@@ -26,49 +26,50 @@ class exception {
|
||||
|
||||
#include "defines.hpp"
|
||||
#include "def.hpp"
|
||||
#include "source_location.hpp"
|
||||
#include "typetraits.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#define OxError(...) ox::Error(__FILE__, __LINE__, __VA_ARGS__)
|
||||
#define OxException(...) ox::Exception(__FILE__, __LINE__, __VA_ARGS__)
|
||||
|
||||
namespace ox {
|
||||
|
||||
using ErrorCode = uint16_t;
|
||||
|
||||
|
||||
struct [[nodiscard]] Error {
|
||||
const char *msg = nullptr;
|
||||
const char *file = nullptr;
|
||||
ox::CString msg = nullptr;
|
||||
ox::CString file = nullptr;
|
||||
uint16_t line = 0;
|
||||
ErrorCode errCode = 0;
|
||||
|
||||
constexpr Error() noexcept = default;
|
||||
|
||||
explicit constexpr Error(ErrorCode ec) noexcept: errCode(ec) {
|
||||
}
|
||||
explicit constexpr Error(
|
||||
ox::CString file,
|
||||
uint32_t const line,
|
||||
ErrorCode const errCode,
|
||||
ox::CString msg = nullptr) noexcept:
|
||||
msg{msg},
|
||||
file{file},
|
||||
line{static_cast<uint16_t>(line)},
|
||||
errCode{errCode} {}
|
||||
|
||||
explicit constexpr Error(const char *file, uint32_t line, ErrorCode 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:
|
||||
file{src.file_name()},
|
||||
line{static_cast<uint16_t>(src.line())},
|
||||
errCode{errCode}
|
||||
{}
|
||||
|
||||
constexpr Error(const Error &o) noexcept {
|
||||
this->msg = o.msg;
|
||||
this->file = o.file;
|
||||
this->line = o.line;
|
||||
this->errCode = o.errCode;
|
||||
}
|
||||
|
||||
constexpr Error &operator=(const Error &o) noexcept {
|
||||
this->msg = o.msg;
|
||||
this->file = o.file;
|
||||
this->line = o.line;
|
||||
this->errCode = o.errCode;
|
||||
return *this;
|
||||
}
|
||||
explicit constexpr Error(
|
||||
ErrorCode const errCode,
|
||||
ox::CString msg,
|
||||
std::source_location const&src = std::source_location::current()) noexcept:
|
||||
msg{msg},
|
||||
file{src.file_name()},
|
||||
line{static_cast<uint16_t>(src.line())},
|
||||
errCode{errCode}
|
||||
{}
|
||||
|
||||
constexpr operator uint64_t() const noexcept {
|
||||
return errCode;
|
||||
@@ -77,51 +78,62 @@ struct [[nodiscard]] Error {
|
||||
};
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto errCode(const Error &err) noexcept {
|
||||
constexpr auto errCode(Error const&err) noexcept {
|
||||
return err.errCode;
|
||||
}
|
||||
|
||||
template<typename T=const char*>
|
||||
template<typename T = char const*>
|
||||
[[nodiscard]]
|
||||
constexpr auto toStr(const Error &err) noexcept {
|
||||
return err.msg ? T(err.msg) : "";
|
||||
constexpr auto toStr(Error const&err) noexcept {
|
||||
return err.msg ? T{err.msg} : "";
|
||||
}
|
||||
|
||||
struct Exception: public std::exception {
|
||||
const char *msg = nullptr;
|
||||
const char *file = nullptr;
|
||||
ox::CString msg = nullptr;
|
||||
ox::CString file = nullptr;
|
||||
uint16_t line = 0;
|
||||
ErrorCode errCode = 0;
|
||||
|
||||
explicit inline Exception(const char *file, uint32_t line, ErrorCode errCode, const char *msg = "") noexcept {
|
||||
explicit inline Exception(ox::CString file, uint32_t line, ErrorCode errCode, char const*msg = "") noexcept {
|
||||
this->file = file;
|
||||
this->line = static_cast<uint16_t>(line);
|
||||
this->msg = msg;
|
||||
this->errCode = errCode;
|
||||
}
|
||||
|
||||
explicit inline Exception(const Error &err) {
|
||||
if (err.msg) {
|
||||
this->msg = err.msg;
|
||||
} else {
|
||||
this->msg = "";
|
||||
}
|
||||
this->file = err.file;
|
||||
this->line = err.line;
|
||||
this->errCode = err.errCode;
|
||||
}
|
||||
explicit inline Exception(
|
||||
ErrorCode const errCode,
|
||||
std::source_location const&src = std::source_location::current()) noexcept:
|
||||
file{src.file_name()},
|
||||
line{static_cast<uint16_t>(src.line())},
|
||||
errCode{errCode} {}
|
||||
|
||||
explicit inline Exception(
|
||||
ErrorCode const errCode,
|
||||
ox::CString msg,
|
||||
std::source_location const&src = std::source_location::current()) noexcept:
|
||||
msg{msg},
|
||||
file{src.file_name()},
|
||||
line{static_cast<uint16_t>(src.line())},
|
||||
errCode{errCode} {}
|
||||
|
||||
explicit inline Exception(Error const&err) noexcept:
|
||||
msg{err.msg ? err.msg : ""},
|
||||
file{err.file},
|
||||
line{err.line},
|
||||
errCode{err.errCode} {}
|
||||
|
||||
constexpr Error toError() const noexcept {
|
||||
return Error(file, line, errCode, msg);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
const char *what() const noexcept override {
|
||||
char const*what() const noexcept override {
|
||||
return msg;
|
||||
}
|
||||
};
|
||||
|
||||
void panic(const char *file, int line, const char *panicMsg, const Error &err) noexcept;
|
||||
void panic(char const*file, int line, char const*panicMsg, Error const&err) noexcept;
|
||||
|
||||
template<typename T>
|
||||
struct [[nodiscard]] Result {
|
||||
@@ -135,25 +147,25 @@ struct [[nodiscard]] Result {
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
constexpr Result(const Result<U> &other) noexcept: value(other.value), error(other.error) {
|
||||
constexpr Result(Result<U> const&other) noexcept: value(other.value), error(other.error) {
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
constexpr Result(Result<U> &&other) noexcept: value(std::move(other.value)), error(std::move(other.error)) {
|
||||
}
|
||||
|
||||
constexpr Result(const Error &error) noexcept: value(), error(error) {
|
||||
constexpr Result(Error const&error) noexcept: value(), error(error) {
|
||||
}
|
||||
|
||||
constexpr Result(const type &value, const Error &error = OxError(0)) noexcept: value(value), error(error) {
|
||||
constexpr Result(type const&value, Error const&error = {}) noexcept: value(value), error(error) {
|
||||
}
|
||||
|
||||
constexpr Result(type &&value, const Error &error = OxError(0)) noexcept: value(std::move(value)), error(error) {
|
||||
constexpr Result(type &&value, Error const&error = {}) noexcept: value(std::move(value)), error(error) {
|
||||
}
|
||||
|
||||
constexpr ~Result() noexcept = default;
|
||||
|
||||
explicit constexpr operator const type&() const noexcept {
|
||||
explicit constexpr operator type const&() const noexcept {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -322,21 +334,21 @@ struct [[nodiscard]] Result {
|
||||
|
||||
namespace detail {
|
||||
|
||||
constexpr Error toError(const Error &e) noexcept {
|
||||
constexpr Error toError(Error const&e) noexcept {
|
||||
return e;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr Error toError(const Result<T> &r) noexcept {
|
||||
constexpr Error toError(Result<T> const&r) noexcept {
|
||||
return r.error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
constexpr void primitiveAssert(const char *file, int line, bool pass, const char *msg) noexcept {
|
||||
constexpr void primitiveAssert(char const*file, int line, bool pass, char const*msg) noexcept {
|
||||
if constexpr(ox::defines::Debug) {
|
||||
if (!pass) [[unlikely]] {
|
||||
panic(file, line, msg, OxError(1));
|
||||
panic(file, line, msg, ox::Error(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
4
deps/ox/src/ox/std/hashmap.hpp
vendored
4
deps/ox/src/ox/std/hashmap.hpp
vendored
@@ -154,7 +154,7 @@ template<typename K, typename T>
|
||||
constexpr Result<T*> HashMap<K, T>::at(MaybeView_t<K> const&k) noexcept {
|
||||
auto p = access(m_pairs, k);
|
||||
if (!p) {
|
||||
return {nullptr, OxError(1, "value not found for given key")};
|
||||
return {nullptr, ox::Error(1, "value not found for given key")};
|
||||
}
|
||||
return &p->value;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ template<typename K, typename T>
|
||||
constexpr Result<const T*> HashMap<K, T>::at(MaybeView_t<K> const&k) const noexcept {
|
||||
auto p = access(m_pairs, k);
|
||||
if (!p) {
|
||||
return {nullptr, OxError(1, "value not found for given key")};
|
||||
return {nullptr, ox::Error(1, "value not found for given key")};
|
||||
}
|
||||
return &p->value;
|
||||
}
|
||||
|
4
deps/ox/src/ox/std/heapmgr.cpp
vendored
4
deps/ox/src/ox/std/heapmgr.cpp
vendored
@@ -77,7 +77,7 @@ static HeapSegment *findSegmentFor(std::size_t sz) noexcept {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
oxPanic(OxError(1), "malloc: could not find segment");
|
||||
oxPanic(ox::Error(1), "malloc: could not find segment");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ void free(void *ptr) noexcept {
|
||||
} else if (p.segment) {
|
||||
p.segment->inUse = false;
|
||||
} else {
|
||||
oxPanic(OxError(1), "Bad heap free");
|
||||
oxPanic(ox::Error(1), "Bad heap free");
|
||||
}
|
||||
}
|
||||
|
||||
|
6
deps/ox/src/ox/std/istring.hpp
vendored
6
deps/ox/src/ox/std/istring.hpp
vendored
@@ -174,7 +174,7 @@ constexpr Error IString<StrCap>::append(const char *str, std::size_t strLen) noe
|
||||
auto const currentLen = len();
|
||||
if (cap() < currentLen + strLen) {
|
||||
strLen = cap() - currentLen;
|
||||
err = OxError(1, "Insufficient space for full string");
|
||||
err = ox::Error(1, "Insufficient space for full string");
|
||||
}
|
||||
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||
ox::strncpy(m_buff.data() + currentLen, str, strLen);
|
||||
@@ -219,7 +219,7 @@ constexpr std::size_t IString<StrCap>::bytes() const noexcept {
|
||||
template<std::size_t StrCap>
|
||||
constexpr ox::Error IString<StrCap>::resize(size_t sz) noexcept {
|
||||
if (sz > StrCap) [[unlikely]] {
|
||||
return OxError(1, "Trying to extend IString beyond its cap");
|
||||
return ox::Error(1, "Trying to extend IString beyond its cap");
|
||||
}
|
||||
for (auto i = m_size; i < sz; ++i) {
|
||||
m_buff[i] = 0;
|
||||
@@ -231,7 +231,7 @@ constexpr ox::Error IString<StrCap>::resize(size_t sz) noexcept {
|
||||
template<std::size_t StrCap>
|
||||
constexpr ox::Error IString<StrCap>::unsafeResize(size_t sz) noexcept {
|
||||
if (sz > StrCap) [[unlikely]] {
|
||||
return OxError(1, "Trying to extend IString beyond its cap");
|
||||
return ox::Error(1, "Trying to extend IString beyond its cap");
|
||||
}
|
||||
m_size = sz;
|
||||
return {};
|
||||
|
6
deps/ox/src/ox/std/new.hpp
vendored
6
deps/ox/src/ox/std/new.hpp
vendored
@@ -42,10 +42,10 @@ constexpr U *make(Args &&...args) noexcept {
|
||||
try {
|
||||
return new T(ox::forward<Args>(args)...);
|
||||
} catch (std::exception const&ex) {
|
||||
oxPanic(OxError(1, ex.what()), ex.what());
|
||||
oxPanic(ox::Error(1, ex.what()), ex.what());
|
||||
return nullptr;
|
||||
} catch (...) {
|
||||
oxPanic(OxError(2, "Allocation or constructor failed"), "Allocation or constructor failed");
|
||||
oxPanic(ox::Error(2, "Allocation or constructor failed"), "Allocation or constructor failed");
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
@@ -62,7 +62,7 @@ constexpr Result<T*> makeCatch(Args &&...args) noexcept {
|
||||
} catch (const ox::Exception &ex) {
|
||||
return ex.toError();
|
||||
} catch (...) {
|
||||
return OxError(1, "Allocation or constructor failed");
|
||||
return ox::Error(1, "Allocation or constructor failed");
|
||||
}
|
||||
#else
|
||||
return new T(ox::forward<Args>(args)...);
|
||||
|
6
deps/ox/src/ox/std/point.hpp
vendored
6
deps/ox/src/ox/std/point.hpp
vendored
@@ -189,9 +189,9 @@ constexpr bool Point::operator!=(const Point &p) const noexcept {
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *io, ox::CommonPtrWith<Point> auto *obj) noexcept {
|
||||
oxReturnError(io->template setTypeInfo<Point>());
|
||||
oxReturnError(io->field("x", &obj->x));
|
||||
oxReturnError(io->field("y", &obj->y));
|
||||
OX_RETURN_ERROR(io->template setTypeInfo<Point>());
|
||||
OX_RETURN_ERROR(io->field("x", &obj->x));
|
||||
OX_RETURN_ERROR(io->field("y", &obj->y));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
12
deps/ox/src/ox/std/reader.cpp
vendored
12
deps/ox/src/ox/std/reader.cpp
vendored
@@ -34,11 +34,11 @@ ox::Result<char> StreamReader::peek() const noexcept {
|
||||
m_strm.get(c);
|
||||
auto const ok = c != EOF;
|
||||
if (ok && m_strm.unget()) [[unlikely]] {
|
||||
return OxError(1, "Unable to unget character");
|
||||
return ox::Error(1, "Unable to unget character");
|
||||
}
|
||||
return {static_cast<char>(c), OxError(!ok, "File peek failed")};
|
||||
return {static_cast<char>(c), ox::Error(!ok, "File peek failed")};
|
||||
} catch (std::exception const&) {
|
||||
return OxError(1, "peek failed");
|
||||
return ox::Error(1, "peek failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ ox::Error StreamReader::seekg(std::size_t p) noexcept {
|
||||
try {
|
||||
m_strm.seekg(static_cast<long long int>(p), std::ios_base::cur);
|
||||
} catch (std::exception const&) {
|
||||
return OxError(1, "seekg failed");
|
||||
return ox::Error(1, "seekg failed");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -59,14 +59,14 @@ ox::Error StreamReader::seekg(int64_t p, ios_base::seekdir sd) noexcept {
|
||||
try {
|
||||
m_strm.seekg(p, sdMap(sd));
|
||||
} catch (std::exception const&) {
|
||||
return OxError(1, "seekg failed");
|
||||
return ox::Error(1, "seekg failed");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Result<std::size_t> StreamReader::tellg() noexcept {
|
||||
const auto sz = m_strm.tellg();
|
||||
return {static_cast<std::size_t>(sz), OxError(sz == -1)};
|
||||
return {static_cast<std::size_t>(sz), ox::Error(sz == -1)};
|
||||
}
|
||||
|
||||
}
|
||||
|
10
deps/ox/src/ox/std/serialize.hpp
vendored
10
deps/ox/src/ox/std/serialize.hpp
vendored
@@ -63,10 +63,10 @@ constexpr ox::Error pad(Writer_c auto &w, const T *v) noexcept {
|
||||
|
||||
template<typename PlatSpec>
|
||||
constexpr ox::Error serialize(Writer_c auto &w, const VectorMemMap<PlatSpec> &vm) noexcept {
|
||||
oxReturnError(w.write(nullptr, vm.smallVecSize));
|
||||
oxReturnError(serialize(w, PlatSpec::correctEndianness(vm.size)));
|
||||
oxReturnError(serialize(w, PlatSpec::correctEndianness(vm.cap)));
|
||||
oxReturnError(serialize(w, PlatSpec::correctEndianness(vm.items)));
|
||||
OX_RETURN_ERROR(w.write(nullptr, vm.smallVecSize));
|
||||
OX_RETURN_ERROR(serialize(w, PlatSpec::correctEndianness(vm.size)));
|
||||
OX_RETURN_ERROR(serialize(w, PlatSpec::correctEndianness(vm.cap)));
|
||||
OX_RETURN_ERROR(serialize(w, PlatSpec::correctEndianness(vm.items)));
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ template<typename T>
|
||||
constexpr ox::Result<ox::Array<char, sizeof(T)>> serialize(const T &in) noexcept {
|
||||
ox::Array<char, sizeof(T)> out = {};
|
||||
CharBuffWriter w(out);
|
||||
oxReturnError(serialize(w, in));
|
||||
OX_RETURN_ERROR(serialize(w, in));
|
||||
return out;
|
||||
};
|
||||
|
||||
|
6
deps/ox/src/ox/std/size.hpp
vendored
6
deps/ox/src/ox/std/size.hpp
vendored
@@ -190,9 +190,9 @@ constexpr bool Size::operator!=(const Size &p) const noexcept {
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *io, ox::CommonPtrWith<Size> auto *obj) noexcept {
|
||||
oxReturnError(io->template setTypeInfo<Size>());
|
||||
oxReturnError(io->field("width", &obj->width));
|
||||
oxReturnError(io->field("height", &obj->height));
|
||||
OX_RETURN_ERROR(io->template setTypeInfo<Size>());
|
||||
OX_RETURN_ERROR(io->field("width", &obj->width));
|
||||
OX_RETURN_ERROR(io->field("height", &obj->height));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
8
deps/ox/src/ox/std/smallmap.hpp
vendored
8
deps/ox/src/ox/std/smallmap.hpp
vendored
@@ -140,7 +140,7 @@ template<typename K, typename T, size_t SmallSz>
|
||||
constexpr Result<T*> SmallMap<K, T, SmallSz>::at(MaybeView_t<K> const&k) noexcept {
|
||||
auto p = access(m_pairs, k);
|
||||
if (!p) {
|
||||
return {nullptr, OxError(1, "value not found for given key")};
|
||||
return {nullptr, ox::Error(1, "value not found for given key")};
|
||||
}
|
||||
return &p->value;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ template<typename K, typename T, size_t SmallSz>
|
||||
constexpr Result<const T*> SmallMap<K, T, SmallSz>::at(MaybeView_t<K> const&k) const noexcept {
|
||||
auto p = access(m_pairs, k);
|
||||
if (!p) {
|
||||
return {nullptr, OxError(1, "value not found for given key")};
|
||||
return {nullptr, ox::Error(1, "value not found for given key")};
|
||||
}
|
||||
return &p->value;
|
||||
}
|
||||
@@ -247,8 +247,8 @@ constexpr typename SmallMap<K, T, SmallSz>::Pair &SmallMap<K, T, SmallSz>::acces
|
||||
template<typename T, typename K, typename V, size_t SmallSz>
|
||||
constexpr Error model(T *io, ox::CommonPtrWith<SmallMap<K, V, SmallSz>> auto *obj) noexcept {
|
||||
using Map = SmallMap<K, V, SmallSz>;
|
||||
oxReturnError(io->template setTypeInfo<Map>());
|
||||
oxReturnError(io->field("pairs", &obj->m_pairs));
|
||||
OX_RETURN_ERROR(io->template setTypeInfo<Map>());
|
||||
OX_RETURN_ERROR(io->field("pairs", &obj->m_pairs));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
68
deps/ox/src/ox/std/source_location.hpp
vendored
Normal file
68
deps/ox/src/ox/std/source_location.hpp
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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{};
|
||||
};
|
||||
static constexpr __impl Default{
|
||||
._M_file_name = "",
|
||||
._M_function_name = "",
|
||||
._M_line = {},
|
||||
._M_column = {},
|
||||
};
|
||||
__impl const*m_data{&Default};
|
||||
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;
|
||||
if (pSl) {
|
||||
sl.m_data = static_cast<__impl const*>(pSl);
|
||||
}
|
||||
return sl;
|
||||
}
|
||||
|
||||
constexpr uint32_t line() const noexcept {
|
||||
return m_data->_M_line;
|
||||
}
|
||||
|
||||
constexpr uint32_t column() const noexcept {
|
||||
return m_data->_M_column;
|
||||
}
|
||||
|
||||
constexpr ox::CString file_name() const noexcept {
|
||||
return m_data->_M_file_name;
|
||||
}
|
||||
|
||||
constexpr ox::CString function_name() const noexcept {
|
||||
return m_data->_M_function_name;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
13
deps/ox/src/ox/std/strconv.hpp
vendored
13
deps/ox/src/ox/std/strconv.hpp
vendored
@@ -1,3 +1,10 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
@@ -17,7 +24,7 @@ constexpr ox::Error writeItoa(Integer v, ox::Writer_c auto &writer) noexcept {
|
||||
constexpr auto base = 10;
|
||||
auto it = 0;
|
||||
if (val < 0) {
|
||||
oxReturnError(writer.put('-'));
|
||||
OX_RETURN_ERROR(writer.put('-'));
|
||||
++it;
|
||||
}
|
||||
while (mod) {
|
||||
@@ -30,13 +37,13 @@ constexpr ox::Error writeItoa(Integer v, ox::Writer_c auto &writer) noexcept {
|
||||
start = 'a';
|
||||
digit -= 10;
|
||||
}
|
||||
oxReturnError(writer.put(static_cast<char>(start + digit)));
|
||||
OX_RETURN_ERROR(writer.put(static_cast<char>(start + digit)));
|
||||
++it;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 0 is a special case
|
||||
oxReturnError(writer.put('0'));
|
||||
OX_RETURN_ERROR(writer.put('0'));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
2
deps/ox/src/ox/std/string.hpp
vendored
2
deps/ox/src/ox/std/string.hpp
vendored
@@ -182,7 +182,7 @@ class BasicString {
|
||||
// make sure last element is a null terminator
|
||||
m_buff[currentLen + strLen] = 0;
|
||||
// this can't fail, but it returns an Error to match BString::append
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
|
||||
constexpr Error append(ox::StringView sv) noexcept {
|
||||
|
2
deps/ox/src/ox/std/stringview.hpp
vendored
2
deps/ox/src/ox/std/stringview.hpp
vendored
@@ -109,7 +109,7 @@ constexpr ox::Result<int> atoi(ox::StringViewCR str) noexcept {
|
||||
total += (str[s] - '0') * multiplier;
|
||||
multiplier *= 10;
|
||||
} else {
|
||||
return OxError(1);
|
||||
return ox::Error(1);
|
||||
}
|
||||
}
|
||||
return total;
|
||||
|
2
deps/ox/src/ox/std/strops.hpp
vendored
2
deps/ox/src/ox/std/strops.hpp
vendored
@@ -106,7 +106,7 @@ constexpr ox::Vector<ox::StringView, smallSz> split(StringViewCR str, StringView
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Result<std::size_t> lastIndexOf(ox::StringViewCR str, int character) noexcept {
|
||||
ox::Result<std::size_t> retval = OxError(1, "Character not found");
|
||||
ox::Result<std::size_t> retval = ox::Error(1, "Character not found");
|
||||
for (auto i = static_cast<int>(str.bytes() - 1); i >= 0; --i) {
|
||||
if (str[static_cast<std::size_t>(i)] == character) {
|
||||
retval = static_cast<std::size_t>(i);
|
||||
|
56
deps/ox/src/ox/std/test/tests.cpp
vendored
56
deps/ox/src/ox/std/test/tests.cpp
vendored
@@ -126,7 +126,7 @@ OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||
OX_CLANG_NOWARN_END
|
||||
ox::heapmgr::free(a1);
|
||||
ox::heapmgr::free(a2);
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -136,10 +136,10 @@ OX_CLANG_NOWARN_END
|
||||
ox::CharBuffWriter bw(buff);
|
||||
oxAssert(ox::writeItoa(5, bw), "ox::writeItoa returned Error");
|
||||
oxExpect(ox::StringView(buff.data()), ox::StringView("5"));
|
||||
oxReturnError(bw.seekp(0));
|
||||
OX_RETURN_ERROR(bw.seekp(0));
|
||||
oxAssert(ox::writeItoa(50, bw), "ox::writeItoa returned Error");
|
||||
oxExpect(ox::StringView(buff.data()), ox::StringView("50"));
|
||||
oxReturnError(bw.seekp(0));
|
||||
OX_RETURN_ERROR(bw.seekp(0));
|
||||
oxAssert(ox::writeItoa(500, bw), "ox::writeItoa returned Error");
|
||||
oxExpect(ox::StringView(buff.data()), ox::StringView("500"));
|
||||
return ox::Error{};
|
||||
@@ -148,41 +148,41 @@ OX_CLANG_NOWARN_END
|
||||
{
|
||||
"ABCDEFG != HIJKLMN",
|
||||
[]() {
|
||||
return OxError(ox::memcmp("ABCDEFG", "HIJKLMN", 7) >= 0);
|
||||
return ox::Error(ox::memcmp("ABCDEFG", "HIJKLMN", 7) >= 0);
|
||||
}
|
||||
},
|
||||
{
|
||||
"HIJKLMN != ABCDEFG",
|
||||
[]() {
|
||||
return OxError(ox::memcmp("HIJKLMN", "ABCDEFG", 7) <= 0);
|
||||
return ox::Error(ox::memcmp("HIJKLMN", "ABCDEFG", 7) <= 0);
|
||||
}
|
||||
},
|
||||
{
|
||||
"ABCDEFG == ABCDEFG",
|
||||
[]() {
|
||||
return OxError(ox::memcmp("ABCDEFG", "ABCDEFG", 7) != 0);
|
||||
return ox::Error(ox::memcmp("ABCDEFG", "ABCDEFG", 7) != 0);
|
||||
}
|
||||
},
|
||||
{
|
||||
"ABCDEFGHI == ABCDEFG",
|
||||
[]() {
|
||||
return OxError(ox::memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
|
||||
return ox::Error(ox::memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
|
||||
}
|
||||
},
|
||||
{
|
||||
"IString",
|
||||
[]() {
|
||||
ox::IString<5> s;
|
||||
oxReturnError(s.append("A"));
|
||||
oxReturnError(s.append("B"));
|
||||
oxReturnError(s.append("9"));
|
||||
oxReturnError(s.append("C"));
|
||||
OX_RETURN_ERROR(s.append("A"));
|
||||
OX_RETURN_ERROR(s.append("B"));
|
||||
OX_RETURN_ERROR(s.append("9"));
|
||||
OX_RETURN_ERROR(s.append("C"));
|
||||
oxAssert(s == "AB9C", "IString append broken");
|
||||
s = "asdf";
|
||||
oxAssert(s == "asdf", "String assign broken");
|
||||
oxAssert(s != "aoeu", "String assign broken");
|
||||
oxAssert(s.len() == 4, "String assign broken");
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -216,7 +216,7 @@ OX_CLANG_NOWARN_END
|
||||
oxAssert(
|
||||
ox::String(ox::StringView("Write")) == ox::StringView("Write"),
|
||||
"String / StringView comparison broken");
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -227,14 +227,14 @@ OX_CLANG_NOWARN_END
|
||||
oxAssert(v.empty(), "Vector::empty() is broken");
|
||||
auto insertTest = [&v](int val, std::size_t size) {
|
||||
v.push_back(val);
|
||||
oxReturnError(OxError(v.size() != size, "Vector size incorrect"));
|
||||
oxReturnError(OxError(v[v.size() - 1] != val, "Vector value wrong"));
|
||||
return OxError(0);
|
||||
OX_RETURN_ERROR(ox::Error(v.size() != size, "Vector size incorrect"));
|
||||
OX_RETURN_ERROR(ox::Error(v[v.size() - 1] != val, "Vector value wrong"));
|
||||
return ox::Error(0);
|
||||
};
|
||||
oxAssert(insertTest(42, 1), "Vector insertion failed");
|
||||
oxAssert(insertTest(100, 2), "Vector insertion failed");
|
||||
oxAssert(insertTest(102, 3), "Vector insertion failed");
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -246,7 +246,7 @@ OX_CLANG_NOWARN_END
|
||||
oxExpect(map.size(), 1u);
|
||||
oxExpect(map["aoeu"], "");
|
||||
oxExpect(map.size(), 2u);
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -262,7 +262,7 @@ OX_CLANG_NOWARN_END
|
||||
ii[5] = 100;
|
||||
oxAssert(ii[4] == 42, "4 != 42");
|
||||
oxAssert(ii[5] == 100, "5 != 100");
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -278,7 +278,7 @@ OX_CLANG_NOWARN_END
|
||||
ii[5] = 100;
|
||||
oxAssert(ii[4] == 42, "4 != 42");
|
||||
oxAssert(ii[5] == 100, "5 != 100");
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -319,7 +319,7 @@ OX_CLANG_NOWARN_END
|
||||
oxExpect(ox::serialize<uint32_t>(257).unwrap(), BA({1, 1, 0, 0}));
|
||||
constexpr auto neg1 = static_cast<char>(-1); // ARM64 Linux assumes -1 literals are ints...
|
||||
oxExpect(ox::serialize<uint32_t>(0xffff'ffff).unwrap(), BA({neg1, neg1, neg1, neg1}));
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -336,7 +336,7 @@ OX_CLANG_NOWARN_END
|
||||
oxAssert(w.write(qwerty.data(), qwerty.bytes()), "write failed");
|
||||
oxExpect(b.size(), 14u);
|
||||
oxExpect(ox::StringView(b.data(), b.size()), "asdfaoeuqwerty");
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -359,7 +359,7 @@ OX_CLANG_NOWARN_END
|
||||
oxExpect(ox::detail::fromHex("a0").unwrap(), 0xa0);
|
||||
oxExpect(ox::detail::fromHex("93").unwrap(), 0x93);
|
||||
oxExpect(ox::detail::fromHex("40").unwrap(), 0x40);
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -379,18 +379,18 @@ OX_CLANG_NOWARN_END
|
||||
oxExpect(ox::detail::toHex(0x93), "93");
|
||||
oxExpect(ox::detail::toHex(0x40), "40");
|
||||
oxExpect(ox::detail::toHex(0xf0), "f0");
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
"UUID",
|
||||
[] {
|
||||
constexpr ox::StringView uuidStr = "8d814442-f46e-4cc3-8edc-ca3c01cc86db";
|
||||
oxRequire(uuid, ox::UUID::fromString(uuidStr));
|
||||
OX_REQUIRE(uuid, ox::UUID::fromString(uuidStr));
|
||||
oxExpect(uuid.toString(), uuidStr);
|
||||
oxExpect(ox::UUID{}.isNull(), true);
|
||||
oxExpect(ox::UUID::fromString(uuidStr).value.isNull(), false);
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -400,7 +400,7 @@ OX_CLANG_NOWARN_END
|
||||
oxExpect(ox::UUID::generate().unwrap().toString(), "5c3f4b5e-ccbf-4727-7f03-3053dedc8827");
|
||||
oxExpect(ox::UUID::generate().unwrap().toString(), "90d0274a-2774-4afa-88e5-0c1d60ba3abf");
|
||||
oxExpect(ox::UUID::generate().unwrap().toString(), "7df77910-841c-48ba-ea2e-44521ac47c2e");
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -467,7 +467,7 @@ OX_CLANG_NOWARN_END
|
||||
sv = "";
|
||||
list = ox::split(sv, '.');
|
||||
oxExpect(list.size(), 0u);
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
32
deps/ox/src/ox/std/trace.hpp
vendored
32
deps/ox/src/ox/std/trace.hpp
vendored
@@ -48,12 +48,12 @@ struct TraceMsgRcv {
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *io, ox::CommonPtrWith<TraceMsgRcv> auto *obj) noexcept {
|
||||
oxReturnError(io->template setTypeInfo<TraceMsgRcv>());
|
||||
oxReturnError(io->field("file", &obj->file));
|
||||
oxReturnError(io->field("line", &obj->line));
|
||||
oxReturnError(io->field("time", &obj->time));
|
||||
oxReturnError(io->field("ch", &obj->ch));
|
||||
oxReturnError(io->field("msg", &obj->msg));
|
||||
OX_RETURN_ERROR(io->template setTypeInfo<TraceMsgRcv>());
|
||||
OX_RETURN_ERROR(io->field("file", &obj->file));
|
||||
OX_RETURN_ERROR(io->field("line", &obj->line));
|
||||
OX_RETURN_ERROR(io->field("time", &obj->time));
|
||||
OX_RETURN_ERROR(io->field("ch", &obj->ch));
|
||||
OX_RETURN_ERROR(io->field("msg", &obj->msg));
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -69,12 +69,12 @@ struct TraceMsg {
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *io, ox::CommonPtrWith<TraceMsg> auto *obj) noexcept {
|
||||
oxReturnError(io->template setTypeInfo<TraceMsg>());
|
||||
oxReturnError(io->fieldCString("file", &obj->file));
|
||||
oxReturnError(io->field("line", &obj->line));
|
||||
oxReturnError(io->field("time", &obj->time));
|
||||
oxReturnError(io->fieldCString("ch", &obj->ch));
|
||||
oxReturnError(io->field("msg", &obj->msg));
|
||||
OX_RETURN_ERROR(io->template setTypeInfo<TraceMsg>());
|
||||
OX_RETURN_ERROR(io->fieldCString("file", &obj->file));
|
||||
OX_RETURN_ERROR(io->field("line", &obj->line));
|
||||
OX_RETURN_ERROR(io->field("time", &obj->time));
|
||||
OX_RETURN_ERROR(io->fieldCString("ch", &obj->ch));
|
||||
OX_RETURN_ERROR(io->field("msg", &obj->msg));
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ struct InitTraceMsgRcv {
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *io, ox::CommonPtrWith<InitTraceMsgRcv> auto *obj) noexcept {
|
||||
oxReturnError(io->template setTypeInfo<InitTraceMsgRcv>());
|
||||
oxReturnError(io->field("appName", &obj->appName));
|
||||
OX_RETURN_ERROR(io->template setTypeInfo<InitTraceMsgRcv>());
|
||||
OX_RETURN_ERROR(io->field("appName", &obj->appName));
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -101,8 +101,8 @@ struct InitTraceMsg {
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *io, ox::CommonPtrWith<InitTraceMsg> auto *obj) noexcept {
|
||||
oxReturnError(io->template setTypeInfo<InitTraceMsg>());
|
||||
oxReturnError(io->field("appName", &obj->appName));
|
||||
OX_RETURN_ERROR(io->template setTypeInfo<InitTraceMsg>());
|
||||
OX_RETURN_ERROR(io->field("appName", &obj->appName));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
2
deps/ox/src/ox/std/types.hpp
vendored
2
deps/ox/src/ox/std/types.hpp
vendored
@@ -61,6 +61,8 @@ using uint_t = unsigned;
|
||||
|
||||
namespace ox {
|
||||
|
||||
using CString = char const*;
|
||||
|
||||
/**
|
||||
* Aliases type T in size and alignment to allow allocating space for a T
|
||||
* without running the constructor.
|
||||
|
2
deps/ox/src/ox/std/uuid.cpp
vendored
2
deps/ox/src/ox/std/uuid.cpp
vendored
@@ -21,7 +21,7 @@ void UUID::seedGenerator(const RandomSeed &seed) noexcept {
|
||||
// UUID v4
|
||||
Result<UUID> UUID::generate() noexcept {
|
||||
if (!s_seeded) {
|
||||
return OxError(1, "UUID generator not seeded.");
|
||||
return ox::Error(1, "UUID generator not seeded.");
|
||||
}
|
||||
UUID out;
|
||||
for (auto &v : out.m_value) {
|
||||
|
22
deps/ox/src/ox/std/uuid.hpp
vendored
22
deps/ox/src/ox/std/uuid.hpp
vendored
@@ -56,10 +56,10 @@ constexpr ox::Result<uint8_t> fromHex(ox::StringViewCR v) noexcept {
|
||||
return out;
|
||||
}();
|
||||
if (!detail::isHexChar(v[0]) || !detail::isHexChar(v[1])) {
|
||||
return OxError(1, "Invalid UUID");
|
||||
return ox::Error(1, "Invalid UUID");
|
||||
}
|
||||
if (v.len() != 2) {
|
||||
return OxError(2);
|
||||
return ox::Error(2);
|
||||
}
|
||||
uint8_t out = 0;
|
||||
out += static_cast<uint8_t>(valMap[static_cast<unsigned char>(v[0])] * 16);
|
||||
@@ -130,7 +130,7 @@ class UUID {
|
||||
|
||||
static constexpr ox::Result<ox::UUID> fromString(ox::StringViewCR s) noexcept {
|
||||
if (s.len() < 36) {
|
||||
return OxError(1, "Insufficient data to contain a complete UUID");
|
||||
return ox::Error(1, "Insufficient data to contain a complete UUID");
|
||||
}
|
||||
UUID out;
|
||||
auto valueI = 0u;
|
||||
@@ -141,9 +141,9 @@ class UUID {
|
||||
}
|
||||
const auto seg = substr(s, i, i + 2);
|
||||
if (seg.len() != 2) {
|
||||
return OxError(1, "Invalid UUID");
|
||||
return ox::Error(1, "Invalid UUID");
|
||||
}
|
||||
oxRequire(val, detail::fromHex(seg));
|
||||
OX_REQUIRE(val, detail::fromHex(seg));
|
||||
out.m_value[valueI] = val;
|
||||
i += 2;
|
||||
++valueI;
|
||||
@@ -175,13 +175,13 @@ class UUID {
|
||||
}
|
||||
};
|
||||
printChars(writer, m_value, 4, valueI);
|
||||
oxReturnError(writer.put('-'));
|
||||
OX_RETURN_ERROR(writer.put('-'));
|
||||
printChars(writer, m_value, 2, valueI);
|
||||
oxReturnError(writer.put('-'));
|
||||
OX_RETURN_ERROR(writer.put('-'));
|
||||
printChars(writer, m_value, 2, valueI);
|
||||
oxReturnError(writer.put('-'));
|
||||
OX_RETURN_ERROR(writer.put('-'));
|
||||
printChars(writer, m_value, 2, valueI);
|
||||
oxReturnError(writer.put('-'));
|
||||
OX_RETURN_ERROR(writer.put('-'));
|
||||
printChars(writer, m_value, 6, valueI);
|
||||
return {};
|
||||
}
|
||||
@@ -217,8 +217,8 @@ struct hash<ox::UUID> {
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *io, ox::CommonPtrWith<UUID> auto *obj) noexcept {
|
||||
oxReturnError(io->template setTypeInfo<UUID>());
|
||||
oxReturnError(io->field("value", &obj->m_value));
|
||||
OX_RETURN_ERROR(io->template setTypeInfo<UUID>());
|
||||
OX_RETURN_ERROR(io->field("value", &obj->m_value));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
4
deps/ox/src/ox/std/vec.cpp
vendored
4
deps/ox/src/ox/std/vec.cpp
vendored
@@ -6,15 +6,13 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <ox/std/defines.hpp>
|
||||
|
||||
#include "vec.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
static_assert([] {
|
||||
Vec2 v(1, 2);
|
||||
return v.x == 1 && v.y == 2 && v.size() == 2;
|
||||
return v.x == 1 && v.y == 2;
|
||||
}());
|
||||
|
||||
}
|
||||
|
21
deps/ox/src/ox/std/vec.hpp
vendored
21
deps/ox/src/ox/std/vec.hpp
vendored
@@ -12,13 +12,9 @@
|
||||
#include <imgui.h>
|
||||
#endif
|
||||
|
||||
#include <ox/model/def.hpp>
|
||||
#include <ox/std/assert.hpp>
|
||||
#include <ox/std/bit.hpp>
|
||||
#include <ox/std/concepts.hpp>
|
||||
#include <ox/std/def.hpp>
|
||||
#include <ox/std/error.hpp>
|
||||
#include <ox/std/iterator.hpp>
|
||||
#include <ox/std/math.hpp>
|
||||
#include <ox/std/types.hpp>
|
||||
|
||||
namespace ox {
|
||||
@@ -61,15 +57,6 @@ class Vec2 {
|
||||
return !operator==(v);
|
||||
}
|
||||
|
||||
explicit constexpr operator class Point() const noexcept;
|
||||
|
||||
explicit constexpr operator class Size() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t size() const noexcept {
|
||||
return 2;
|
||||
}
|
||||
|
||||
constexpr Vec2 operator+(float i) const noexcept {
|
||||
return {x + i, y + i};
|
||||
}
|
||||
@@ -113,9 +100,9 @@ class Vec2 {
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *io, ox::CommonPtrWith<Vec2> auto *obj) noexcept {
|
||||
oxReturnError(io->template setTypeInfo<Vec2>());
|
||||
oxReturnError(io->field("x", &obj->x));
|
||||
oxReturnError(io->field("y", &obj->y));
|
||||
OX_RETURN_ERROR(io->template setTypeInfo<Vec2>());
|
||||
OX_RETURN_ERROR(io->field("x", &obj->x));
|
||||
OX_RETURN_ERROR(io->field("y", &obj->y));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
18
deps/ox/src/ox/std/vector.hpp
vendored
18
deps/ox/src/ox/std/vector.hpp
vendored
@@ -439,7 +439,7 @@ constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::at(size_t i) noexcep
|
||||
if (i < size()) [[likely]] {
|
||||
return &operator[](i);
|
||||
}
|
||||
return OxError(1, "Vector: Invalid index");
|
||||
return ox::Error(1, "Vector: Invalid index");
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
@@ -447,13 +447,13 @@ constexpr Result<T const*> Vector<T, SmallVectorSize, Allocator>::at(size_t i) c
|
||||
if (i < size()) [[likely]] {
|
||||
return &operator[](i);
|
||||
}
|
||||
return OxError(1, "Vector: Invalid index");
|
||||
return ox::Error(1, "Vector: Invalid index");
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::front() noexcept {
|
||||
if (!m_size) {
|
||||
return {nullptr, OxError(1)};
|
||||
return {nullptr, ox::Error(1)};
|
||||
}
|
||||
return &m_items[0];
|
||||
}
|
||||
@@ -461,7 +461,7 @@ constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::front() noexcept {
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<const T*> Vector<T, SmallVectorSize, Allocator>::front() const noexcept {
|
||||
if (!m_size) {
|
||||
return {nullptr, OxError(1)};
|
||||
return {nullptr, ox::Error(1)};
|
||||
}
|
||||
return &m_items[0];
|
||||
}
|
||||
@@ -469,7 +469,7 @@ constexpr Result<const T*> Vector<T, SmallVectorSize, Allocator>::front() const
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::back() noexcept {
|
||||
if (!m_size) {
|
||||
return {nullptr, OxError(1)};
|
||||
return {nullptr, ox::Error(1)};
|
||||
}
|
||||
return &m_items[m_size - 1];
|
||||
}
|
||||
@@ -477,7 +477,7 @@ constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::back() noexcept {
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<const T*> Vector<T, SmallVectorSize, Allocator>::back() const noexcept {
|
||||
if (!m_size) {
|
||||
return {nullptr, OxError(1)};
|
||||
return {nullptr, ox::Error(1)};
|
||||
}
|
||||
return &m_items[m_size - 1];
|
||||
}
|
||||
@@ -634,7 +634,7 @@ template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>>
|
||||
Vector<T, SmallVectorSize, Allocator>::erase(std::size_t pos) noexcept(useNoexcept) {
|
||||
if (pos >= m_size) {
|
||||
return OxError(1, "Vector::erase failed: pos is greater than Vector size");
|
||||
return ox::Error(1, "Vector::erase failed: pos is greater than Vector size");
|
||||
}
|
||||
--m_size;
|
||||
for (auto i = pos; i < m_size; ++i) {
|
||||
@@ -648,12 +648,12 @@ template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Error Vector<T, SmallVectorSize, Allocator>::unordered_erase(std::size_t pos)
|
||||
noexcept(useNoexcept) {
|
||||
if (pos >= m_size) {
|
||||
return OxError(1);
|
||||
return ox::Error(1);
|
||||
}
|
||||
--m_size;
|
||||
m_items[pos] = std::move(m_items[m_size]);
|
||||
m_items[m_size].~T();
|
||||
return OxError(0);
|
||||
return ox::Error(0);
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
|
6
deps/ox/src/ox/std/writer.hpp
vendored
6
deps/ox/src/ox/std/writer.hpp
vendored
@@ -74,10 +74,10 @@ class WriterT: public Writer_v {
|
||||
*/
|
||||
constexpr ox::Result<std::size_t> allocate(Writer_c auto &writer, std::size_t sz) noexcept {
|
||||
const auto p = writer.tellp();
|
||||
oxReturnError(writer.seekp(0, ios_base::end));
|
||||
OX_RETURN_ERROR(writer.seekp(0, ios_base::end));
|
||||
const auto out = writer.tellp();
|
||||
oxReturnError(writer.write(nullptr, sz));
|
||||
oxReturnError(writer.seekp(p));
|
||||
OX_RETURN_ERROR(writer.write(nullptr, sz));
|
||||
OX_RETURN_ERROR(writer.seekp(p));
|
||||
return out;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user