From 962fe8bc2214553d4f05be1397d30ad297c3e278 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 18 Dec 2024 22:04:25 -0600 Subject: [PATCH] [ox] Change macro names to comply with broader conventions --- deps/ox/ox-docs.md | 82 +++++++++---------- deps/ox/src/ox/clargs/clargs.cpp | 6 +- deps/ox/src/ox/claw/read.cpp | 10 +-- deps/ox/src/ox/claw/read.hpp | 4 +- deps/ox/src/ox/claw/test/tests.cpp | 52 ++++++------ deps/ox/src/ox/claw/write.hpp | 22 ++--- deps/ox/src/ox/event/signal.hpp | 12 +-- deps/ox/src/ox/event/test/tests.cpp | 4 +- .../src/ox/fs/filestore/filestoretemplate.hpp | 34 ++++---- deps/ox/src/ox/fs/filesystem/directory.hpp | 32 ++++---- deps/ox/src/ox/fs/filesystem/filelocation.hpp | 22 ++--- deps/ox/src/ox/fs/filesystem/filesystem.cpp | 8 +- deps/ox/src/ox/fs/filesystem/filesystem.hpp | 58 ++++++------- .../ox/src/ox/fs/filesystem/passthroughfs.cpp | 12 +-- .../ox/src/ox/fs/filesystem/passthroughfs.hpp | 4 +- deps/ox/src/ox/fs/ptrarith/nodebuffer.hpp | 2 +- deps/ox/src/ox/fs/tool.cpp | 8 +- deps/ox/src/ox/logconn/logconn.cpp | 2 +- deps/ox/src/ox/logconn/logconn.hpp | 10 +-- deps/ox/src/ox/mc/intops.hpp | 10 +-- deps/ox/src/ox/mc/presenceindicator.hpp | 10 +-- deps/ox/src/ox/mc/read.hpp | 76 ++++++++--------- deps/ox/src/ox/mc/test/tests.cpp | 72 ++++++++-------- deps/ox/src/ox/mc/write.hpp | 76 ++++++++--------- deps/ox/src/ox/model/def.hpp | 12 +-- deps/ox/src/ox/model/desctypes.hpp | 44 +++++----- deps/ox/src/ox/model/descwrite.hpp | 6 +- deps/ox/src/ox/model/modelvalue.cpp | 2 +- deps/ox/src/ox/model/modelvalue.hpp | 46 +++++------ deps/ox/src/ox/model/test/tests.cpp | 8 +- deps/ox/src/ox/model/typestore.hpp | 8 +- deps/ox/src/ox/model/walk.hpp | 20 ++--- deps/ox/src/ox/oc/read.cpp | 2 +- deps/ox/src/ox/oc/read.hpp | 8 +- deps/ox/src/ox/oc/test/tests.cpp | 58 ++++++------- deps/ox/src/ox/oc/write.hpp | 14 ++-- deps/ox/src/ox/preloader/alignmentcatcher.hpp | 2 +- deps/ox/src/ox/preloader/preloader.hpp | 68 +++++++-------- deps/ox/src/ox/preloader/sizecatcher.hpp | 4 +- deps/ox/src/ox/preloader/unionsizecatcher.hpp | 4 +- deps/ox/src/ox/std/bounds.hpp | 10 +-- deps/ox/src/ox/std/def.hpp | 12 +-- deps/ox/src/ox/std/defer.hpp | 2 +- deps/ox/src/ox/std/point.hpp | 6 +- deps/ox/src/ox/std/serialize.hpp | 10 +-- deps/ox/src/ox/std/size.hpp | 6 +- deps/ox/src/ox/std/smallmap.hpp | 4 +- deps/ox/src/ox/std/strconv.hpp | 6 +- deps/ox/src/ox/std/test/tests.cpp | 18 ++-- deps/ox/src/ox/std/trace.hpp | 32 ++++---- deps/ox/src/ox/std/uuid.hpp | 14 ++-- deps/ox/src/ox/std/vec.hpp | 6 +- deps/ox/src/ox/std/writer.hpp | 6 +- 53 files changed, 533 insertions(+), 533 deletions(-) diff --git a/deps/ox/ox-docs.md b/deps/ox/ox-docs.md index 2cdbfa34..7a29d545 100644 --- a/deps/ox/ox-docs.md +++ b/deps/ox/ox-docs.md @@ -97,12 +97,12 @@ ox::Result caller8(int i) { ``` Lastly, there are a few macros available to help in passing ```ox::Error```s -back up the call stack, ```oxReturnError```, ```oxThrowError```, and -```oxRequire```. +back up the call stack, ```OX_RETURN_ERROR```, ```OX_THROW_ERROR```, and +```OX_REQUIRE```. -```oxReturnError``` is by far the more helpful of the two. -```oxReturnError``` will return an ```ox::Error``` if it is not 0 and -```oxThrowError``` will throw an ```ox::Error``` if it is not 0. +```OX_RETURN_ERROR``` is by far the more helpful of the two. +```OX_RETURN_ERROR``` will return an ```ox::Error``` if it is not 0 and +```OX_THROW_ERROR``` will throw an ```ox::Error``` if it is not 0. Since ```ox::Error``` is always nodiscard, you must do something with them. In rare cases, you may not have anything you can do with them or you may know @@ -113,13 +113,13 @@ This should be used sparingly. ```cpp void studioCode() { auto [val, err] = foo(1); - oxThrowError(err); + OX_THROW_ERROR(err); doStuff(val); } ox::Error engineCode() noexcept { auto [val, err] = foo(1); - oxReturnError(err); + OX_RETURN_ERROR(err); doStuff(val); return {}; } @@ -136,19 +136,19 @@ Both macros will also take the ```ox::Result``` directly: ```cpp void studioCode() { auto valerr = foo(1); - oxThrowError(valerr); + OX_THROW_ERROR(valerr); doStuff(valerr.value); } ox::Error engineCode() noexcept { auto valerr = foo(1); - oxReturnError(valerr); + OX_RETURN_ERROR(valerr); doStuff(valerr.value); return {}; } ``` -Ox also has the ```oxRequire``` macro, which will initialize a value if there is no error, and return if there is. +Ox also has the ```OX_REQUIRE``` macro, which will initialize a value if there is no error, and return if there is. It aims to somewhat emulate the ```?``` operator in Rust and Swift. Rust ```?``` operator: @@ -163,23 +163,23 @@ fn f2() -> Result { } ``` -```oxRequire```: +```OX_REQUIRE```: ```cpp ox::Result f() noexcept { // do stuff } ox::Result f2() noexcept { - oxRequire(i, f()); // const auto [out, oxConcat(oxRequire_err_, __LINE__)] = x; oxReturnError(oxConcat(oxRequire_err_, __LINE__)) + OX_REQUIRE(i, f()); // const auto [out, OX_CONCAT(oxRequire_err_, __LINE__)] = x; OX_RETURN_ERROR(OX_CONCAT(oxRequire_err_, __LINE__)) return i + 4; } ``` -```oxRequire``` is not quite as versatile, but it should still cleanup a lot of otherwise less ideal code. +```OX_REQUIRE``` is not quite as versatile, but it should still cleanup a lot of otherwise less ideal code. -```oxRequire``` by default creates a const, but there is also an ```oxRequireM``` (oxRequire Mutable) +```OX_REQUIRE``` by default creates a const, but there is also an ```OX_REQUIRE_M``` (OX_REQUIRE Mutable) variant for creating a non-const value. -* ```oxRequireM``` - oxRequire Mutable +* ```OX_REQUIRE_M``` - OX_REQUIRE Mutable ### Logging and Output @@ -268,19 +268,19 @@ constexpr ox::Error model(T *h, ox::CommonPtrWith auto *pal) n h->template setTypeInfo(); // it is also possible to provide the type name and type version as function arguments //h->setTypeInfo("net.drinkingtea.nostalgia.core.NostalgiaPalette", 1); - oxReturnError(h->field("colors", &pal->colors)); + OX_RETURN_ERROR(h->field("colors", &pal->colors)); return {}; } template constexpr ox::Error model(T *h, ox::CommonPtrWith auto *ng) noexcept { h->template setTypeInfo(); - oxReturnError(h->field("bpp", &ng->bpp)); - oxReturnError(h->field("rows", &ng->rows)); - oxReturnError(h->field("columns", &ng->columns)); - oxReturnError(h->field("defaultPalette", &ng->defaultPalette)); - oxReturnError(h->field("pal", &ng->pal)); - oxReturnError(h->field("pixels", &ng->pixels)); + OX_RETURN_ERROR(h->field("bpp", &ng->bpp)); + OX_RETURN_ERROR(h->field("rows", &ng->rows)); + OX_RETURN_ERROR(h->field("columns", &ng->columns)); + OX_RETURN_ERROR(h->field("defaultPalette", &ng->defaultPalette)); + OX_RETURN_ERROR(h->field("pal", &ng->pal)); + OX_RETURN_ERROR(h->field("pixels", &ng->pixels)); return {}; } ``` @@ -315,9 +315,9 @@ class FileAddress { template constexpr Error model(T *h, ox::CommonPtrWith auto *obj) noexcept { h->template setTypeInfo(); - oxReturnError(h->fieldCString("path", &obj->path)); - oxReturnError(h->fieldCString("constPath", &obj->path)); - oxReturnError(h->field("inode", &obj->inode)); + OX_RETURN_ERROR(h->fieldCString("path", &obj->path)); + OX_RETURN_ERROR(h->fieldCString("constPath", &obj->path)); + OX_RETURN_ERROR(h->field("inode", &obj->inode)); return {}; } @@ -327,13 +327,13 @@ constexpr Error model(T *io, ox::CommonPtrWith auto *fa) noexcept { // cannot read from object in Reflect operation if constexpr(ox_strcmp(T::opType(), OpType::Reflect) == 0) { int8_t type = 0; - oxReturnError(io->field("type", &type)); - oxReturnError(io->field("data", UnionView(&fa->m_data, 0))); + OX_RETURN_ERROR(io->field("type", &type)); + OX_RETURN_ERROR(io->field("data", UnionView(&fa->m_data, 0))); } else { auto type = static_cast(fa->m_type); - oxReturnError(io->field("type", &type)); + OX_RETURN_ERROR(io->field("type", &type)); fa->m_type = static_cast(type); - oxReturnError(io->field("data", UnionView(&fa->m_data, static_cast(fa->m_type)))); + OX_RETURN_ERROR(io->field("data", UnionView(&fa->m_data, static_cast(fa->m_type)))); } return {}; } @@ -343,13 +343,13 @@ constexpr Error model(T *io, ox::CommonPtrWith auto *fa) noexcept { There are also macros in `````` for simplifying the declaration of models: ```cpp -oxModelBegin(NostalgiaGraphic) - oxModelField(bpp) - oxModelField(rows) - oxModelField(columns) - oxModelField(defaultPalette) - oxModelField(pal) - oxModelField(pixels) +OX_MODEL_BEGIN(NostalgiaGraphic) + OX_MODEL_FIELD(bpp) + OX_MODEL_FIELD(rows) + OX_MODEL_FIELD(columns) + OX_MODEL_FIELD(defaultPalette) + OX_MODEL_FIELD(pal) + OX_MODEL_FIELD(pixels) oxModelEnd() ``` @@ -392,7 +392,7 @@ ox::Result loadPalette1(ox::BufferView const&buff) noexcept { ox::Result loadPalette2(ox::BufferView const&buff) noexcept { NostalgiaPalette pal; - oxReturnError(ox::readMC(buff, pal)); + OX_RETURN_ERROR(ox::readMC(buff, pal)); return pal; } ``` @@ -405,7 +405,7 @@ ox::Result loadPalette2(ox::BufferView const&buff) noexcept { ox::Result writeSpritePalette1(NostalgiaPalette const&pal) noexcept { ox::Buffer buffer(ox::units::MB); std::size_t sz = 0; - oxReturnError(ox::writeMC(buffer.data(), buffer.size(), pal, &sz)); + OX_RETURN_ERROR(ox::writeMC(buffer.data(), buffer.size(), pal, &sz)); buffer.resize(sz); return buffer; } @@ -428,7 +428,7 @@ ox::Result loadPalette1(ox::BufferView const&buff) noexcept { ox::Result loadPalette2(ox::BufferView const&buff) noexcept { NostalgiaPalette pal; - oxReturnError(ox::readOC(buff, &pal)); + OX_RETURN_ERROR(ox::readOC(buff, &pal)); return pal; } ``` @@ -440,7 +440,7 @@ ox::Result loadPalette2(ox::BufferView const&buff) noexcept { ox::Result writeSpritePalette1(NostalgiaPalette const&pal) noexcept { ox::Buffer buffer(ox::units::MB); - oxReturnError(ox::writeOC(buffer.data(), buffer.size(), pal)); + OX_RETURN_ERROR(ox::writeOC(buffer.data(), buffer.size(), pal)); return buffer; } @@ -462,7 +462,7 @@ ox::Result loadPalette1(ox::BufferView const&buff) noexcept { ox::Result loadPalette2(ox::BufferView const&buff) noexcept { NostalgiaPalette pal; - oxReturnError(ox::readClaw(buff, pal)); + OX_RETURN_ERROR(ox::readClaw(buff, pal)); return pal; } ``` diff --git a/deps/ox/src/ox/clargs/clargs.cpp b/deps/ox/src/ox/clargs/clargs.cpp index 941d25f6..475ab2fc 100644 --- a/deps/ox/src/ox/clargs/clargs.cpp +++ b/deps/ox/src/ox/clargs/clargs.cpp @@ -55,17 +55,17 @@ int ClArgs::getInt(ox::StringViewCR arg, int defaultValue) const noexcept { } Result ClArgs::getBool(ox::StringViewCR arg) const noexcept { - oxRequire(out, m_bools.at(arg)); + OX_REQUIRE(out, m_bools.at(arg)); return *out; } Result ClArgs::getString(ox::StringViewCR argName) const noexcept { - oxRequire(out, m_strings.at(argName)); + OX_REQUIRE(out, m_strings.at(argName)); return *out; } Result ClArgs::getInt(ox::StringViewCR arg) const noexcept { - oxRequire(out, m_ints.at(arg)); + OX_REQUIRE(out, m_ints.at(arg)); return *out; } diff --git a/deps/ox/src/ox/claw/read.cpp b/deps/ox/src/ox/claw/read.cpp index 806ff7e1..1b0ef86f 100644 --- a/deps/ox/src/ox/claw/read.cpp +++ b/deps/ox/src/ox/claw/read.cpp @@ -88,26 +88,26 @@ Result readClawHeader(ox::BufferView buff) noexcept { } Result stripClawHeader(ox::BufferView buff) noexcept { - oxRequire(header, readClawHeader(buff)); + OX_REQUIRE(header, readClawHeader(buff)); return {{header.data, header.dataSize}}; } Result readClaw(TypeStore &ts, BufferView buff) noexcept { - oxRequire(header, readClawHeader(buff)); + OX_REQUIRE(header, readClawHeader(buff)); auto const [t, tdErr] = ts.getLoad( header.typeName, header.typeVersion, header.typeParams); if (tdErr) { return ox::Error(3, "Could not load type descriptor"); } ModelObject obj; - oxReturnError(obj.setType(t)); + OX_RETURN_ERROR(obj.setType(t)); switch (header.fmt) { case ClawFormat::Metal: { ox::BufferReader br({header.data, header.dataSize}); MetalClawReader reader(br); ModelHandlerInterface handler(&reader); - oxReturnError(model(&handler, &obj)); + OX_RETURN_ERROR(model(&handler, &obj)); return obj; } case ClawFormat::Organic: @@ -115,7 +115,7 @@ Result readClaw(TypeStore &ts, BufferView buff) noexcept { #ifdef OX_USE_STDLIB OrganicClawReader reader({header.data, header.dataSize}); ModelHandlerInterface handler(&reader); - oxReturnError(model(&handler, &obj)); + OX_RETURN_ERROR(model(&handler, &obj)); return obj; #else break; diff --git a/deps/ox/src/ox/claw/read.hpp b/deps/ox/src/ox/claw/read.hpp index 4ec1b09c..bbffa434 100644 --- a/deps/ox/src/ox/claw/read.hpp +++ b/deps/ox/src/ox/claw/read.hpp @@ -40,7 +40,7 @@ Result stripClawHeader(ox::BufferView buff) noexcept; template Error readClaw(ox::BufferView buff, T &val) { - oxRequire(header, readClawHeader(buff)); + OX_REQUIRE(header, readClawHeader(buff)); if (header.typeName != getModelTypeName()) { return ox::Error(Error_ClawTypeMismatch, "Claw Read: Type mismatch"); } @@ -73,7 +73,7 @@ Error readClaw(ox::BufferView buff, T &val) { template Result readClaw(ox::BufferView buff) { Result val; - oxReturnError(readClaw(buff, val.value)); + OX_RETURN_ERROR(readClaw(buff, val.value)); return val; } diff --git a/deps/ox/src/ox/claw/test/tests.cpp b/deps/ox/src/ox/claw/test/tests.cpp index c37d662a..dfbacb45 100644 --- a/deps/ox/src/ox/claw/test/tests.cpp +++ b/deps/ox/src/ox/claw/test/tests.cpp @@ -62,44 +62,44 @@ struct TestStruct { template constexpr ox::Error model(T *io, ox::CommonPtrWith auto *obj) { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("Bool", &obj->Bool)); - oxReturnError(io->field("Int", &obj->Int)); - oxReturnError(io->fieldCString("String", &obj->String)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("Bool", &obj->Bool)); + OX_RETURN_ERROR(io->field("Int", &obj->Int)); + OX_RETURN_ERROR(io->fieldCString("String", &obj->String)); return ox::Error(0); } template constexpr ox::Error model(T *io, ox::CommonPtrWith auto *obj) { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("Bool", &obj->Bool)); - oxReturnError(io->field("Int", &obj->Int)); - oxReturnError(io->field("String", &obj->String)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("Bool", &obj->Bool)); + OX_RETURN_ERROR(io->field("Int", &obj->Int)); + OX_RETURN_ERROR(io->field("String", &obj->String)); return ox::Error(0); } template constexpr ox::Error model(T *io, ox::CommonPtrWith auto *obj) { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("Bool", &obj->Bool)); - oxReturnError(io->field("Int", &obj->Int)); - oxReturnError(io->field("Int1", &obj->Int1)); - oxReturnError(io->field("Int2", &obj->Int2)); - oxReturnError(io->field("Int3", &obj->Int3)); - oxReturnError(io->field("Int4", &obj->Int4)); - oxReturnError(io->field("Int5", &obj->Int5)); - oxReturnError(io->field("Int6", &obj->Int6)); - oxReturnError(io->field("Int7", &obj->Int7)); - oxReturnError(io->field("Int8", &obj->Int8)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("Bool", &obj->Bool)); + OX_RETURN_ERROR(io->field("Int", &obj->Int)); + OX_RETURN_ERROR(io->field("Int1", &obj->Int1)); + OX_RETURN_ERROR(io->field("Int2", &obj->Int2)); + OX_RETURN_ERROR(io->field("Int3", &obj->Int3)); + OX_RETURN_ERROR(io->field("Int4", &obj->Int4)); + OX_RETURN_ERROR(io->field("Int5", &obj->Int5)); + OX_RETURN_ERROR(io->field("Int6", &obj->Int6)); + OX_RETURN_ERROR(io->field("Int7", &obj->Int7)); + OX_RETURN_ERROR(io->field("Int8", &obj->Int8)); int unionIdx = 0; if constexpr(T::opType() != ox::OpType::Reflect) { unionIdx = obj->unionIdx; } - oxReturnError(io->field("Union", ox::UnionView{&obj->Union, unionIdx})); - oxReturnError(io->field("String", &obj->String)); - oxReturnError(io->field("List", obj->List, 4)); - oxReturnError(io->field("EmptyStruct", &obj->EmptyStruct)); - oxReturnError(io->field("Struct", &obj->Struct)); + OX_RETURN_ERROR(io->field("Union", ox::UnionView{&obj->Union, unionIdx})); + OX_RETURN_ERROR(io->field("String", &obj->String)); + OX_RETURN_ERROR(io->field("List", obj->List, 4)); + OX_RETURN_ERROR(io->field("EmptyStruct", &obj->EmptyStruct)); + OX_RETURN_ERROR(io->field("Struct", &obj->Struct)); return ox::Error(0); } @@ -134,7 +134,7 @@ static std::map tests = { [] { constexpr auto hdr = ox::StringLiteral("M2;com.drinkingtea.ox.claw.test.Header2;3;awefawf"); constexpr auto expected = ox::StringLiteral("com.drinkingtea.ox.claw.test.Header2;3"); - oxRequire(actual, ox::readClawTypeId({hdr.data(), hdr.len() + 1})); + OX_REQUIRE(actual, ox::readClawTypeId({hdr.data(), hdr.len() + 1})); oxExpect(actual, expected); return ox::Error{}; } @@ -145,7 +145,7 @@ static std::map tests = { // This test doesn't confirm much, but it does show that the writer // doesn't segfault TestStruct ts; - oxReturnError(ox::writeClaw(ts, ox::ClawFormat::Metal)); + OX_RETURN_ERROR(ox::writeClaw(ts, ox::ClawFormat::Metal)); return ox::Error(0); } }, diff --git a/deps/ox/src/ox/claw/write.hpp b/deps/ox/src/ox/claw/write.hpp index 1e163c35..0d7183aa 100644 --- a/deps/ox/src/ox/claw/write.hpp +++ b/deps/ox/src/ox/claw/write.hpp @@ -76,21 +76,21 @@ template ox::Error writeClawHeader(Writer_c auto &writer, const T *t, ClawFormat fmt) noexcept { switch (fmt) { case ClawFormat::Metal: - oxReturnError(write(writer, "M2;")); + OX_RETURN_ERROR(write(writer, "M2;")); break; case ClawFormat::Organic: - oxReturnError(write(writer, "O1;")); + OX_RETURN_ERROR(write(writer, "O1;")); break; default: return ox::Error(1); } - oxReturnError(write(writer, detail::getTypeName(t))); - oxReturnError(writer.put(';')); + OX_RETURN_ERROR(write(writer, detail::getTypeName(t))); + OX_RETURN_ERROR(writer.put(';')); const auto tn = detail::getTypeVersion(t); if (tn > -1) { - oxReturnError(ox::writeItoa(tn, writer)); + OX_RETURN_ERROR(ox::writeItoa(tn, writer)); } - oxReturnError(writer.put(';')); + OX_RETURN_ERROR(writer.put(';')); return {}; } @@ -102,19 +102,19 @@ Result writeClaw( std::size_t buffReserveSz = 2 * units::KB) noexcept { Buffer out(buffReserveSz); BufferWriter bw(&out, 0); - oxReturnError(detail::writeClawHeader(bw, &t, fmt)); + OX_RETURN_ERROR(detail::writeClawHeader(bw, &t, fmt)); #ifdef OX_USE_STDLIB if (fmt == ClawFormat::Metal) { - oxReturnError(writeMC(bw, t)); + OX_RETURN_ERROR(writeMC(bw, t)); } else if (fmt == ClawFormat::Organic) { - oxRequire(data, writeOC(t)); - oxReturnError(bw.write(data.data(), data.size())); + OX_REQUIRE(data, writeOC(t)); + OX_RETURN_ERROR(bw.write(data.data(), data.size())); } #else if (fmt != ClawFormat::Metal) { return ox::Error(1, "OC is not supported in this build"); } - oxReturnError(writeMC(bw, t)); + OX_RETURN_ERROR(writeMC(bw, t)); #endif out.resize(bw.tellp()); return out; diff --git a/deps/ox/src/ox/event/signal.hpp b/deps/ox/src/ox/event/signal.hpp index bb947b0b..51e18dea 100644 --- a/deps/ox/src/ox/event/signal.hpp +++ b/deps/ox/src/ox/event/signal.hpp @@ -57,7 +57,7 @@ class Signal { void call(Args... args) final { if constexpr(detail::isError::value) { - oxThrowError(f(args...)); + OX_THROW_ERROR(f(args...)); } else { f(args...); } @@ -76,7 +76,7 @@ class Signal { void call(Args... args) final { if constexpr(detail::isError*(m_methodPtr))(args...))>::value) { - oxThrowError((m_receiver->*(m_methodPtr))(args...)); + OX_THROW_ERROR((m_receiver->*(m_methodPtr))(args...)); } else { f(args...); } @@ -107,7 +107,7 @@ class Signal { void call(Args... args) final { if constexpr(detail::isError*(m_methodPtr))(args...))>::value) { - oxThrowError((m_receiver->*(m_methodPtr))(args...)); + OX_THROW_ERROR((m_receiver->*(m_methodPtr))(args...)); } else { (m_receiver->*(m_methodPtr))(args...); } @@ -193,7 +193,7 @@ Error Signal::disconnectObject(const void *receiver) const noexcept { for (auto i = 0u; i < m_slots.size(); ++i) { const auto &slot = m_slots[i]; if (slot->receiver() == receiver) { - oxReturnError(m_slots.erase(i)); + OX_RETURN_ERROR(m_slots.erase(i)); --i; } } @@ -381,7 +381,7 @@ Error Signal::disconnectObject(const void *receiver) const noexc for (auto i = 0u; i < m_slots.size(); ++i) { const auto &slot = m_slots[i]; if (slot->receiver() == receiver) { - oxReturnError(m_slots.erase(i)); + OX_RETURN_ERROR(m_slots.erase(i)); --i; } } @@ -398,7 +398,7 @@ void Signal::emit(Args... args) const noexcept { template Error Signal::emitCheckError(Args... args) const noexcept { for (auto &f : m_slots) { - oxReturnError(f->call(ox::forward(args)...)); + OX_RETURN_ERROR(f->call(ox::forward(args)...)); } return ox::Error(0); } diff --git a/deps/ox/src/ox/event/test/tests.cpp b/deps/ox/src/ox/event/test/tests.cpp index 975609fa..e421c5e2 100644 --- a/deps/ox/src/ox/event/test/tests.cpp +++ b/deps/ox/src/ox/event/test/tests.cpp @@ -31,8 +31,8 @@ std::map> tests = { }); TestStruct ts; signal.connect(&ts, &TestStruct::method); - oxReturnError(signal.emitCheckError(5)); - oxReturnError(ox::Error(ts.value != 5)); + OX_RETURN_ERROR(signal.emitCheckError(5)); + OX_RETURN_ERROR(ox::Error(ts.value != 5)); return ox::Error(0); } }, diff --git a/deps/ox/src/ox/fs/filestore/filestoretemplate.hpp b/deps/ox/src/ox/fs/filestore/filestoretemplate.hpp index b6407e9d..a11da156 100644 --- a/deps/ox/src/ox/fs/filestore/filestoretemplate.hpp +++ b/deps/ox/src/ox/fs/filestore/filestoretemplate.hpp @@ -228,17 +228,17 @@ Error FileStoreTemplate::setSize(std::size_t size) { template Error FileStoreTemplate::incLinks(uint64_t id) { - oxRequireM(item, find(static_cast(id)).validate()); + OX_REQUIRE_M(item, find(static_cast(id)).validate()); ++item->links; return ox::Error(0); } template Error FileStoreTemplate::decLinks(uint64_t id) { - oxRequireM(item, find(static_cast(id)).validate()); + OX_REQUIRE_M(item, find(static_cast(id)).validate()); --item->links; if (item->links == 0) { - oxReturnError(remove(item)); + OX_RETURN_ERROR(remove(item)); } return ox::Error(0); } @@ -249,7 +249,7 @@ Error FileStoreTemplate::write(uint64_t id64, const void *data, FsSize_t oxTracef("ox.fs.FileStoreTemplate.write", "Attempting to write to inode {}", id); auto existing = find(id); if (!canWrite(existing, dataSize)) { - oxReturnError(compact()); + OX_RETURN_ERROR(compact()); existing = find(id); } @@ -269,7 +269,7 @@ Error FileStoreTemplate::write(uint64_t id64, const void *data, FsSize_t // if first malloc failed, compact and try again if (!dest.valid()) { oxTrace("ox.fs.FileStoreTemplate.write", "Allocation failed, compacting"); - oxReturnError(compact()); + OX_RETURN_ERROR(compact()); dest = m_buffer->malloc(dataSize).value; } if (dest.valid()) { @@ -305,7 +305,7 @@ Error FileStoreTemplate::write(uint64_t id64, const void *data, FsSize_t } } } - oxReturnError(m_buffer->free(dest)); + OX_RETURN_ERROR(m_buffer->free(dest)); } return ox::Error(1); } @@ -422,10 +422,10 @@ ptrarith::Ptr FileStoreTemplate::read(uint64_t id) template Error FileStoreTemplate::resize() { - oxReturnError(compact()); + OX_RETURN_ERROR(compact()); const auto newSize = static_cast(size() - available()); oxTracef("ox.fs.FileStoreTemplate.resize", "resize to: {}", newSize); - oxReturnError(m_buffer->setSize(newSize)); + OX_RETURN_ERROR(m_buffer->setSize(newSize)); oxTracef("ox.fs.FileStoreTemplate.resize", "resized to: {}", m_buffer->size()); return ox::Error(0); } @@ -438,14 +438,14 @@ Error FileStoreTemplate::resize(std::size_t size, void *newBuff) { m_buffSize = static_cast(size); if (newBuff) { m_buffer = reinterpret_cast(newBuff); - oxReturnError(m_buffer->setSize(static_cast(size))); + OX_RETURN_ERROR(m_buffer->setSize(static_cast(size))); } return ox::Error(0); } template Result FileStoreTemplate::stat(uint64_t id) const { - oxRequire(inode, find(static_cast(id)).validate()); + OX_REQUIRE(inode, find(static_cast(id)).validate()); return StatInfo { id, inode->links, @@ -477,7 +477,7 @@ char *FileStoreTemplate::buff() { template Error FileStoreTemplate::walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) { for (auto i = m_buffer->iterator(); i.valid(); i.next()) { - oxReturnError(cb(i->fileType, i.ptr().offset(), i.ptr().end())); + OX_RETURN_ERROR(cb(i->fileType, i.ptr().offset(), i.ptr().end())); } return ox::Error(0); } @@ -546,7 +546,7 @@ Error FileStoreTemplate::placeItem(ItemPtr item) { if (!fsData) { return ox::Error(1); } - oxRequireM(root, m_buffer->ptr(fsData->rootNode).validate()); + OX_REQUIRE_M(root, m_buffer->ptr(fsData->rootNode).validate()); if (root->id == item->id) { fsData->rootNode = item; item->left = root->left; @@ -602,7 +602,7 @@ Error FileStoreTemplate::unplaceItem(ItemPtr item) { if (!fsData) { return ox::Error(1); } - oxRequireM(root, m_buffer->ptr(fsData->rootNode).validate()); + OX_REQUIRE_M(root, m_buffer->ptr(fsData->rootNode).validate()); if (root->id == item->id) { item->left = root->left; item->right = root->right; @@ -656,10 +656,10 @@ Error FileStoreTemplate::unplaceItem(ItemPtr root, ItemPtr item, int dep return ox::Error(1); } if (item->right) { - oxReturnError(placeItem(m_buffer->ptr(item->right))); + OX_RETURN_ERROR(placeItem(m_buffer->ptr(item->right))); } if (item->left) { - oxReturnError(placeItem(m_buffer->ptr(item->left))); + OX_RETURN_ERROR(placeItem(m_buffer->ptr(item->left))); } return ox::Error(0); } @@ -667,8 +667,8 @@ Error FileStoreTemplate::unplaceItem(ItemPtr root, ItemPtr item, int dep template Error FileStoreTemplate::remove(ItemPtr item) { if (item.valid()) { - oxReturnError(unplaceItem(item)); - oxReturnError(m_buffer->free(item)); + OX_RETURN_ERROR(unplaceItem(item)); + OX_RETURN_ERROR(m_buffer->free(item)); return ox::Error(0); } return ox::Error(1); diff --git a/deps/ox/src/ox/fs/filesystem/directory.hpp b/deps/ox/src/ox/fs/filesystem/directory.hpp index 068e6498..616116ab 100644 --- a/deps/ox/src/ox/fs/filesystem/directory.hpp +++ b/deps/ox/src/ox/fs/filesystem/directory.hpp @@ -141,7 +141,7 @@ template Error Directory::init() noexcept { constexpr auto Size = sizeof(Buffer); oxTracef("ox.fs.Directory.init", "Initializing Directory with Inode ID: {}", m_inodeId); - oxReturnError(m_fs.write(m_inodeId, nullptr, Size, static_cast(FileType::Directory))); + OX_RETURN_ERROR(m_fs.write(m_inodeId, nullptr, Size, static_cast(FileType::Directory))); auto buff = m_fs.read(m_inodeId).template to(); if (!buff.valid()) { m_size = 0; @@ -158,7 +158,7 @@ Error Directory::mkdir(PathIterator path, bool parents) { oxTrace("ox.fs.Directory.mkdir", path.fullPath()); // determine if already exists ox::StringView name; - oxReturnError(path.get(name)); + OX_RETURN_ERROR(path.get(name)); auto childInode = find(PathIterator(name)); if (!childInode.ok()) { // if this is not the last item in the path and parents is disabled, @@ -169,10 +169,10 @@ Error Directory::mkdir(PathIterator path, bool parents) { childInode = m_fs.generateInodeId(); oxTracef("ox.fs.Directory.mkdir", "Generated Inode ID: {}", childInode.value); oxLogError(childInode.error); - oxReturnError(childInode.error); + OX_RETURN_ERROR(childInode.error); // initialize the directory Directory child(m_fs, childInode.value); - oxReturnError(child.init()); + OX_RETURN_ERROR(child.init()); auto err = write(PathIterator(name), childInode.value); if (err) { oxLogError(err); @@ -183,7 +183,7 @@ Error Directory::mkdir(PathIterator path, bool parents) { } Directory child(m_fs, childInode.value); if (path.hasNext()) { - oxReturnError(child.mkdir(path.next(), parents)); + OX_RETURN_ERROR(child.mkdir(path.next(), parents)); } } return {}; @@ -196,8 +196,8 @@ Error Directory::write(PathIterator path, uint64_t inode64 if (path.next().hasNext()) { // not yet at target directory, recurse to next one oxTracef("ox.fs.Directory.write", "Attempting to write to next sub-Directory: {} of {}", name, path.fullPath()); - oxReturnError(path.get(name)); - oxRequire(nextChild, findEntry(name)); + OX_RETURN_ERROR(path.get(name)); + OX_REQUIRE(nextChild, findEntry(name)); oxTracef("ox.fs.Directory.write", "{}: {}", name, nextChild); if (nextChild) { return Directory(m_fs, nextChild).write(path.next(), inode); @@ -207,12 +207,12 @@ Error Directory::write(PathIterator path, uint64_t inode64 } } else { oxTrace("ox.fs.Directory.write", path.fullPath()); - oxReturnError(path.next(name)); + OX_RETURN_ERROR(path.next(name)); // insert the new entry on this directory // get the name // find existing version of directory oxTracef("ox.fs.Directory.write", "Searching for directory inode {}", m_inodeId); - oxRequire(oldStat, m_fs.stat(m_inodeId)); + OX_REQUIRE(oldStat, m_fs.stat(m_inodeId)); oxTracef("ox.fs.Directory.write", "Found existing directory of size {}", oldStat.size); auto old = m_fs.read(m_inodeId).template to(); if (!old.valid()) { @@ -227,14 +227,14 @@ Error Directory::write(PathIterator path, uint64_t inode64 oxTrace("ox.fs.Directory.write.fail", "Could not allocate memory for copy of Directory"); return ox::Error(1, "Could not allocate memory for copy of Directory"); } - oxReturnError(cpy->setSize(newSize)); + OX_RETURN_ERROR(cpy->setSize(newSize)); auto val = cpy->malloc(entryDataSize).value; if (!val.valid()) { oxTrace("ox.fs.Directory.write.fail", "Could not allocate memory for new directory entry"); return ox::Error(1, "Could not allocate memory for new directory entry"); } oxTracef("ox.fs.Directory.write", "Attempting to write Directory entry: {}", name); - oxReturnError(val->init(inode, name, val.size())); + OX_RETURN_ERROR(val->init(inode, name, val.size())); return m_fs.write(m_inodeId, cpy.get(), cpy->size(), static_cast(FileType::Directory)); } } @@ -242,7 +242,7 @@ Error Directory::write(PathIterator path, uint64_t inode64 template Error Directory::remove(PathIterator path) noexcept { ox::StringView name; - oxReturnError(path.get(name)); + OX_RETURN_ERROR(path.get(name)); oxTrace("ox.fs.Directory.remove", name); auto buff = m_fs.read(m_inodeId).template to(); if (buff.valid()) { @@ -251,7 +251,7 @@ Error Directory::remove(PathIterator path) noexcept { auto data = i->data(); if (data.valid()) { if (name == data->name) { - oxReturnError(buff->free(i)); + OX_RETURN_ERROR(buff->free(i)); } } else { oxTrace("ox.fs.Directory.remove", "INVALID DIRECTORY ENTRY"); @@ -277,7 +277,7 @@ Error Directory::ls(F cb) noexcept { for (auto i = buff->iterator(); i.valid(); i.next()) { auto data = i->data(); if (data.valid()) { - oxReturnError(cb(data->name, data->inode)); + OX_RETURN_ERROR(cb(data->name, data->inode)); } else { oxTrace("ox.fs.Directory.ls", "INVALID DIRECTORY ENTRY"); } @@ -314,8 +314,8 @@ template Result Directory::find(PathIterator path) const noexcept { // determine if already exists ox::StringView name; - oxReturnError(path.get(name)); - oxRequire(v, findEntry(name)); + OX_RETURN_ERROR(path.get(name)); + OX_REQUIRE(v, findEntry(name)); // recurse if not at end of path if (auto p = path.next(); p.valid()) { Directory dir(m_fs, v); diff --git a/deps/ox/src/ox/fs/filesystem/filelocation.hpp b/deps/ox/src/ox/fs/filesystem/filelocation.hpp index ac6c8628..e106a1e2 100644 --- a/deps/ox/src/ox/fs/filesystem/filelocation.hpp +++ b/deps/ox/src/ox/fs/filesystem/filelocation.hpp @@ -154,29 +154,29 @@ constexpr const char *getModelTypeName() noexcept { template constexpr Error model(T *h, CommonPtrWith auto *obj) noexcept { - oxReturnError(h->template setTypeInfo()); - oxReturnError(h->fieldCString("path", &obj->path)); - oxReturnError(h->fieldCString("constPath", &obj->path)); - oxReturnError(h->field("inode", &obj->inode)); + OX_RETURN_ERROR(h->template setTypeInfo()); + OX_RETURN_ERROR(h->fieldCString("path", &obj->path)); + OX_RETURN_ERROR(h->fieldCString("constPath", &obj->path)); + OX_RETURN_ERROR(h->field("inode", &obj->inode)); return {}; } template constexpr Error model(T *h, CommonPtrWith auto *fa) noexcept { - oxReturnError(h->template setTypeInfo()); + OX_RETURN_ERROR(h->template setTypeInfo()); if constexpr(T::opType() == OpType::Reflect) { int8_t type = -1; - oxReturnError(h->field("type", &type)); - oxReturnError(h->field("data", UnionView(&fa->m_data, type))); + OX_RETURN_ERROR(h->field("type", &type)); + OX_RETURN_ERROR(h->field("data", UnionView(&fa->m_data, type))); } else if constexpr(T::opType() == OpType::Read) { auto type = static_cast(fa->m_type); - oxReturnError(h->field("type", &type)); + OX_RETURN_ERROR(h->field("type", &type)); fa->m_type = static_cast(type); - oxReturnError(h->field("data", UnionView(&fa->m_data, static_cast(fa->m_type)))); + OX_RETURN_ERROR(h->field("data", UnionView(&fa->m_data, static_cast(fa->m_type)))); } else if constexpr(T::opType() == OpType::Write) { auto const type = static_cast(fa->m_type); - oxReturnError(h->field("type", &type)); - oxReturnError(h->field("data", UnionView(&fa->m_data, static_cast(fa->m_type)))); + OX_RETURN_ERROR(h->field("type", &type)); + OX_RETURN_ERROR(h->field("data", UnionView(&fa->m_data, static_cast(fa->m_type)))); } return {}; } diff --git a/deps/ox/src/ox/fs/filesystem/filesystem.cpp b/deps/ox/src/ox/fs/filesystem/filesystem.cpp index e3e4e3af..9e097d38 100644 --- a/deps/ox/src/ox/fs/filesystem/filesystem.cpp +++ b/deps/ox/src/ox/fs/filesystem/filesystem.cpp @@ -38,16 +38,16 @@ Error FileSystem::read(const FileAddress &addr, void *buffer, std::size_t size) } Result FileSystem::read(const FileAddress &addr) noexcept { - oxRequire(s, stat(addr)); + OX_REQUIRE(s, stat(addr)); Buffer buff(static_cast(s.size)); - oxReturnError(read(addr, buff.data(), buff.size())); + OX_RETURN_ERROR(read(addr, buff.data(), buff.size())); return buff; } Result FileSystem::read(StringViewCR path) noexcept { - oxRequire(s, statPath(path)); + OX_REQUIRE(s, statPath(path)); Buffer buff(static_cast(s.size)); - oxReturnError(readFilePath(path, buff.data(), buff.size())); + OX_RETURN_ERROR(readFilePath(path, buff.data(), buff.size())); return buff; } diff --git a/deps/ox/src/ox/fs/filesystem/filesystem.hpp b/deps/ox/src/ox/fs/filesystem/filesystem.hpp index a0235736..0028e540 100644 --- a/deps/ox/src/ox/fs/filesystem/filesystem.hpp +++ b/deps/ox/src/ox/fs/filesystem/filesystem.hpp @@ -284,17 +284,17 @@ FileSystemTemplate::~FileSystemTemplate() noexcept { template Error FileSystemTemplate::format(void *buff, uint64_t buffSize) noexcept { - oxReturnError(FileStore::format(buff, static_cast(buffSize))); + OX_RETURN_ERROR(FileStore::format(buff, static_cast(buffSize))); FileStore fs(buff, static_cast(buffSize)); constexpr auto rootDirInode = MaxValue / 2; Directory rootDir(fs, rootDirInode); - oxReturnError(rootDir.init()); + OX_RETURN_ERROR(rootDir.init()); FileSystemData fd; fd.rootDirInode = rootDirInode; oxTracef("ox.fs.FileSystemTemplate.format", "rootDirInode: {}", fd.rootDirInode.get()); - oxReturnError(fs.write(InodeFsData, &fd, sizeof(fd))); + OX_RETURN_ERROR(fs.write(InodeFsData, &fd, sizeof(fd))); if (!fs.read(fd.rootDirInode).valid()) { oxTrace("ox.fs.FileSystemTemplate.format.error", "FileSystemTemplate::format did not correctly create root directory"); @@ -307,26 +307,26 @@ Error FileSystemTemplate::format(void *buff, uint64_t buff template Error FileSystemTemplate::mkdir(StringViewCR path, bool recursive) noexcept { oxTracef("ox.fs.FileSystemTemplate.mkdir", "path: {}, recursive: {}", path, recursive); - oxRequireM(rootDir, this->rootDir()); + OX_REQUIRE_M(rootDir, this->rootDir()); return rootDir.mkdir(path, recursive); } template Error FileSystemTemplate::move(StringViewCR src, StringViewCR dest) noexcept { - oxRequire(fd, fileSystemData()); + OX_REQUIRE(fd, fileSystemData()); Directory rootDir(m_fs, fd.rootDirInode); - oxRequireM(inode, rootDir.find(src)); - oxReturnError(rootDir.write(dest, inode)); - oxReturnError(rootDir.remove(src)); + OX_REQUIRE_M(inode, rootDir.find(src)); + OX_RETURN_ERROR(rootDir.write(dest, inode)); + OX_RETURN_ERROR(rootDir.remove(src)); return ox::Error(0); } template Error FileSystemTemplate::readFilePath(StringViewCR path, void *buffer, std::size_t buffSize) noexcept { oxTrace("ox.fs.FileSystemTemplate.readFilePath", path); - oxRequire(fd, fileSystemData()); + OX_REQUIRE(fd, fileSystemData()); Directory rootDir(m_fs, fd.rootDirInode); - oxRequire(s, stat(path)); + OX_REQUIRE(s, stat(path)); if (s.size > buffSize) { return ox::Error(1, "Buffer to small to load file"); } @@ -335,16 +335,16 @@ Error FileSystemTemplate::readFilePath(StringViewCR path, template Result FileSystemTemplate::directAccessPath(StringViewCR path) const noexcept { - oxRequire(fd, fileSystemData()); + OX_REQUIRE(fd, fileSystemData()); Directory rootDir(m_fs, fd.rootDirInode); - oxRequire(inode, rootDir.find(path)); + OX_REQUIRE(inode, rootDir.find(path)); return directAccessInode(inode); } template Error FileSystemTemplate::readFileInode(uint64_t inode, void *buffer, std::size_t buffSize) noexcept { oxTracef("ox.fs.FileSystemTemplate.readFileInode", "{}", inode); - oxRequire(s, stat(inode)); + OX_REQUIRE(s, stat(inode)); if (s.size > buffSize) { return ox::Error(1, "Buffer to small to load file"); } @@ -368,7 +368,7 @@ Result FileSystemTemplate::directAccessInode( template Result> FileSystemTemplate::ls(StringViewCR path) const noexcept { Vector out; - oxReturnError(ls(path, [&out](StringViewCR name, typename FileStore::InodeId_t) { + OX_RETURN_ERROR(ls(path, [&out](StringViewCR name, typename FileStore::InodeId_t) { out.emplace_back(name); return ox::Error(0); })); @@ -379,17 +379,17 @@ template template Error FileSystemTemplate::ls(StringViewCR path, F cb) const { oxTracef("ox.fs.FileSystemTemplate.ls", "path: {}", path); - oxRequire(s, stat(path)); + OX_REQUIRE(s, stat(path)); Directory dir(m_fs, s.inode); return dir.ls(cb); } template Error FileSystemTemplate::remove(StringViewCR path, bool recursive) noexcept { - oxRequire(fd, fileSystemData()); + OX_REQUIRE(fd, fileSystemData()); Directory rootDir(m_fs, fd.rootDirInode); - oxRequire(inode, rootDir.find(path)); - oxRequire(st, statInode(inode)); + OX_REQUIRE(inode, rootDir.find(path)); + OX_REQUIRE(st, statInode(inode)); if (st.fileType == FileType::NormalFile || recursive) { if (auto err = rootDir.remove(path)) { // removal failed, try putting the index back @@ -410,7 +410,7 @@ Error FileSystemTemplate::resize() noexcept { template Error FileSystemTemplate::resize(uint64_t size, void *buffer) noexcept { - oxReturnError(m_fs.resize(static_cast(size), buffer)); + OX_RETURN_ERROR(m_fs.resize(static_cast(size), buffer)); return {}; } @@ -423,11 +423,11 @@ Error FileSystemTemplate::writeFilePath( oxTrace("ox.fs.FileSystemTemplate.writeFilePath", path); auto [inode, err] = find(path); if (err) { - oxReturnError(m_fs.generateInodeId().moveTo(inode)); - oxRequireM(rootDir, this->rootDir()); - oxReturnError(rootDir.write(path, inode)); + OX_RETURN_ERROR(m_fs.generateInodeId().moveTo(inode)); + OX_REQUIRE_M(rootDir, this->rootDir()); + OX_RETURN_ERROR(rootDir.write(path, inode)); } - oxReturnError(writeFileInode(inode, buffer, size, fileType)); + OX_RETURN_ERROR(writeFileInode(inode, buffer, size, fileType)); return {}; } @@ -439,7 +439,7 @@ Error FileSystemTemplate::writeFileInode(uint64_t inode, c template Result FileSystemTemplate::statInode(uint64_t inode) const noexcept { - oxRequire(s, m_fs.stat(inode)); + OX_REQUIRE(s, m_fs.stat(inode)); FileStat out; out.inode = s.inode; out.links = s.links; @@ -450,7 +450,7 @@ Result FileSystemTemplate::statInode(uint64_t in template Result FileSystemTemplate::statPath(StringViewCR path) const noexcept { - oxRequire(inode, find(path)); + OX_REQUIRE(inode, find(path)); return stat(inode); } @@ -487,25 +487,25 @@ bool FileSystemTemplate::valid() const noexcept { template Result::FileSystemData> FileSystemTemplate::fileSystemData() const noexcept { FileSystemData fd; - oxReturnError(m_fs.read(InodeFsData, &fd, sizeof(fd))); + OX_RETURN_ERROR(m_fs.read(InodeFsData, &fd, sizeof(fd))); return fd; } template Result FileSystemTemplate::find(StringViewCR path) const noexcept { - oxRequire(fd, fileSystemData()); + OX_REQUIRE(fd, fileSystemData()); // return root as a special case if (path == "/") { return static_cast(fd.rootDirInode); } Directory rootDir(m_fs, fd.rootDirInode); - oxRequire(out, rootDir.find(path)); + OX_REQUIRE(out, rootDir.find(path)); return static_cast(out); } template Result FileSystemTemplate::rootDir() const noexcept { - oxRequire(fd, fileSystemData()); + OX_REQUIRE(fd, fileSystemData()); return Directory(m_fs, fd.rootDirInode); } diff --git a/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp b/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp index ef6a3d63..5217069d 100644 --- a/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp +++ b/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp @@ -39,7 +39,7 @@ Error PassThroughFS::mkdir(StringViewCR path, bool recursive) noexcept { success = true; } else { success = std::filesystem::create_directories(p, ec); - oxReturnError(ox::Error(static_cast(ec.value()), "PassThroughFS: mkdir failed")); + OX_RETURN_ERROR(ox::Error(static_cast(ec.value()), "PassThroughFS: mkdir failed")); } } else { std::error_code ec; @@ -48,7 +48,7 @@ Error PassThroughFS::mkdir(StringViewCR path, bool recursive) noexcept { success = true; } else { success = std::filesystem::create_directory(p, ec); - oxReturnError(ox::Error(static_cast(ec.value()), "PassThroughFS: mkdir failed")); + OX_RETURN_ERROR(ox::Error(static_cast(ec.value()), "PassThroughFS: mkdir failed")); } } return ox::Error(success ? 0 : 1); @@ -67,7 +67,7 @@ Result> PassThroughFS::ls(StringViewCR dir) const noexcept { Vector out; std::error_code ec; const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec); - oxReturnError(ox::Error(static_cast(ec.value()), "PassThroughFS: ls failed")); + OX_RETURN_ERROR(ox::Error(static_cast(ec.value()), "PassThroughFS: ls failed")); for (const auto &p : di) { const auto u8p = p.path().filename().u8string(); out.emplace_back(reinterpret_cast(u8p.c_str())); @@ -101,7 +101,7 @@ Result PassThroughFS::statPath(StringViewCR path) const noexcept { oxTracef("ox.fs.PassThroughFS.statInode", "{} {}", ec.message(), path); const uint64_t size = type == FileType::Directory ? 0 : std::filesystem::file_size(p, ec); oxTracef("ox.fs.PassThroughFS.statInode.size", "{} {}", path, size); - oxReturnError(ox::Error(static_cast(ec.value()), "PassThroughFS: stat failed")); + OX_RETURN_ERROR(ox::Error(static_cast(ec.value()), "PassThroughFS: stat failed")); return FileStat{0, 0, size, type}; } @@ -112,14 +112,14 @@ uint64_t PassThroughFS::spaceNeeded(uint64_t size) const noexcept { Result PassThroughFS::available() const noexcept { std::error_code ec; const auto s = std::filesystem::space(m_path, ec); - oxReturnError(ox::Error(static_cast(ec.value()), "PassThroughFS: could not get FS size")); + OX_RETURN_ERROR(ox::Error(static_cast(ec.value()), "PassThroughFS: could not get FS size")); return s.available; } Result PassThroughFS::size() const noexcept { std::error_code ec; const auto s = std::filesystem::space(m_path, ec); - oxReturnError(ox::Error(static_cast(ec.value()), "PassThroughFS: could not get FS size")); + OX_RETURN_ERROR(ox::Error(static_cast(ec.value()), "PassThroughFS: could not get FS size")); return s.capacity; } diff --git a/deps/ox/src/ox/fs/filesystem/passthroughfs.hpp b/deps/ox/src/ox/fs/filesystem/passthroughfs.hpp index ffd0d38b..19eeadb9 100644 --- a/deps/ox/src/ox/fs/filesystem/passthroughfs.hpp +++ b/deps/ox/src/ox/fs/filesystem/passthroughfs.hpp @@ -92,9 +92,9 @@ template Error PassThroughFS::ls(StringViewCR dir, F cb) const noexcept { std::error_code ec; const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec); - oxReturnError(ox::Error(static_cast(ec.value()), "PassThroughFS: ls failed")); + OX_RETURN_ERROR(ox::Error(static_cast(ec.value()), "PassThroughFS: ls failed")); for (auto &p : di) { - oxReturnError(cb(p.path().filename().c_str(), 0)); + OX_RETURN_ERROR(cb(p.path().filename().c_str(), 0)); } return ox::Error(0); } diff --git a/deps/ox/src/ox/fs/ptrarith/nodebuffer.hpp b/deps/ox/src/ox/fs/ptrarith/nodebuffer.hpp index 6030a18e..4f7b44e7 100644 --- a/deps/ox/src/ox/fs/ptrarith/nodebuffer.hpp +++ b/deps/ox/src/ox/fs/ptrarith/nodebuffer.hpp @@ -408,7 +408,7 @@ Error NodeBuffer::compact(F cb) noexcept { } // move node ox::memcpy(dest, src, src->fullSize()); - oxReturnError(cb(src, dest)); + OX_RETURN_ERROR(cb(src, dest)); // update surrounding nodes auto prev = ptr(dest->prev); if (prev.valid()) { diff --git a/deps/ox/src/ox/fs/tool.cpp b/deps/ox/src/ox/fs/tool.cpp index 479aa070..82e4b4c6 100644 --- a/deps/ox/src/ox/fs/tool.cpp +++ b/deps/ox/src/ox/fs/tool.cpp @@ -35,7 +35,7 @@ static ox::Result loadFsBuff(const char *path) noexcept { } static ox::Result> loadFs(const char *path) noexcept { - oxRequire(buff, loadFsBuff(path)); + OX_REQUIRE(buff, loadFsBuff(path)); return {ox::make_unique(buff.data, buff.size)}; } @@ -44,7 +44,7 @@ static ox::Error runLs(ox::FileSystem *fs, ox::Span args) noexcept oxErr("Must provide a directory to ls\n"); return ox::Error(1); } - oxRequire(files, fs->ls(args[1])); + OX_REQUIRE(files, fs->ls(args[1])); for (const auto &file : files) { oxOutf("{}\n", file); } @@ -56,7 +56,7 @@ static ox::Error runRead(ox::FileSystem *fs, ox::Span args) noexcep oxErr("Must provide a path to a file to read\n"); return ox::Error(1); } - oxRequire(buff, fs->read(ox::StringView(args[1]))); + OX_REQUIRE(buff, fs->read(ox::StringView(args[1]))); std::ignore = fwrite(buff.data(), sizeof(decltype(buff)::value_type), buff.size(), stdout); return ox::Error(0); } @@ -69,7 +69,7 @@ static ox::Error run(int argc, const char **argv) noexcept { auto const args = ox::Span{argv, static_cast(argc)}; auto const fsPath = args[1]; ox::String subCmd(args[2]); - oxRequire(fs, loadFs(fsPath)); + OX_REQUIRE(fs, loadFs(fsPath)); if (subCmd == "ls") { return runLs(fs.get(), args + 2); } else if (subCmd == "read") { diff --git a/deps/ox/src/ox/logconn/logconn.cpp b/deps/ox/src/ox/logconn/logconn.cpp index 2b4e6ba9..6bec2997 100644 --- a/deps/ox/src/ox/logconn/logconn.cpp +++ b/deps/ox/src/ox/logconn/logconn.cpp @@ -64,7 +64,7 @@ ox::Error LoggerConn::initConn(ox::StringViewCR appName) noexcept { addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_port = htons(5590); m_socket = static_cast(socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)); - oxReturnError(ox::Error(static_cast(connect(static_cast(m_socket), reinterpret_cast(&addr), sizeof(addr))))); + OX_RETURN_ERROR(ox::Error(static_cast(connect(static_cast(m_socket), reinterpret_cast(&addr), sizeof(addr))))); return sendInit({.appName = ox::BasicString<128>(appName)}); } diff --git a/deps/ox/src/ox/logconn/logconn.hpp b/deps/ox/src/ox/logconn/logconn.hpp index 8a2b3ae4..fc143698 100644 --- a/deps/ox/src/ox/logconn/logconn.hpp +++ b/deps/ox/src/ox/logconn/logconn.hpp @@ -45,13 +45,13 @@ class LoggerConn: public trace::Logger { ox::Error send(trace::MsgId msgId, const auto &msg) noexcept { ox::Array buff; std::size_t sz = 0; - oxReturnError(ox::writeMC(&buff[0], buff.size(), msg, &sz)); + OX_RETURN_ERROR(ox::writeMC(&buff[0], buff.size(), msg, &sz)); //std::printf("sz: %lu\n", sz); - oxRequire(szBuff, serialize(static_cast(sz))); + OX_REQUIRE(szBuff, serialize(static_cast(sz))); std::unique_lock buffLk(m_buffMut); - oxReturnError(m_buff.put(static_cast(msgId))); - oxReturnError(m_buff.write(szBuff.data(), szBuff.size())); - oxReturnError(m_buff.write(buff.data(), sz)); + OX_RETURN_ERROR(m_buff.put(static_cast(msgId))); + OX_RETURN_ERROR(m_buff.write(szBuff.data(), szBuff.size())); + OX_RETURN_ERROR(m_buff.write(buff.data(), sz)); buffLk.unlock(); m_waitCond.notify_one(); return {}; diff --git a/deps/ox/src/ox/mc/intops.hpp b/deps/ox/src/ox/mc/intops.hpp index 567af5c6..6e8f6858 100644 --- a/deps/ox/src/ox/mc/intops.hpp +++ b/deps/ox/src/ox/mc/intops.hpp @@ -135,19 +135,19 @@ static_assert(countBytes(0b1111'1111) == 9); template constexpr Result decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noexcept { uint8_t firstByte = 0; - oxReturnError(rdr.read(&firstByte, 1)); - oxReturnError(rdr.seekg(-1, ox::ios_base::cur)); + OX_RETURN_ERROR(rdr.read(&firstByte, 1)); + OX_RETURN_ERROR(rdr.seekg(-1, ox::ios_base::cur)); const auto bytes = countBytes(firstByte); if (bytes == 9) { *bytesRead = bytes; I out = 0; - oxReturnError(rdr.seekg(1, ox::ios_base::cur)); - oxReturnError(rdr.read(&out, sizeof(I))); + OX_RETURN_ERROR(rdr.seekg(1, ox::ios_base::cur)); + OX_RETURN_ERROR(rdr.read(&out, sizeof(I))); return fromLittleEndian(out); } *bytesRead = bytes; uint64_t decoded = 0; - oxReturnError(rdr.read(&decoded, bytes)); + OX_RETURN_ERROR(rdr.read(&decoded, bytes)); decoded >>= bytes; // move sign bit if constexpr(is_signed_v) { diff --git a/deps/ox/src/ox/mc/presenceindicator.hpp b/deps/ox/src/ox/mc/presenceindicator.hpp index 44a17a84..6f68e5b1 100644 --- a/deps/ox/src/ox/mc/presenceindicator.hpp +++ b/deps/ox/src/ox/mc/presenceindicator.hpp @@ -47,7 +47,7 @@ constexpr Result FieldBitmapReader::get(std::size_t idx) const noe constexpr auto blockBits = sizeof(m_mapBlock); auto const blockIdx = idx / blockBits; if (m_mapBlockIdx != blockIdx) [[unlikely]] { - oxReturnError(loadMapBlock(blockIdx)); + OX_RETURN_ERROR(loadMapBlock(blockIdx)); } idx %= blockBits; return (m_mapBlock >> idx) & 1; @@ -55,12 +55,12 @@ constexpr Result FieldBitmapReader::get(std::size_t idx) const noe template constexpr ox::Error FieldBitmapReader::loadMapBlock(std::size_t idx) const noexcept { - oxRequire(g, m_reader.tellg()); - oxReturnError(m_reader.seekg(static_cast(m_mapStart + idx), ox::ios_base::beg)); + OX_REQUIRE(g, m_reader.tellg()); + OX_RETURN_ERROR(m_reader.seekg(static_cast(m_mapStart + idx), ox::ios_base::beg)); ox::Array mapBlock{}; - oxReturnError(m_reader.read(mapBlock.data(), sizeof(m_mapBlock))); + OX_RETURN_ERROR(m_reader.read(mapBlock.data(), sizeof(m_mapBlock))); // Warning: narrow-conv - oxReturnError(m_reader.seekg(static_cast(g), ox::ios_base::beg)); + OX_RETURN_ERROR(m_reader.seekg(static_cast(g), ox::ios_base::beg)); m_mapBlock = 0; for (auto i = 0ull; auto b : mapBlock) { m_mapBlock |= static_cast(std::bit_cast(b)) << i; diff --git a/deps/ox/src/ox/mc/read.hpp b/deps/ox/src/ox/mc/read.hpp index 2e849fb0..abb6c39e 100644 --- a/deps/ox/src/ox/mc/read.hpp +++ b/deps/ox/src/ox/mc/read.hpp @@ -194,7 +194,7 @@ constexpr Error MetalClawReaderTemplate::field(const char*, bool *val) n if (!m_unionIdx.has_value() || static_cast(*m_unionIdx) == m_field) { auto const result = m_fieldPresence.get(static_cast(m_field)); *val = result.value; - oxReturnError(result); + OX_RETURN_ERROR(result); } ++m_field; return ox::Error(0); @@ -207,15 +207,15 @@ constexpr Error MetalClawReaderTemplate::field(const char *name, auto *v if (m_fieldPresence.get(static_cast(m_field))) { // read the length std::size_t bytesRead = 0; - oxRequire(len, mc::decodeInteger(m_reader, &bytesRead)); + OX_REQUIRE(len, mc::decodeInteger(m_reader, &bytesRead)); // read the list if (valLen >= len) { auto reader = child({}); auto &handler = *reader.interface(); - oxReturnError(handler.setTypeInfo("List", 0, {}, static_cast(len))); + OX_RETURN_ERROR(handler.setTypeInfo("List", 0, {}, static_cast(len))); for (std::size_t i = 0; i < len; ++i) { OX_ALLOW_UNSAFE_BUFFERS_BEGIN - oxReturnError(handler.field({}, &val[i])); + OX_RETURN_ERROR(handler.field({}, &val[i])); OX_ALLOW_UNSAFE_BUFFERS_END } } else { @@ -234,24 +234,24 @@ constexpr Error MetalClawReaderTemplate::field(const char*, HashMap(*m_unionIdx) == m_field) { if (m_fieldPresence.get(static_cast(m_field))) { // read the length - oxRequire(g, m_reader.tellg()); + OX_REQUIRE(g, m_reader.tellg()); std::size_t bytesRead = 0; - oxRequire(len, mc::decodeInteger(m_reader, &bytesRead)); - oxReturnError(m_reader.seekg(g)); + OX_REQUIRE(len, mc::decodeInteger(m_reader, &bytesRead)); + OX_RETURN_ERROR(m_reader.seekg(g)); // read the list auto reader = child(""); auto &handler = *reader.interface(); - oxReturnError(handler.setTypeInfo("List", 0, {}, static_cast(len))); + OX_RETURN_ERROR(handler.setTypeInfo("List", 0, {}, static_cast(len))); // this loop body needs to be in a lambda because of the potential alloca call constexpr auto loopBody = [](auto &handler, auto &val) { - oxRequire(keyLen, handler.stringLength(nullptr)); + OX_REQUIRE(keyLen, handler.stringLength(nullptr)); auto wkey = ox_malloca(keyLen + 1, char, 0); auto wkeyPtr = wkey.get(); - oxReturnError(handler.fieldCString("", &wkeyPtr, keyLen + 1)); + OX_RETURN_ERROR(handler.fieldCString("", &wkeyPtr, keyLen + 1)); return handler.field("", &val[wkeyPtr]); }; for (std::size_t i = 0; i < len; ++i) { - oxReturnError(loopBody(handler, *val)); + OX_RETURN_ERROR(loopBody(handler, *val)); } } } @@ -266,11 +266,11 @@ constexpr Error MetalClawReaderTemplate::field(const char *name, T *val) if (!m_unionIdx.has_value() || static_cast(*m_unionIdx) == m_field) { // set size of val if the field is present, don't worry about it if not if (m_fieldPresence.get(static_cast(m_field))) { - oxRequire(len, arrayLength(name, false)); - oxReturnError(ox::resizeVector(*val, len)); + OX_REQUIRE(len, arrayLength(name, false)); + OX_RETURN_ERROR(ox::resizeVector(*val, len)); return field(name, val->data(), val->size()); } - oxReturnError(ox::resizeVector(*val, 0)); + OX_RETURN_ERROR(ox::resizeVector(*val, 0)); } ++m_field; return {}; @@ -278,7 +278,7 @@ constexpr Error MetalClawReaderTemplate::field(const char *name, T *val) if (!m_unionIdx.has_value() || static_cast(*m_unionIdx) == m_field) { // set size of val if the field is present, don't worry about it if not if (m_fieldPresence.get(static_cast(m_field))) { - oxRequire(len, arrayLength(name, false)); + OX_REQUIRE(len, arrayLength(name, false)); if (len > val->size()) { return ox::Error(1, "Input array is too long"); } @@ -291,7 +291,7 @@ constexpr Error MetalClawReaderTemplate::field(const char *name, T *val) if ((!m_unionIdx.has_value() || static_cast(*m_unionIdx) == m_field) && val) { if (m_fieldPresence.get(static_cast(m_field))) { auto reader = child(""); - oxReturnError(model(reader.interface(), val)); + OX_RETURN_ERROR(model(reader.interface(), val)); } } ++m_field; @@ -305,7 +305,7 @@ constexpr Error MetalClawReaderTemplate::field(const char*, UnionView(*m_unionIdx) == m_field) && val.get()) { if (m_fieldPresence.get(static_cast(m_field))) { auto reader = child("", ox::Optional(ox::in_place, val.idx())); - oxReturnError(model(reader.interface(), val.get())); + OX_RETURN_ERROR(model(reader.interface(), val.get())); } } ++m_field; @@ -319,12 +319,12 @@ constexpr Error MetalClawReaderTemplate::field(const char*, BasicString< if (m_fieldPresence.get(static_cast(m_field))) { // read the length std::size_t bytesRead = 0; - oxRequire(size, mc::decodeInteger(m_reader, &bytesRead)); + OX_REQUIRE(size, mc::decodeInteger(m_reader, &bytesRead)); const auto cap = size; *val = BasicString(cap); auto data = val->data(); // read the string - oxReturnError(m_reader.read(data, size)); + OX_RETURN_ERROR(m_reader.read(data, size)); } else { *val = ""; } @@ -340,12 +340,12 @@ constexpr Error MetalClawReaderTemplate::field(const char*, IString * if (m_fieldPresence.get(static_cast(m_field))) { // read the length std::size_t bytesRead = 0; - oxRequire(size, mc::decodeInteger(m_reader, &bytesRead)); + OX_REQUIRE(size, mc::decodeInteger(m_reader, &bytesRead)); *val = IString(); - oxReturnError(val->resize(size)); + OX_RETURN_ERROR(val->resize(size)); auto const data = val->data(); // read the string - oxReturnError(m_reader.read(data, size)); + OX_RETURN_ERROR(m_reader.read(data, size)); } else { *val = ""; } @@ -359,14 +359,14 @@ constexpr Error MetalClawReaderTemplate::fieldCString(const char*, char if (m_fieldPresence.get(static_cast(m_field))) { // read the length std::size_t bytesRead = 0; - oxRequire(size, mc::decodeInteger(m_reader, &bytesRead)); + OX_REQUIRE(size, mc::decodeInteger(m_reader, &bytesRead)); if (size > buffLen) { return ox::Error(McOutputBuffEnded); } // re-allocate in case too small auto data = val; // read the string - oxReturnError(m_reader.read(data, size)); + OX_RETURN_ERROR(m_reader.read(data, size)); data[size] = 0; } ++m_field; @@ -378,13 +378,13 @@ constexpr Error MetalClawReaderTemplate::fieldCString(const char*, char if (m_fieldPresence.get(static_cast(m_field))) { // read the length std::size_t bytesRead = 0; - oxRequire(size, mc::decodeInteger(m_reader, &bytesRead)); + OX_REQUIRE(size, mc::decodeInteger(m_reader, &bytesRead)); // re-allocate in case too small safeDelete(*val); *val = new char[size + 1]; auto data = ox::Span{*val, size + 1}; // read the string - oxReturnError(m_reader.read(data.data(), size)); + OX_RETURN_ERROR(m_reader.read(data.data(), size)); data[size] = 0; } ++m_field; @@ -397,7 +397,7 @@ constexpr Error MetalClawReaderTemplate::fieldCString(const char*, char if (m_fieldPresence.get(static_cast(m_field))) { // read the length std::size_t bytesRead = 0; - oxRequire(size, mc::decodeInteger(m_reader, &bytesRead)); + OX_REQUIRE(size, mc::decodeInteger(m_reader, &bytesRead)); // re-allocate if too small if (buffLen < size + 1) { safeDelete(*val); @@ -406,7 +406,7 @@ constexpr Error MetalClawReaderTemplate::fieldCString(const char*, char } auto data = ox::Span{*val, size + 1}; // read the string - oxReturnError(m_reader.read(data.data(), size)); + OX_RETURN_ERROR(m_reader.read(data.data(), size)); data[size] = 0; } else { auto data = *val; @@ -425,10 +425,10 @@ constexpr Result MetalClawReaderTemplate::arrayLength(const if (m_fieldPresence.get(static_cast(m_field))) { // read the length std::size_t bytesRead = 0; - oxRequire(g, m_reader.tellg()); - oxRequire(out, mc::decodeInteger(m_reader, &bytesRead)); + OX_REQUIRE(g, m_reader.tellg()); + OX_REQUIRE(out, mc::decodeInteger(m_reader, &bytesRead)); if (!pass) { - oxReturnError(m_reader.seekg(g)); + OX_RETURN_ERROR(m_reader.seekg(g)); } return out; } @@ -443,7 +443,7 @@ constexpr Result MetalClawReaderTemplate::stringLength(con // read the length std::size_t bytesRead = 0; auto len = mc::decodeInteger(m_reader, &bytesRead); - oxReturnError(m_reader.seekg(-static_cast(bytesRead), ox::ios_base::cur)); + OX_RETURN_ERROR(m_reader.seekg(-static_cast(bytesRead), ox::ios_base::cur)); return len; } } @@ -457,7 +457,7 @@ constexpr Error MetalClawReaderTemplate::readInteger(I *val) noexcept { if (m_fieldPresence.get(static_cast(m_field))) { std::size_t bytesRead = 0; auto const result = mc::decodeInteger(m_reader, &bytesRead); - oxReturnError(result); + OX_RETURN_ERROR(result); *val = result.value; } else { *val = 0; @@ -474,15 +474,15 @@ constexpr Error MetalClawReaderTemplate::field(const char*, CB cb) noexc if (m_fieldPresence.get(static_cast(m_field))) { // read the length std::size_t bytesRead = 0; - oxRequire(len, mc::decodeInteger(m_reader, &bytesRead)); + OX_REQUIRE(len, mc::decodeInteger(m_reader, &bytesRead)); // read the list auto reader = child(""); auto &handler = *reader.interface(); - oxReturnError(handler.setTypeInfo("List", 0, {}, static_cast(len))); + OX_RETURN_ERROR(handler.setTypeInfo("List", 0, {}, static_cast(len))); for (std::size_t i = 0; i < len; ++i) { T val; - oxReturnError(handler.field("", &val)); - oxReturnError(cb(i, &val)); + OX_RETURN_ERROR(handler.field("", &val)); + OX_RETURN_ERROR(cb(i, &val)); } } } @@ -548,7 +548,7 @@ Error readMC(ox::BufferView buff, T &val) noexcept { template Result readMC(ox::BufferView buff) noexcept { Result val; - oxReturnError(readMC(buff, val.value)); + OX_RETURN_ERROR(readMC(buff, val.value)); return val; } diff --git a/deps/ox/src/ox/mc/test/tests.cpp b/deps/ox/src/ox/mc/test/tests.cpp index 4e4b4f19..e795ba37 100644 --- a/deps/ox/src/ox/mc/test/tests.cpp +++ b/deps/ox/src/ox/mc/test/tests.cpp @@ -62,46 +62,46 @@ struct TestStruct { template constexpr ox::Error model(T *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("Bool", &obj->Bool)); - oxReturnError(io->field("Int", &obj->Int)); - oxReturnError(io->fieldCString("CString", &obj->CString)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("Bool", &obj->Bool)); + OX_RETURN_ERROR(io->field("Int", &obj->Int)); + OX_RETURN_ERROR(io->fieldCString("CString", &obj->CString)); return ox::Error(0); } -oxModelBegin(TestStructNest) - oxModelField(Bool) - oxModelField(Int) - oxModelField(IString) -oxModelEnd() +OX_MODEL_BEGIN(TestStructNest) + OX_MODEL_FIELD(Bool) + OX_MODEL_FIELD(Int) + OX_MODEL_FIELD(IString) +OX_MODEL_END() template constexpr ox::Error model(T *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("Bool", &obj->Bool)); - oxReturnError(io->field("Int", &obj->Int)); - oxReturnError(io->field("Int1", &obj->Int1)); - oxReturnError(io->field("Int2", &obj->Int2)); - oxReturnError(io->field("Int3", &obj->Int3)); - oxReturnError(io->field("Int4", &obj->Int4)); - oxReturnError(io->field("Int5", &obj->Int5)); - oxReturnError(io->field("Int6", &obj->Int6)); - oxReturnError(io->field("Int7", &obj->Int7)); - oxReturnError(io->field("Int8", &obj->Int8)); - oxReturnError(io->field("unionIdx", &obj->unionIdx)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("Bool", &obj->Bool)); + OX_RETURN_ERROR(io->field("Int", &obj->Int)); + OX_RETURN_ERROR(io->field("Int1", &obj->Int1)); + OX_RETURN_ERROR(io->field("Int2", &obj->Int2)); + OX_RETURN_ERROR(io->field("Int3", &obj->Int3)); + OX_RETURN_ERROR(io->field("Int4", &obj->Int4)); + OX_RETURN_ERROR(io->field("Int5", &obj->Int5)); + OX_RETURN_ERROR(io->field("Int6", &obj->Int6)); + OX_RETURN_ERROR(io->field("Int7", &obj->Int7)); + OX_RETURN_ERROR(io->field("Int8", &obj->Int8)); + OX_RETURN_ERROR(io->field("unionIdx", &obj->unionIdx)); if constexpr(T::opType() == ox::OpType::Reflect) { - oxReturnError(io->field("Union", ox::UnionView{&obj->Union, 0})); + OX_RETURN_ERROR(io->field("Union", ox::UnionView{&obj->Union, 0})); } else { - oxReturnError(io->field("Union", ox::UnionView{&obj->Union, obj->unionIdx})); + OX_RETURN_ERROR(io->field("Union", ox::UnionView{&obj->Union, obj->unionIdx})); } - oxReturnError(io->field("String", &obj->String)); - oxReturnError(io->field("IString", &obj->IString)); - oxReturnError(io->field("List", obj->List, 4)); - oxReturnError(io->field("Vector", &obj->Vector)); - oxReturnError(io->field("Vector2", &obj->Vector2)); - oxReturnError(io->field("Map", &obj->Map)); - oxReturnError(io->field("Struct", &obj->Struct)); - oxReturnError(io->field("EmptyStruct", &obj->EmptyStruct)); + OX_RETURN_ERROR(io->field("String", &obj->String)); + OX_RETURN_ERROR(io->field("IString", &obj->IString)); + OX_RETURN_ERROR(io->field("List", obj->List, 4)); + OX_RETURN_ERROR(io->field("Vector", &obj->Vector)); + OX_RETURN_ERROR(io->field("Vector2", &obj->Vector2)); + OX_RETURN_ERROR(io->field("Map", &obj->Map)); + OX_RETURN_ERROR(io->field("Struct", &obj->Struct)); + OX_RETURN_ERROR(io->field("EmptyStruct", &obj->EmptyStruct)); return ox::Error(0); } @@ -114,8 +114,8 @@ std::map tests = { // doesn't segfault ox::Array buff; TestStruct ts; - oxReturnError(ox::writeMC(buff.data(), buff.size(), ts)); - oxReturnError(ox::writeMC(ts)); + OX_RETURN_ERROR(ox::writeMC(buff.data(), buff.size(), ts)); + OX_RETURN_ERROR(ox::writeMC(ts)); return ox::Error(0); } }, @@ -260,7 +260,7 @@ std::map tests = { using ox::mc::decodeInteger; static constexpr auto check = [](auto val) { auto result = decodeInteger(encodeInteger(val)); - oxReturnError(result.error); + OX_RETURN_ERROR(result.error); if (result.value != val) { std::cout << "Bad value: " << result.value << ", expected: " << val << '\n'; return ox::Error(1); @@ -319,7 +319,7 @@ std::map tests = { const auto [type, typeErr] = ox::buildTypeDef(typeStore, testIn); oxAssert(typeErr, "Descriptor write failed"); ox::ModelObject testOut; - oxReturnError(testOut.setType(type)); + OX_RETURN_ERROR(testOut.setType(type)); oxAssert(ox::readMC(dataBuff, testOut), "Data read failed"); oxAssert(testOut.at("Int").unwrap()->get() == testIn.Int, "testOut.Int failed"); oxAssert(testOut.at("Bool").unwrap()->get() == testIn.Bool, "testOut.Bool failed"); @@ -371,7 +371,7 @@ std::map tests = { const auto [type, typeErr] = ox::buildTypeDef(typeStore, testIn); oxAssert(typeErr, "Descriptor write failed"); ox::BufferReader br({dataBuff, dataBuffLen}); - oxReturnError(ox::walkModel(type, br, + OX_RETURN_ERROR(ox::walkModel(type, br, [](const ox::Vector&, const ox::Vector&, const ox::DescriptorField &f, ox::MetalClawReader *rdr) -> ox::Error { //std::cout << f.fieldName.c_str() << '\n'; auto fieldName = f.fieldName.c_str(); diff --git a/deps/ox/src/ox/mc/write.hpp b/deps/ox/src/ox/mc/write.hpp index ffbfd022..cfc1a587 100644 --- a/deps/ox/src/ox/mc/write.hpp +++ b/deps/ox/src/ox/mc/write.hpp @@ -117,10 +117,10 @@ class MetalClawWriter { bool fieldSet = false; if (val && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) { auto mi = mc::encodeInteger(val); - oxReturnError(m_writer.write(reinterpret_cast(mi.data.data()), mi.length)); + OX_RETURN_ERROR(m_writer.write(reinterpret_cast(mi.data.data()), mi.length)); fieldSet = true; } - oxReturnError(m_fieldPresence.set(static_cast(m_field), fieldSet)); + OX_RETURN_ERROR(m_fieldPresence.set(static_cast(m_field), fieldSet)); ++m_field; return ox::Error(0); } @@ -181,7 +181,7 @@ constexpr Error MetalClawWriter::field(const char*, const uint64_t *val) template constexpr Error MetalClawWriter::field(const char*, const bool *val) noexcept { if (!m_unionIdx.has_value() || *m_unionIdx == m_field) { - oxReturnError(m_fieldPresence.set(static_cast(m_field), *val)); + OX_RETURN_ERROR(m_fieldPresence.set(static_cast(m_field), *val)); } ++m_field; return ox::Error(0); @@ -194,12 +194,12 @@ constexpr Error MetalClawWriter::field(const char*, const BasicStringlen() && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) { // write the length const auto strLen = mc::encodeInteger(val->len()); - oxReturnError(m_writer.write(reinterpret_cast(strLen.data.data()), strLen.length)); + OX_RETURN_ERROR(m_writer.write(reinterpret_cast(strLen.data.data()), strLen.length)); // write the string - oxReturnError(m_writer.write(val->c_str(), static_cast(val->len()))); + OX_RETURN_ERROR(m_writer.write(val->c_str(), static_cast(val->len()))); fieldSet = true; } - oxReturnError(m_fieldPresence.set(static_cast(m_field), fieldSet)); + OX_RETURN_ERROR(m_fieldPresence.set(static_cast(m_field), fieldSet)); ++m_field; return ox::Error(0); } @@ -217,12 +217,12 @@ constexpr Error MetalClawWriter::fieldCString(const char*, const char *c const auto strLen = *val ? ox::strlen(*val) : 0; // write the length const auto strLenBuff = mc::encodeInteger(strLen); - oxReturnError(m_writer.write(reinterpret_cast(strLenBuff.data.data()), strLenBuff.length)); + OX_RETURN_ERROR(m_writer.write(reinterpret_cast(strLenBuff.data.data()), strLenBuff.length)); // write the string - oxReturnError(m_writer.write(*val, static_cast(strLen))); + OX_RETURN_ERROR(m_writer.write(*val, static_cast(strLen))); fieldSet = true; } - oxReturnError(m_fieldPresence.set(static_cast(m_field), fieldSet)); + OX_RETURN_ERROR(m_fieldPresence.set(static_cast(m_field), fieldSet)); ++m_field; return ox::Error(0); } @@ -243,12 +243,12 @@ constexpr Error MetalClawWriter::fieldCString(const char*, const char *v if (strLen && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) { // write the length const auto strLenBuff = mc::encodeInteger(strLen); - oxReturnError(m_writer.write(reinterpret_cast(strLenBuff.data.data()), strLenBuff.length)); + OX_RETURN_ERROR(m_writer.write(reinterpret_cast(strLenBuff.data.data()), strLenBuff.length)); // write the string - oxReturnError(m_writer.write(val, static_cast(strLen))); + OX_RETURN_ERROR(m_writer.write(val, static_cast(strLen))); fieldSet = true; } - oxReturnError(m_fieldPresence.set(static_cast(m_field), fieldSet)); + OX_RETURN_ERROR(m_fieldPresence.set(static_cast(m_field), fieldSet)); ++m_field; return ox::Error(0); } @@ -264,11 +264,11 @@ constexpr Error MetalClawWriter::field(const char*, const T *val) noexce auto const writeIdx = m_writer.tellp(); MetalClawWriter writer(m_writer); ModelHandlerInterface> handler{&writer}; - oxReturnError(model(&handler, val)); - oxReturnError(writer.finalize()); + OX_RETURN_ERROR(model(&handler, val)); + OX_RETURN_ERROR(writer.finalize()); fieldSet = writeIdx != m_writer.tellp(); } - oxReturnError(m_fieldPresence.set(static_cast(m_field), fieldSet)); + OX_RETURN_ERROR(m_fieldPresence.set(static_cast(m_field), fieldSet)); ++m_field; return {}; } @@ -282,11 +282,11 @@ constexpr Error MetalClawWriter::field(const char*, UnionView auto const writeIdx = m_writer.tellp(); MetalClawWriter writer(m_writer, ox::Optional(ox::in_place, val.idx())); ModelHandlerInterface handler{&writer}; - oxReturnError(model(&handler, val.get())); - oxReturnError(writer.finalize()); + OX_RETURN_ERROR(model(&handler, val.get())); + OX_RETURN_ERROR(writer.finalize()); fieldSet = writeIdx != m_writer.tellp(); } - oxReturnError(m_fieldPresence.set(static_cast(m_field), fieldSet)); + OX_RETURN_ERROR(m_fieldPresence.set(static_cast(m_field), fieldSet)); ++m_field; return {}; } @@ -298,21 +298,21 @@ constexpr Error MetalClawWriter::field(const char*, const T *val, std::s if (len && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) { // write the length const auto arrLen = mc::encodeInteger(len); - oxReturnError(m_writer.write(reinterpret_cast(arrLen.data.data()), arrLen.length)); + OX_RETURN_ERROR(m_writer.write(reinterpret_cast(arrLen.data.data()), arrLen.length)); auto const writeIdx = m_writer.tellp(); MetalClawWriter writer(m_writer); ModelHandlerInterface handler{&writer}; - oxReturnError(handler.template setTypeInfo("List", 0, {}, static_cast(len))); + OX_RETURN_ERROR(handler.template setTypeInfo("List", 0, {}, static_cast(len))); // write the array for (std::size_t i = 0; i < len; ++i) { OX_ALLOW_UNSAFE_BUFFERS_BEGIN - oxReturnError(handler.field("", &val[i])); + OX_RETURN_ERROR(handler.field("", &val[i])); OX_ALLOW_UNSAFE_BUFFERS_END } - oxReturnError(writer.finalize()); + OX_RETURN_ERROR(writer.finalize()); fieldSet = writeIdx != m_writer.tellp(); } - oxReturnError(m_fieldPresence.set(static_cast(m_field), fieldSet)); + OX_RETURN_ERROR(m_fieldPresence.set(static_cast(m_field), fieldSet)); ++m_field; return ox::Error(0); } @@ -326,30 +326,30 @@ constexpr Error MetalClawWriter::field(const char*, const HashMap(arrLen.data.data()), arrLen.length)); + OX_RETURN_ERROR(m_writer.write(reinterpret_cast(arrLen.data.data()), arrLen.length)); // write map MetalClawWriter writer(m_writer); ModelHandlerInterface handler{&writer}; // double len for both key and value - oxReturnError(handler.setTypeInfo("Map", 0, {}, len * 2)); + OX_RETURN_ERROR(handler.setTypeInfo("Map", 0, {}, len * 2)); // this loop body needs to be in a lambda because of the potential alloca call constexpr auto loopBody = [](auto &handler, auto const&key, auto const&val) -> ox::Error { const auto keyLen = key.len(); auto wkey = ox_malloca(keyLen + 1, char, 0); memcpy(wkey.get(), key.c_str(), keyLen + 1); - oxReturnError(handler.fieldCString("", wkey.get(), keyLen)); - oxRequireM(value, val.at(key)); + OX_RETURN_ERROR(handler.fieldCString("", wkey.get(), keyLen)); + OX_REQUIRE_M(value, val.at(key)); return handler.field("", value); }; // write the array for (std::size_t i = 0; i < len; ++i) { auto const&key = keys[i]; - oxReturnError(loopBody(handler, key, *val)); + OX_RETURN_ERROR(loopBody(handler, key, *val)); } - oxReturnError(writer.finalize()); + OX_RETURN_ERROR(writer.finalize()); fieldSet = true; } - oxReturnError(m_fieldPresence.set(static_cast(m_field), fieldSet)); + OX_RETURN_ERROR(m_fieldPresence.set(static_cast(m_field), fieldSet)); ++m_field; return ox::Error(0); } @@ -362,7 +362,7 @@ constexpr ox::Error MetalClawWriter::setTypeInfo( const Vector&, std::size_t fields) noexcept { const auto fieldPresenceLen = (fields - 1) / 8 + 1; - oxReturnError(m_writer.write(nullptr, fieldPresenceLen)); + OX_RETURN_ERROR(m_writer.write(nullptr, fieldPresenceLen)); m_presenceMapBuff.resize(fieldPresenceLen); m_fieldPresence.setBuffer(m_presenceMapBuff.data(), m_presenceMapBuff.size()); m_fieldPresence.setFields(static_cast(fields)); @@ -372,33 +372,33 @@ constexpr ox::Error MetalClawWriter::setTypeInfo( template ox::Error MetalClawWriter::finalize() noexcept { const auto end = m_writer.tellp(); - oxReturnError(m_writer.seekp(m_writerBeginP)); - oxReturnError(m_writer.write( + OX_RETURN_ERROR(m_writer.seekp(m_writerBeginP)); + OX_RETURN_ERROR(m_writer.write( reinterpret_cast(m_presenceMapBuff.data()), m_presenceMapBuff.size())); - oxReturnError(m_writer.seekp(end)); + OX_RETURN_ERROR(m_writer.seekp(end)); return {}; } Result writeMC(Writer_c auto &writer, const auto &val) noexcept { MetalClawWriter mcWriter(writer); ModelHandlerInterface handler{&mcWriter}; - oxReturnError(model(&handler, &val)); - oxReturnError(mcWriter.finalize()); + OX_RETURN_ERROR(model(&handler, &val)); + OX_RETURN_ERROR(mcWriter.finalize()); return {}; } Result writeMC(auto const&val, std::size_t buffReserveSz = 2 * units::KB) noexcept { Buffer buff(buffReserveSz); BufferWriter bw(&buff, 0); - oxReturnError(writeMC(bw, val)); + OX_RETURN_ERROR(writeMC(bw, val)); buff.resize(bw.tellp()); return buff; } Error writeMC(char *buff, std::size_t buffLen, auto const&val, std::size_t *sizeOut = nullptr) noexcept { CharBuffWriter bw{{buff, buffLen}}; - oxReturnError(writeMC(bw, val)); + OX_RETURN_ERROR(writeMC(bw, val)); if (sizeOut) { *sizeOut = bw.tellp(); } diff --git a/deps/ox/src/ox/model/def.hpp b/deps/ox/src/ox/model/def.hpp index ce8647d8..0599ebdb 100644 --- a/deps/ox/src/ox/model/def.hpp +++ b/deps/ox/src/ox/model/def.hpp @@ -11,9 +11,9 @@ #include // oxModelFwdDecl is necessary because Apple-Clang is broken... -#define oxModelFwdDecl(modelName) constexpr ox::Error model(auto *io, ox::CommonPtrWith auto *o) noexcept -#define oxModelBegin(modelName) constexpr ox::Error model(auto *io, [[maybe_unused]] ox::CommonPtrWith auto *o) noexcept { oxReturnError(io->template setTypeInfo()); -#define oxModelEnd() return ox::Error(0); } -#define oxModelField(fieldName) oxReturnError(io->field(#fieldName, &o->fieldName)); -#define oxModelFieldRename(objFieldName, serFieldName) oxReturnError(io->field(#serFieldName, &o->objFieldName)); -#define oxModelFriend(modelName) friend constexpr ox::Error model(auto *io, ox::CommonPtrWith auto *o) noexcept +#define OX_MODEL_FWD_DECL(modelName) constexpr ox::Error model(auto *io, ox::CommonPtrWith auto *o) noexcept +#define OX_MODEL_BEGIN(modelName) constexpr ox::Error model(auto *io, [[maybe_unused]] ox::CommonPtrWith auto *o) noexcept { OX_RETURN_ERROR(io->template setTypeInfo()); +#define OX_MODEL_END() return ox::Error(0); } +#define OX_MODEL_FIELD(fieldName) OX_RETURN_ERROR(io->field(#fieldName, &o->fieldName)); +#define OX_MODEL_FIELD_RENAME(objFieldName, serFieldName) OX_RETURN_ERROR(io->field(#serFieldName, &o->objFieldName)); +#define OX_MODEL_FRIEND(modelName) friend constexpr ox::Error model(auto *io, ox::CommonPtrWith auto *o) noexcept diff --git a/deps/ox/src/ox/model/desctypes.hpp b/deps/ox/src/ox/model/desctypes.hpp index d04008d7..f22d2a23 100644 --- a/deps/ox/src/ox/model/desctypes.hpp +++ b/deps/ox/src/ox/model/desctypes.hpp @@ -76,20 +76,20 @@ struct Subscript { template constexpr Error model(T *io, CommonPtrWith auto *type) noexcept { - oxReturnError(io->template setTypeInfo()); + OX_RETURN_ERROR(io->template setTypeInfo()); if constexpr(T::opType() == OpType::Reflect) { uint32_t st = 0; - oxReturnError(io->field("subscriptType", &st)); + OX_RETURN_ERROR(io->field("subscriptType", &st)); } else if constexpr(T::opType() == OpType::Write) { auto pt = type ? static_cast(type->subscriptType) : 0; - oxReturnError(io->field("subscriptType", &pt)); + OX_RETURN_ERROR(io->field("subscriptType", &pt)); } else { auto pt = type ? static_cast(type->subscriptType) : 0; - oxReturnError(io->field("subscriptType", &pt)); + OX_RETURN_ERROR(io->field("subscriptType", &pt)); type->subscriptType = static_cast(pt); } - oxReturnError(io->field("length", &type->length)); - oxReturnError(io->field("smallSzLen", &type->smallSzLen)); + OX_RETURN_ERROR(io->field("length", &type->length)); + OX_RETURN_ERROR(io->field("smallSzLen", &type->smallSzLen)); return {}; } @@ -185,37 +185,37 @@ constexpr auto buildTypeId(const DescriptorType &t) noexcept { template constexpr Error model(T *io, CommonPtrWith auto *type) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("typeName", &type->typeName)); - oxReturnError(io->field("typeVersion", &type->typeVersion)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("typeName", &type->typeName)); + OX_RETURN_ERROR(io->field("typeVersion", &type->typeVersion)); if constexpr(T::opType() == OpType::Reflect) { uint8_t pt = 0; - oxReturnError(io->field("primitiveType", &pt)); + OX_RETURN_ERROR(io->field("primitiveType", &pt)); } else if constexpr(T::opType() == OpType::Write) { auto pt = type ? static_cast(type->primitiveType) : 0; - oxReturnError(io->field("primitiveType", &pt)); + OX_RETURN_ERROR(io->field("primitiveType", &pt)); } else { auto pt = type ? static_cast(type->primitiveType) : 0; - oxReturnError(io->field("primitiveType", &pt)); + OX_RETURN_ERROR(io->field("primitiveType", &pt)); type->primitiveType = static_cast(pt); } - oxReturnError(io->field("typeParams", &type->typeParams)); - oxReturnError(io->field("fieldList", &type->fieldList)); - oxReturnError(io->field("length", &type->length)); - oxReturnError(io->field("preloadable", &type->preloadable)); + OX_RETURN_ERROR(io->field("typeParams", &type->typeParams)); + OX_RETURN_ERROR(io->field("fieldList", &type->fieldList)); + OX_RETURN_ERROR(io->field("length", &type->length)); + OX_RETURN_ERROR(io->field("preloadable", &type->preloadable)); return {}; } template constexpr Error model(T *io, CommonPtrWith auto *field) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("typeId", &field->typeId)); - oxReturnError(io->field("fieldName", &field->fieldName)); - oxReturnError(io->field("subscriptLevels", &field->subscriptLevels)); - oxReturnError(io->field("subscriptStack", &field->subscriptStack)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("typeId", &field->typeId)); + OX_RETURN_ERROR(io->field("fieldName", &field->fieldName)); + OX_RETURN_ERROR(io->field("subscriptLevels", &field->subscriptLevels)); + OX_RETURN_ERROR(io->field("subscriptStack", &field->subscriptStack)); // defaultValue is unused now, but leave placeholder for backwards compatibility int defaultValue = 0; - oxReturnError(io->field("defaultValue", &defaultValue)); + OX_RETURN_ERROR(io->field("defaultValue", &defaultValue)); return {}; } diff --git a/deps/ox/src/ox/model/descwrite.hpp b/deps/ox/src/ox/model/descwrite.hpp index 29245a34..290d5863 100644 --- a/deps/ox/src/ox/model/descwrite.hpp +++ b/deps/ox/src/ox/model/descwrite.hpp @@ -384,11 +384,11 @@ constexpr Result buildTypeDef(TypeStore &typeStore) noexcept { if (std::is_constant_evaluated()) { std::allocator a; T *t = a.allocate(1); - oxReturnError(model(&handler, t)); + OX_RETURN_ERROR(model(&handler, t)); a.deallocate(t, 1); } else { auto t = ox_malloca(sizeof(T), T); - oxReturnError(model(&handler, t.get())); + OX_RETURN_ERROR(model(&handler, t.get())); } return writer.definition(); } @@ -397,7 +397,7 @@ template constexpr Result buildTypeDef(TypeStore &typeStore, T &val) noexcept { TypeDescWriter writer(&typeStore); ModelHandlerInterface handler(&writer); - oxReturnError(model(&handler, &val)); + OX_RETURN_ERROR(model(&handler, &val)); return writer.definition(); } diff --git a/deps/ox/src/ox/model/modelvalue.cpp b/deps/ox/src/ox/model/modelvalue.cpp index eef8a8a2..839ac717 100644 --- a/deps/ox/src/ox/model/modelvalue.cpp +++ b/deps/ox/src/ox/model/modelvalue.cpp @@ -12,7 +12,7 @@ namespace ox { static_assert([]() -> ox::Error { ox::ModelValue v; - oxReturnError(v.setType()); + OX_RETURN_ERROR(v.setType()); if (v.type() != ModelValue::Type::SignedInteger32) { return ox::Error(1, "type is wrong"); } diff --git a/deps/ox/src/ox/model/modelvalue.hpp b/deps/ox/src/ox/model/modelvalue.hpp index 0a37fc2d..7b178626 100644 --- a/deps/ox/src/ox/model/modelvalue.hpp +++ b/deps/ox/src/ox/model/modelvalue.hpp @@ -242,7 +242,7 @@ class ModelValueArray { m_vec.resize(sz); if (sz > oldSz) { for (auto i = oldSz; i < sz; ++i) { - oxReturnError(m_vec[i].setType(m_type, m_subscriptStack, m_typeSubscriptLevels)); + OX_RETURN_ERROR(m_vec[i].setType(m_type, m_subscriptStack, m_typeSubscriptLevels)); } } return {}; @@ -401,7 +401,7 @@ class ModelValueVector { m_vec.resize(sz); if (sz > oldSz) { for (auto i = oldSz; i < sz; ++i) { - oxReturnError(m_vec[i].setType(m_type, m_subscriptStack, m_typeSubscriptLevels)); + OX_RETURN_ERROR(m_vec[i].setType(m_type, m_subscriptStack, m_typeSubscriptLevels)); } } return {}; @@ -519,7 +519,7 @@ class ModelObject { ModelValue value; }; protected: - oxModelFriend(ModelObject); + OX_MODEL_FRIEND(ModelObject); friend ModelValue; Vector> m_fieldsOrder; HashMap m_fields; @@ -639,13 +639,13 @@ class ModelObject { template constexpr Error set(const String &k, T &&val) noexcept { - oxRequire(t, m_fields.at(k)); + OX_REQUIRE(t, m_fields.at(k)); *t = ox::forward(val); return {}; } constexpr ox::Result at(StringView const&k) noexcept { - oxRequire(v, m_fields.at(k)); + OX_REQUIRE(v, m_fields.at(k)); return *v; } @@ -676,7 +676,7 @@ class ModelObject { for (const auto &f : type->fieldList) { auto field = make_unique(); field->name = f.fieldName; - oxReturnError(field->value.setType(f.type, f.subscriptStack, f.subscriptLevels)); + OX_RETURN_ERROR(field->value.setType(f.type, f.subscriptStack, f.subscriptLevels)); m_fields[field->name] = &field->value; m_fieldsOrder.emplace_back(std::move(field)); } @@ -722,7 +722,7 @@ class ModelUnion { static constexpr Result> make(const DescriptorType *type) noexcept { UniquePtr out(new ModelUnion); - oxReturnError(out->setType(type)); + OX_RETURN_ERROR(out->setType(type)); return out; } @@ -731,7 +731,7 @@ class ModelUnion { } constexpr ox::Result at(StringView const&k) noexcept { - oxRequire(v, m_fields.at(k)); + OX_REQUIRE(v, m_fields.at(k)); return &(*v)->value; } @@ -763,7 +763,7 @@ class ModelUnion { [[nodiscard]] constexpr Result get(StringView const&k) const noexcept { - oxRequire(t, m_fields.at(k)); + OX_REQUIRE(t, m_fields.at(k)); return &(*t)->value; } @@ -799,7 +799,7 @@ class ModelUnion { auto field = make_unique(); field->name = f.fieldName; field->idx = i; - oxReturnError(field->value.setType(f.type, SubscriptStack{static_cast(f.subscriptLevels)}, f.subscriptLevels)); + OX_RETURN_ERROR(field->value.setType(f.type, SubscriptStack{static_cast(f.subscriptLevels)}, f.subscriptLevels)); m_fields[field->name] = field.get(); m_fieldsOrder.emplace_back(std::move(field)); ++i; @@ -967,19 +967,19 @@ constexpr std::size_t alignOf(const ModelValue &t) noexcept { } constexpr Error model(auto *h, CommonPtrWith auto *obj) noexcept { - oxReturnError(h->template setTypeInfo( + OX_RETURN_ERROR(h->template setTypeInfo( obj->typeName().c_str(), obj->typeVersion(), {}, obj->m_fieldsOrder.size())); for (auto &f : obj->m_fieldsOrder) { - oxReturnError(h->field(f->name.c_str(), &f->value)); + OX_RETURN_ERROR(h->field(f->name.c_str(), &f->value)); } return ox::Error(0); } constexpr Error model(auto *h, CommonPtrWith auto *obj) noexcept { - oxReturnError(h->template setTypeInfo( + OX_RETURN_ERROR(h->template setTypeInfo( obj->typeName().c_str(), obj->typeVersion(), {}, obj->m_fieldsOrder.size())); for (auto &f : obj->m_fieldsOrder) { - oxReturnError(h->field(f->name.c_str(), &f->value)); + OX_RETURN_ERROR(h->field(f->name.c_str(), &f->value)); } return ox::Error(0); } @@ -1087,12 +1087,12 @@ constexpr Error ModelValue::setType( if (subscript.subscriptType == Subscript::SubscriptType::InlineArray) { m_type = Type::InlineArray; m_data.array = new ModelValueArray; - oxReturnError(m_data.array->setType(type, subscriptStack, subscriptLevels - 1)); - oxReturnError(m_data.array->setSize(static_cast(subscript.length))); + OX_RETURN_ERROR(m_data.array->setType(type, subscriptStack, subscriptLevels - 1)); + OX_RETURN_ERROR(m_data.array->setSize(static_cast(subscript.length))); } else { m_type = Type::Vector; m_data.vec = new ModelValueVector; - oxReturnError(m_data.vec->setType(type, subscriptStack, subscriptLevels - 1)); + OX_RETURN_ERROR(m_data.vec->setType(type, subscriptStack, subscriptLevels - 1)); } return {}; } else if (type->typeName == types::Bool) { @@ -1121,12 +1121,12 @@ constexpr Error ModelValue::setType( } else if (type->primitiveType == PrimitiveType::Struct) { m_type = Type::Object; m_data.obj = new ModelObject; - oxReturnError(m_data.obj->setType(type)); + OX_RETURN_ERROR(m_data.obj->setType(type)); } else if (type->primitiveType == PrimitiveType::Union) { m_type = Type::Union; - oxRequireM(u, ModelUnion::make(type)); + OX_REQUIRE_M(u, ModelUnion::make(type)); m_data.uni = u.release(); - oxReturnError(m_data.uni->setType(type)); + OX_RETURN_ERROR(m_data.uni->setType(type)); } oxAssert(m_type != Type::Undefined, "No type set"); return ox::Error(0); @@ -1141,11 +1141,11 @@ constexpr Error ModelValue::setType() noexcept { // rather than using getValue() if constexpr(type == Type::Object) { m_data.obj = new ModelObject; - oxReturnError(m_data.obj->setType(type)); + OX_RETURN_ERROR(m_data.obj->setType(type)); } else if constexpr(type == Type::Union) { - oxRequireM(u, ModelUnion::make(type)); + OX_REQUIRE_M(u, ModelUnion::make(type)); m_data.uni = u.release(); - oxReturnError(m_data.uni->setType(type)); + OX_RETURN_ERROR(m_data.uni->setType(type)); } else if constexpr(type == Type::String) { m_data.str = new String; } else if constexpr(type == Type::Vector) { diff --git a/deps/ox/src/ox/model/test/tests.cpp b/deps/ox/src/ox/model/test/tests.cpp index 79d59c3a..9aea6bff 100644 --- a/deps/ox/src/ox/model/test/tests.cpp +++ b/deps/ox/src/ox/model/test/tests.cpp @@ -17,8 +17,8 @@ struct TestType { static constexpr auto TypeVersion = 1; }; -oxModelBegin(TestType) -oxModelEnd() +OX_MODEL_BEGIN(TestType) +OX_MODEL_END() struct TestType2 { }; @@ -38,12 +38,12 @@ std::map tests = { "ModelValue", [] { ox::ModelValue v; - oxReturnError(v.setType()); + OX_RETURN_ERROR(v.setType()); //v.m_type = ox::ModelValue::getType(); if (v.type() != ox::ModelValue::Type::SignedInteger32) { return ox::Error(1, "type is wrong"); } - oxReturnError(v.set(5)); + OX_RETURN_ERROR(v.set(5)); return ox::Error{}; } }, diff --git a/deps/ox/src/ox/model/typestore.hpp b/deps/ox/src/ox/model/typestore.hpp index 6aca7516..d79902cb 100644 --- a/deps/ox/src/ox/model/typestore.hpp +++ b/deps/ox/src/ox/model/typestore.hpp @@ -31,7 +31,7 @@ class TypeStore { constexpr Result get(const auto &name, int typeVersion, const TypeParamPack &typeParams) const noexcept { const auto typeId = buildTypeId(name, typeVersion, typeParams); - oxRequire(out, m_cache.at(typeId)); + OX_REQUIRE(out, m_cache.at(typeId)); return out->get(); } @@ -40,7 +40,7 @@ class TypeStore { constexpr auto typeName = ModelTypeName_v; constexpr auto typeVersion = ModelTypeVersion_v; const auto typeId = buildTypeId(typeName, typeVersion, {}); - oxRequire(out, m_cache.at(typeId)); + OX_REQUIRE(out, m_cache.at(typeId)); return out->get(); } @@ -56,9 +56,9 @@ class TypeStore { auto [val, err] = m_cache.at(typeId); if (err) { if (!std::is_constant_evaluated()) { - oxRequireM(dt, loadDescriptor(typeId)); + OX_REQUIRE_M(dt, loadDescriptor(typeId)); for (auto &f : dt->fieldList) { - oxReturnError(this->getLoad(f.typeId).moveTo(f.type)); + OX_RETURN_ERROR(this->getLoad(f.typeId).moveTo(f.type)); } auto &out = m_cache[typeId]; out = std::move(dt); diff --git a/deps/ox/src/ox/model/walk.hpp b/deps/ox/src/ox/model/walk.hpp index 707efe92..0d452bb7 100644 --- a/deps/ox/src/ox/model/walk.hpp +++ b/deps/ox/src/ox/model/walk.hpp @@ -50,7 +50,7 @@ constexpr DataWalker::DataWalker(DescriptorType *type, T fieldHandler template constexpr Result DataWalker::type() const noexcept { - oxRequire(out, m_typeStack.back()); + OX_REQUIRE(out, m_typeStack.back()); return *out; } @@ -87,9 +87,9 @@ static constexpr Error parseField(const DescriptorField &field, Reader *rdr, Dat walker->pushNamePath(field.fieldName); if (field.subscriptLevels) { // add array handling - oxRequire(arrayLen, rdr->arrayLength(field.fieldName.c_str(), true)); + OX_REQUIRE(arrayLen, rdr->arrayLength(field.fieldName.c_str(), true)); auto child = rdr->child(field.fieldName.c_str()); - oxReturnError(child.setTypeInfo(field.type->typeName.c_str(), field.type->typeVersion, field.type->typeParams, arrayLen)); + OX_RETURN_ERROR(child.setTypeInfo(field.type->typeName.c_str(), field.type->typeVersion, field.type->typeParams, arrayLen)); DescriptorField f(field); // create mutable copy --f.subscriptLevels; String subscript; @@ -98,7 +98,7 @@ static constexpr Error parseField(const DescriptorField &field, Reader *rdr, Dat subscript += static_cast(i); subscript += "]"; walker->pushNamePath(subscript); - oxReturnError(parseField(f, &child, walker)); + OX_RETURN_ERROR(parseField(f, &child, walker)); walker->popNamePath(); } rdr->nextField(); @@ -108,20 +108,20 @@ static constexpr Error parseField(const DescriptorField &field, Reader *rdr, Dat case PrimitiveType::SignedInteger: case PrimitiveType::Bool: case PrimitiveType::String: - oxReturnError(walker->read(field, rdr)); + OX_RETURN_ERROR(walker->read(field, rdr)); break; case PrimitiveType::Struct: case PrimitiveType::Union: if (rdr->fieldPresent(field.fieldName.c_str())) { auto child = rdr->child(field.fieldName.c_str()); walker->pushType(field.type); - oxReturnError(model(&child, walker)); + OX_RETURN_ERROR(model(&child, walker)); walker->popType(); rdr->nextField(); } else { // skip and discard absent field int discard; - oxReturnError(rdr->field(field.fieldName.c_str(), &discard)); + OX_RETURN_ERROR(rdr->field(field.fieldName.c_str(), &discard)); } break; } @@ -132,14 +132,14 @@ static constexpr Error parseField(const DescriptorField &field, Reader *rdr, Dat template constexpr Error model(Reader *rdr, DataWalker *walker) noexcept { - oxRequire(type, walker->type()); + OX_REQUIRE(type, walker->type()); auto typeName = type->typeName.c_str(); auto typeVersion = type->typeVersion; auto typeParams = type->typeParams; auto &fields = type->fieldList; - oxReturnError(rdr->setTypeInfo(typeName, typeVersion, typeParams, fields.size())); + OX_RETURN_ERROR(rdr->setTypeInfo(typeName, typeVersion, typeParams, fields.size())); for (const auto &field : fields) { - oxReturnError(parseField(field, rdr, walker)); + OX_RETURN_ERROR(parseField(field, rdr, walker)); } return ox::Error(0); } diff --git a/deps/ox/src/ox/oc/read.cpp b/deps/ox/src/ox/oc/read.cpp index 1b1b2948..d27b5abf 100644 --- a/deps/ox/src/ox/oc/read.cpp +++ b/deps/ox/src/ox/oc/read.cpp @@ -135,7 +135,7 @@ Error OrganicClawReader::fieldCString(const char *key, char **val, std::size_t b Error OrganicClawReader::field(const char *key, UUID *val) noexcept { UUIDStr str; - oxReturnError(field(key, &str)); + OX_RETURN_ERROR(field(key, &str)); return UUID::fromString(str).moveTo(*val); } diff --git a/deps/ox/src/ox/oc/read.hpp b/deps/ox/src/ox/oc/read.hpp index c0d9145e..9306d65a 100644 --- a/deps/ox/src/ox/oc/read.hpp +++ b/deps/ox/src/ox/oc/read.hpp @@ -152,7 +152,7 @@ Error OrganicClawReader::field(const char *key, T *val) noexcept { } else if constexpr (isVector_v) { const auto&srcVal = value(key); const auto srcSize = srcVal.size(); - oxReturnError(ox::resizeVector(*val, srcSize)); + OX_RETURN_ERROR(ox::resizeVector(*val, srcSize)); err = field(key, val->data(), val->size()); } else if constexpr (isArray_v) { const auto&srcVal = value(key); @@ -245,7 +245,7 @@ Error OrganicClawReader::field(const char *key, T *val, std::size_t valLen) noex ModelHandlerInterface handler{&r}; for (decltype(srcSize) i = 0; i < srcSize; ++i) { OX_ALLOW_UNSAFE_BUFFERS_BEGIN - oxReturnError(handler.field("", &val[i])); + OX_RETURN_ERROR(handler.field("", &val[i])); OX_ALLOW_UNSAFE_BUFFERS_END } return ox::Error(0); @@ -263,7 +263,7 @@ Error OrganicClawReader::field(const char *key, HashMap *val) noexcep ModelHandlerInterface handler{&r}; for (decltype(srcSize) i = 0; i < srcSize; ++i) { const auto k = keys[i].c_str(); - oxReturnError(handler.field(k, &val->operator[](k))); + OX_RETURN_ERROR(handler.field(k, &val->operator[](k))); } return ox::Error(0); } @@ -292,7 +292,7 @@ OX_ALLOW_UNSAFE_BUFFERS_END template Result readOC(BufferView buff) noexcept { Result val; - oxReturnError(readOC(buff, val.value)); + OX_RETURN_ERROR(readOC(buff, val.value)); return val; } diff --git a/deps/ox/src/ox/oc/test/tests.cpp b/deps/ox/src/ox/oc/test/tests.cpp index bf3d69d3..3532f90f 100644 --- a/deps/ox/src/ox/oc/test/tests.cpp +++ b/deps/ox/src/ox/oc/test/tests.cpp @@ -74,44 +74,44 @@ struct TestStruct { }; constexpr ox::Error model(auto *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("Bool", &obj->Bool)); - oxReturnError(io->field("Int", &obj->Int)); - oxReturnError(io->fieldCString("String", &obj->String)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("Bool", &obj->Bool)); + OX_RETURN_ERROR(io->field("Int", &obj->Int)); + OX_RETURN_ERROR(io->fieldCString("String", &obj->String)); return ox::Error(0); } constexpr ox::Error model(auto *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("Bool", &obj->Bool)); - oxReturnError(io->field("Int", &obj->Int)); - oxReturnError(io->field("String", &obj->String)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("Bool", &obj->Bool)); + OX_RETURN_ERROR(io->field("Int", &obj->Int)); + OX_RETURN_ERROR(io->field("String", &obj->String)); return ox::Error(0); } constexpr ox::Error model(auto *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("Bool", &obj->Bool)); - oxReturnError(io->field("Int", &obj->Int)); - oxReturnError(io->field("Int1", &obj->Int1)); - oxReturnError(io->field("Int2", &obj->Int2)); - oxReturnError(io->field("Int3", &obj->Int3)); - oxReturnError(io->field("Int4", &obj->Int4)); - oxReturnError(io->field("Int5", &obj->Int5)); - oxReturnError(io->field("Int6", &obj->Int6)); - oxReturnError(io->field("Int7", &obj->Int7)); - oxReturnError(io->field("Int8", &obj->Int8)); - oxReturnError(io->field("unionIdx", &obj->unionIdx)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("Bool", &obj->Bool)); + OX_RETURN_ERROR(io->field("Int", &obj->Int)); + OX_RETURN_ERROR(io->field("Int1", &obj->Int1)); + OX_RETURN_ERROR(io->field("Int2", &obj->Int2)); + OX_RETURN_ERROR(io->field("Int3", &obj->Int3)); + OX_RETURN_ERROR(io->field("Int4", &obj->Int4)); + OX_RETURN_ERROR(io->field("Int5", &obj->Int5)); + OX_RETURN_ERROR(io->field("Int6", &obj->Int6)); + OX_RETURN_ERROR(io->field("Int7", &obj->Int7)); + OX_RETURN_ERROR(io->field("Int8", &obj->Int8)); + OX_RETURN_ERROR(io->field("unionIdx", &obj->unionIdx)); if (io->opType() == ox::OpType::Reflect) { - oxReturnError(io->field("Union", ox::UnionView{&obj->Union, 0})); + OX_RETURN_ERROR(io->field("Union", ox::UnionView{&obj->Union, 0})); } else { - oxReturnError(io->field("Union", ox::UnionView{&obj->Union, obj->unionIdx})); + OX_RETURN_ERROR(io->field("Union", ox::UnionView{&obj->Union, obj->unionIdx})); } - oxReturnError(io->field("String", &obj->String)); - oxReturnError(io->field("List", obj->List, 4)); - oxReturnError(io->field("Map", &obj->Map)); - oxReturnError(io->field("EmptyStruct", &obj->EmptyStruct)); - oxReturnError(io->field("Struct", &obj->Struct)); + OX_RETURN_ERROR(io->field("String", &obj->String)); + OX_RETURN_ERROR(io->field("List", obj->List, 4)); + OX_RETURN_ERROR(io->field("Map", &obj->Map)); + OX_RETURN_ERROR(io->field("EmptyStruct", &obj->EmptyStruct)); + OX_RETURN_ERROR(io->field("Struct", &obj->Struct)); return ox::Error(0); } @@ -210,7 +210,7 @@ const std::map tests = { auto type = ox::buildTypeDef(typeStore, testIn); oxAssert(type.error, "Descriptor write failed"); ox::ModelObject testOut; - oxReturnError(testOut.setType(type.value)); + OX_RETURN_ERROR(testOut.setType(type.value)); oxAssert(ox::readOC(dataBuff, testOut), "Data read failed"); oxAssert(testOut.get("Int").unwrap()->get() == testIn.Int, "testOut.Int failed"); oxAssert(testOut.get("Bool").unwrap()->get() == testIn.Bool, "testOut.Bool failed"); @@ -259,7 +259,7 @@ const std::map tests = { ox::TypeStore typeStore; auto type = ox::buildTypeDef(typeStore, testIn); oxAssert(type.error, "Descriptor write failed"); - oxReturnError(ox::walkModel(type.value, oc.data(), oc.size(), + OX_RETURN_ERROR(ox::walkModel(type.value, oc.data(), oc.size(), [](const ox::Vector&, const ox::Vector&, const ox::DescriptorField &f, ox::OrganicClawReader *rdr) -> ox::Error { auto fieldName = f.fieldName.c_str(); diff --git a/deps/ox/src/ox/oc/write.hpp b/deps/ox/src/ox/oc/write.hpp index 749af136..a1a3388b 100644 --- a/deps/ox/src/ox/oc/write.hpp +++ b/deps/ox/src/ox/oc/write.hpp @@ -122,8 +122,8 @@ class OrganicClawWriter { for (std::size_t i = 0; i < keys.size(); ++i) { const auto k = keys[i].c_str(); if (k) [[likely]] { - oxRequireM(value, val->at(k)); - oxReturnError(handler.field(k, value)); + OX_REQUIRE_M(value, val->at(k)); + OX_RETURN_ERROR(handler.field(k, value)); } } value(key) = w.m_json; @@ -201,7 +201,7 @@ Error OrganicClawWriter::field(const char *key, const T *val, std::size_t len) n ModelHandlerInterface handler{&w}; for (std::size_t i = 0; i < len; ++i) { OX_ALLOW_UNSAFE_BUFFERS_BEGIN - oxReturnError(handler.field({}, &val[i])); + OX_RETURN_ERROR(handler.field({}, &val[i])); OX_ALLOW_UNSAFE_BUFFERS_END } value(key) = w.m_json; @@ -227,7 +227,7 @@ Error OrganicClawWriter::field(const char *key, const T *val) noexcept { } else if (val && targetValid()) { OrganicClawWriter w; ModelHandlerInterface handler{&w}; - oxReturnError(model(&handler, val)); + OX_RETURN_ERROR(model(&handler, val)); if (!w.m_json.empty() || m_json.isArray()) { value(key) = w.m_json; } @@ -241,7 +241,7 @@ Error OrganicClawWriter::field(const char *key, UnionView val) noexcep if (targetValid()) { OrganicClawWriter w(val.idx()); ModelHandlerInterface handler{&w}; - oxReturnError(model(&handler, val.get())); + OX_RETURN_ERROR(model(&handler, val.get())); if (!w.m_json.isNull()) { value(key) = w.m_json; } @@ -253,7 +253,7 @@ Error OrganicClawWriter::field(const char *key, UnionView val) noexcep Result writeOC(const auto &val) noexcept { OrganicClawWriter writer; ModelHandlerInterface handler(&writer); - oxReturnError(model(&handler, &val)); + OX_RETURN_ERROR(model(&handler, &val)); Json::StreamWriterBuilder const jsonBuilder; const auto str = Json::writeString(jsonBuilder, writer.m_json); Result buff; @@ -265,7 +265,7 @@ Result writeOC(const auto &val) noexcept { Result writeOCString(const auto &val) noexcept { OrganicClawWriter writer; ModelHandlerInterface handler(&writer); - oxReturnError(model(&handler, &val)); + OX_RETURN_ERROR(model(&handler, &val)); Json::StreamWriterBuilder const jsonBuilder; const auto str = Json::writeString(jsonBuilder, writer.m_json); Result buff; diff --git a/deps/ox/src/ox/preloader/alignmentcatcher.hpp b/deps/ox/src/ox/preloader/alignmentcatcher.hpp index 07b2fbb2..31751908 100644 --- a/deps/ox/src/ox/preloader/alignmentcatcher.hpp +++ b/deps/ox/src/ox/preloader/alignmentcatcher.hpp @@ -63,7 +63,7 @@ struct AlignmentCatcher: public ModelHandlerBase, OpT template constexpr ox::Error field(StringViewCR, const T *val, std::size_t cnt) noexcept { for (std::size_t i = 0; i < cnt; ++i) { - oxReturnError(field(nullptr, &val[i])); + OX_RETURN_ERROR(field(nullptr, &val[i])); } return {}; } diff --git a/deps/ox/src/ox/preloader/preloader.hpp b/deps/ox/src/ox/preloader/preloader.hpp index cf49d00c..e836b7cb 100644 --- a/deps/ox/src/ox/preloader/preloader.hpp +++ b/deps/ox/src/ox/preloader/preloader.hpp @@ -162,7 +162,7 @@ constexpr ox::Error Preloader::field(StringViewCR, const ox::UnionView if (!unionCheckAndIt()) { return {}; } - oxReturnError(pad(val.get())); + OX_RETURN_ERROR(pad(val.get())); m_unionIdx.emplace_back(val.idx()); const auto err = preload(this, val.get()); m_unionIdx.pop_back(); @@ -175,13 +175,13 @@ constexpr ox::Error Preloader::field(StringViewCR name, const T *val) if (!unionCheckAndIt()) { return {}; } - oxReturnError(pad(val)); + OX_RETURN_ERROR(pad(val)); if constexpr(ox::is_integral_v) { return ox::serialize(m_writer, PlatSpec::correctEndianness(*val)); } else if constexpr(ox::is_pointer_v) { const PtrType a = startAlloc(sizeOf(val), alignOf(*val), m_writer.tellp()) + PlatSpec::RomStart; - oxReturnError(field(name, *val)); - oxReturnError(endAlloc()); + OX_RETURN_ERROR(field(name, *val)); + OX_RETURN_ERROR(endAlloc()); return ox::serialize(m_writer, PlatSpec::correctEndianness(a)); } else if constexpr(ox::isVector_v) { return fieldVector(name, val); @@ -211,19 +211,19 @@ constexpr ox::Error Preloader::field(StringViewCR, const ox::BasicStri .size = PlatSpec::correctEndianness(static_cast(sz)), .cap = PlatSpec::correctEndianness(static_cast(sz)), }; - oxReturnError(pad(&vecVal)); + OX_RETURN_ERROR(pad(&vecVal)); const auto restore = m_writer.tellp(); std::size_t a = 0; if (sz && sz >= SmallStringSize) { - oxReturnError(ox::allocate(m_writer, sz).moveTo(a)); + OX_RETURN_ERROR(ox::allocate(m_writer, sz).moveTo(a)); } else { a = restore; } vecVal.items = PlatSpec::correctEndianness(static_cast(a) + PlatSpec::RomStart); - oxReturnError(m_writer.seekp(a)); - oxReturnError(m_writer.write(val->data(), sz)); - oxReturnError(m_writer.seekp(restore)); - oxReturnError(serialize(m_writer, vecVal)); + OX_RETURN_ERROR(m_writer.seekp(a)); + OX_RETURN_ERROR(m_writer.write(val->data(), sz)); + OX_RETURN_ERROR(m_writer.seekp(restore)); + OX_RETURN_ERROR(serialize(m_writer, vecVal)); m_ptrs.emplace_back(restore + offsetof(VecMap, items), vecVal.items); return {}; } @@ -234,12 +234,12 @@ constexpr ox::Error Preloader::field(StringViewCR name, const ox::Arra if (!unionCheckAndIt()) { return {}; } - oxReturnError(pad(&(*val)[0])); + OX_RETURN_ERROR(pad(&(*val)[0])); // serialize the Array elements if constexpr(sz) { m_unionIdx.emplace_back(-1); for (std::size_t i = 0; i < val->size(); ++i) { - oxReturnError(this->interface()->field(name, &(*val)[i])); + OX_RETURN_ERROR(this->interface()->field(name, &(*val)[i])); } m_unionIdx.pop_back(); } @@ -253,11 +253,11 @@ constexpr ox::Error Preloader::field(StringViewCR, const T **val, std: return {}; } if (cnt) { - oxReturnError(pad(*val)); + OX_RETURN_ERROR(pad(*val)); // serialize the array m_unionIdx.emplace_back(-1); for (std::size_t i = 0; i < cnt; ++i) { - oxReturnError(this->interface()->field(nullptr, &val[i])); + OX_RETURN_ERROR(this->interface()->field(nullptr, &val[i])); } m_unionIdx.pop_back(); } @@ -267,11 +267,11 @@ constexpr ox::Error Preloader::field(StringViewCR, const T **val, std: template constexpr ox::Result Preloader::startAlloc(size_t sz, size_t align) noexcept { m_allocStack.emplace_back(static_cast(m_writer.tellp())); - oxReturnError(m_writer.seekp(0, ox::ios_base::end)); + OX_RETURN_ERROR(m_writer.seekp(0, ox::ios_base::end)); auto const padding = calcPadding(align); - oxRequireM(a, ox::allocate(m_writer, sz + padding)); + OX_REQUIRE_M(a, ox::allocate(m_writer, sz + padding)); a += padding; - oxReturnError(m_writer.seekp(a)); + OX_RETURN_ERROR(m_writer.seekp(a)); m_allocStart.push_back(a); return a; } @@ -280,11 +280,11 @@ template constexpr ox::Result Preloader::startAlloc( std::size_t sz, size_t align, std::size_t restore) noexcept { m_allocStack.emplace_back(restore, ox::ios_base::beg); - oxReturnError(m_writer.seekp(0, ox::ios_base::end)); + OX_RETURN_ERROR(m_writer.seekp(0, ox::ios_base::end)); auto const padding = calcPadding(align); - oxRequireM(a, ox::allocate(m_writer, sz + padding)); + OX_REQUIRE_M(a, ox::allocate(m_writer, sz + padding)); a += padding; - oxReturnError(m_writer.seekp(a)); + OX_RETURN_ERROR(m_writer.seekp(a)); m_allocStart.push_back(a); return a; } @@ -295,7 +295,7 @@ constexpr ox::Error Preloader::endAlloc() noexcept { return m_writer.seekp(0, ox::ios_base::end); } const auto &si = *m_allocStack.back().unwrap(); - oxReturnError(m_writer.seekp(static_cast(si.restore), si.seekdir)); + OX_RETURN_ERROR(m_writer.seekp(static_cast(si.restore), si.seekdir)); m_allocStack.pop_back(); m_allocStart.pop_back(); return {}; @@ -304,12 +304,12 @@ constexpr ox::Error Preloader::endAlloc() noexcept { template constexpr ox::Error Preloader::offsetPtrs(std::size_t offset) noexcept { for (const auto &p : m_ptrs) { - oxReturnError(m_writer.seekp(p.loc)); + OX_RETURN_ERROR(m_writer.seekp(p.loc)); const auto val = PlatSpec::template correctEndianness( static_cast(p.value + offset)); - oxReturnError(ox::serialize(m_writer, val)); + OX_RETURN_ERROR(ox::serialize(m_writer, val)); } - oxReturnError(m_writer.seekp(0, ox::ios_base::end)); + OX_RETURN_ERROR(m_writer.seekp(0, ox::ios_base::end)); return {}; } @@ -354,39 +354,39 @@ constexpr ox::Error Preloader::fieldVector( template constexpr ox::Error Preloader::fieldVector( StringViewCR, const auto *val, ox::VectorMemMap vecVal) noexcept { - oxReturnError(pad(&vecVal)); + OX_RETURN_ERROR(pad(&vecVal)); const auto vecValPt = m_writer.tellp(); // serialize the Vector elements if (val->size()) { const auto sz = sizeOf(&(*val)[0]) * val->size(); const auto align = alignOf((*val)[0]); - oxReturnError(m_writer.seekp(0, ox::ios_base::end)); + OX_RETURN_ERROR(m_writer.seekp(0, ox::ios_base::end)); auto const padding = calcPadding(align); - oxRequireM(p, ox::allocate(m_writer, sz + padding)); + OX_REQUIRE_M(p, ox::allocate(m_writer, sz + padding)); p += padding; - oxReturnError(m_writer.seekp(p)); + OX_RETURN_ERROR(m_writer.seekp(p)); m_unionIdx.emplace_back(-1); for (std::size_t i = 0; i < val->size(); ++i) { - oxReturnError(this->interface()->field(nullptr, &val->operator[](i))); + OX_RETURN_ERROR(this->interface()->field(nullptr, &val->operator[](i))); } m_unionIdx.pop_back(); vecVal.items = PlatSpec::correctEndianness( static_cast(p + PlatSpec::RomStart)); - oxReturnError(m_writer.seekp(vecValPt)); + OX_RETURN_ERROR(m_writer.seekp(vecValPt)); } else { vecVal.items = 0; } // serialize the Vector - oxReturnError(serialize(m_writer, vecVal)); + OX_RETURN_ERROR(serialize(m_writer, vecVal)); m_ptrs.emplace_back(m_writer.tellp() - PtrSize, vecVal.items); return {}; } template constexpr ox::Error Preloader::fieldArray(StringViewCR, ox::ModelValueArray const*val) noexcept { - oxReturnError(pad(&(*val)[0])); + OX_RETURN_ERROR(pad(&(*val)[0])); for (auto const&v : *val) { - oxReturnError(this->interface()->field({}, &v)); + OX_RETURN_ERROR(this->interface()->field({}, &v)); } return {}; } @@ -405,7 +405,7 @@ constexpr size_t Preloader::calcPadding(size_t align) const noexcept { template constexpr ox::Error preload(Preloader *pl, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(model(pl->interface(), obj)); + OX_RETURN_ERROR(model(pl->interface(), obj)); return pl->pad(obj); } diff --git a/deps/ox/src/ox/preloader/sizecatcher.hpp b/deps/ox/src/ox/preloader/sizecatcher.hpp index e9ca5463..fb1eba6b 100644 --- a/deps/ox/src/ox/preloader/sizecatcher.hpp +++ b/deps/ox/src/ox/preloader/sizecatcher.hpp @@ -74,7 +74,7 @@ template constexpr ox::Error SizeCatcher::field(const char*, const UnionView val) noexcept { pad(val.get()); UnionSizeCatcher sc; - oxReturnError(model(sc.interface(), val.get())); + OX_RETURN_ERROR(model(sc.interface(), val.get())); m_size += sc.size(); return {}; } @@ -91,7 +91,7 @@ template template constexpr ox::Error SizeCatcher::field(const char*, const T **val, std::size_t cnt) noexcept { for (std::size_t i = 0; i < cnt; ++i) { - oxReturnError(field("", &val[i])); + OX_RETURN_ERROR(field("", &val[i])); } return {}; } diff --git a/deps/ox/src/ox/preloader/unionsizecatcher.hpp b/deps/ox/src/ox/preloader/unionsizecatcher.hpp index 34682000..e6a59be5 100644 --- a/deps/ox/src/ox/preloader/unionsizecatcher.hpp +++ b/deps/ox/src/ox/preloader/unionsizecatcher.hpp @@ -43,7 +43,7 @@ class UnionSizeCatcher: public ModelHandlerBase, OpTy template constexpr ox::Error field(StringViewCR, const UnionView val) noexcept { UnionSizeCatcher sc; - oxReturnError(model(sc.interface(), val.get())); + OX_RETURN_ERROR(model(sc.interface(), val.get())); m_size += sc.size(); return {}; } @@ -80,7 +80,7 @@ template template constexpr ox::Error UnionSizeCatcher::field(StringViewCR, const T **val, std::size_t cnt) noexcept { for (std::size_t i = 0; i < cnt; ++i) { - oxReturnError(field("", &val[i])); + OX_RETURN_ERROR(field("", &val[i])); } return {}; } diff --git a/deps/ox/src/ox/std/bounds.hpp b/deps/ox/src/ox/std/bounds.hpp index 78090a58..e49fa511 100644 --- a/deps/ox/src/ox/std/bounds.hpp +++ b/deps/ox/src/ox/std/bounds.hpp @@ -126,11 +126,11 @@ constexpr void Bounds::set(const Point &pt1, const Point &pt2) noexcept { template constexpr Error model(T *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - 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()); + 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 {}; } diff --git a/deps/ox/src/ox/std/def.hpp b/deps/ox/src/ox/std/def.hpp index ab848ca0..eb7ee0e7 100644 --- a/deps/ox/src/ox/std/def.hpp +++ b/deps/ox/src/ox/std/def.hpp @@ -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 diff --git a/deps/ox/src/ox/std/defer.hpp b/deps/ox/src/ox/std/defer.hpp index 390ffebb..b1f0ea47 100644 --- a/deps/ox/src/ox/std/defer.hpp +++ b/deps/ox/src/ox/std/defer.hpp @@ -31,4 +31,4 @@ class Defer { } -#define oxDefer ox::Defer const oxConcat(oxDefer_, __LINE__) = +#define OX_DEFER ox::Defer const OX_CONCAT(oxDefer_, __LINE__) = diff --git a/deps/ox/src/ox/std/point.hpp b/deps/ox/src/ox/std/point.hpp index 57737f8f..c2738551 100644 --- a/deps/ox/src/ox/std/point.hpp +++ b/deps/ox/src/ox/std/point.hpp @@ -189,9 +189,9 @@ constexpr bool Point::operator!=(const Point &p) const noexcept { template constexpr Error model(T *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("x", &obj->x)); - oxReturnError(io->field("y", &obj->y)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("x", &obj->x)); + OX_RETURN_ERROR(io->field("y", &obj->y)); return {}; } diff --git a/deps/ox/src/ox/std/serialize.hpp b/deps/ox/src/ox/std/serialize.hpp index 4fc8778f..2ff5c625 100644 --- a/deps/ox/src/ox/std/serialize.hpp +++ b/deps/ox/src/ox/std/serialize.hpp @@ -63,10 +63,10 @@ constexpr ox::Error pad(Writer_c auto &w, const T *v) noexcept { template constexpr ox::Error serialize(Writer_c auto &w, const VectorMemMap &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 constexpr ox::Result> serialize(const T &in) noexcept { ox::Array out = {}; CharBuffWriter w(out); - oxReturnError(serialize(w, in)); + OX_RETURN_ERROR(serialize(w, in)); return out; }; diff --git a/deps/ox/src/ox/std/size.hpp b/deps/ox/src/ox/std/size.hpp index b2980ed9..b43d1f02 100644 --- a/deps/ox/src/ox/std/size.hpp +++ b/deps/ox/src/ox/std/size.hpp @@ -190,9 +190,9 @@ constexpr bool Size::operator!=(const Size &p) const noexcept { template constexpr Error model(T *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("width", &obj->width)); - oxReturnError(io->field("height", &obj->height)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("width", &obj->width)); + OX_RETURN_ERROR(io->field("height", &obj->height)); return {}; } diff --git a/deps/ox/src/ox/std/smallmap.hpp b/deps/ox/src/ox/std/smallmap.hpp index bb482215..0c3ab260 100644 --- a/deps/ox/src/ox/std/smallmap.hpp +++ b/deps/ox/src/ox/std/smallmap.hpp @@ -247,8 +247,8 @@ constexpr typename SmallMap::Pair &SmallMap::acces template constexpr Error model(T *io, ox::CommonPtrWith> auto *obj) noexcept { using Map = SmallMap; - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("pairs", &obj->m_pairs)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("pairs", &obj->m_pairs)); return {}; } diff --git a/deps/ox/src/ox/std/strconv.hpp b/deps/ox/src/ox/std/strconv.hpp index da60b2ec..5ef1bfc8 100644 --- a/deps/ox/src/ox/std/strconv.hpp +++ b/deps/ox/src/ox/std/strconv.hpp @@ -24,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) { @@ -37,13 +37,13 @@ constexpr ox::Error writeItoa(Integer v, ox::Writer_c auto &writer) noexcept { start = 'a'; digit -= 10; } - oxReturnError(writer.put(static_cast(start + digit))); + OX_RETURN_ERROR(writer.put(static_cast(start + digit))); ++it; } } } else { // 0 is a special case - oxReturnError(writer.put('0')); + OX_RETURN_ERROR(writer.put('0')); } return {}; } diff --git a/deps/ox/src/ox/std/test/tests.cpp b/deps/ox/src/ox/std/test/tests.cpp index 634e3b01..ede7e60a 100644 --- a/deps/ox/src/ox/std/test/tests.cpp +++ b/deps/ox/src/ox/std/test/tests.cpp @@ -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{}; @@ -173,10 +173,10 @@ OX_CLANG_NOWARN_END "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"); @@ -227,8 +227,8 @@ 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(ox::Error(v.size() != size, "Vector size incorrect")); - oxReturnError(ox::Error(v[v.size() - 1] != val, "Vector value wrong")); + 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"); @@ -386,7 +386,7 @@ OX_CLANG_NOWARN_END "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); diff --git a/deps/ox/src/ox/std/trace.hpp b/deps/ox/src/ox/std/trace.hpp index b156957f..d2050214 100644 --- a/deps/ox/src/ox/std/trace.hpp +++ b/deps/ox/src/ox/std/trace.hpp @@ -48,12 +48,12 @@ struct TraceMsgRcv { template constexpr Error model(T *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - 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()); + 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 constexpr Error model(T *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - 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()); + 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 constexpr Error model(T *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("appName", &obj->appName)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("appName", &obj->appName)); return {}; } @@ -101,8 +101,8 @@ struct InitTraceMsg { template constexpr Error model(T *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("appName", &obj->appName)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("appName", &obj->appName)); return {}; } diff --git a/deps/ox/src/ox/std/uuid.hpp b/deps/ox/src/ox/std/uuid.hpp index ca32aeeb..81a7a307 100644 --- a/deps/ox/src/ox/std/uuid.hpp +++ b/deps/ox/src/ox/std/uuid.hpp @@ -143,7 +143,7 @@ class UUID { if (seg.len() != 2) { 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 { template constexpr Error model(T *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("value", &obj->m_value)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("value", &obj->m_value)); return {}; } diff --git a/deps/ox/src/ox/std/vec.hpp b/deps/ox/src/ox/std/vec.hpp index 027b599e..7124cfb5 100644 --- a/deps/ox/src/ox/std/vec.hpp +++ b/deps/ox/src/ox/std/vec.hpp @@ -100,9 +100,9 @@ class Vec2 { template constexpr Error model(T *io, ox::CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->field("x", &obj->x)); - oxReturnError(io->field("y", &obj->y)); + OX_RETURN_ERROR(io->template setTypeInfo()); + OX_RETURN_ERROR(io->field("x", &obj->x)); + OX_RETURN_ERROR(io->field("y", &obj->y)); return {}; } diff --git a/deps/ox/src/ox/std/writer.hpp b/deps/ox/src/ox/std/writer.hpp index 9f75cf06..9ac3393d 100644 --- a/deps/ox/src/ox/std/writer.hpp +++ b/deps/ox/src/ox/std/writer.hpp @@ -74,10 +74,10 @@ class WriterT: public Writer_v { */ constexpr ox::Result 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; }