[ox] Remove OxError

This commit is contained in:
Gary Talent 2024-12-13 22:06:47 -06:00
parent 9881253f2a
commit 345fb03857
57 changed files with 383 additions and 384 deletions

View File

@ -18,7 +18,7 @@ ox::Result<ox::StringView> readClawTypeId(ox::BufferView buff) noexcept {
size_t outSz{};
const auto s1End = ox::strchr(buffRaw, ';', buffLen);
if (!s1End) {
return OxError(1, "Could not read Claw header");
return ox::Error(1, "Could not read Claw header");
}
auto const fmtSz = static_cast<std::size_t>(s1End - buffRaw) + 1;
buffRaw += fmtSz;
@ -26,7 +26,7 @@ ox::Result<ox::StringView> readClawTypeId(ox::BufferView buff) noexcept {
outSz += fmtSz;
auto const s2End = ox::strchr(buffRaw, ';', buffLen);
if (!s2End) {
return OxError(2, "Could not read Claw header");
return ox::Error(2, "Could not read Claw header");
}
auto const s2Size = static_cast<std::size_t>(s2End - buffRaw) + 1;
buffRaw += s2Size;
@ -34,7 +34,7 @@ ox::Result<ox::StringView> readClawTypeId(ox::BufferView buff) noexcept {
outSz += s2Size;
auto const s3End = ox::strchr(buffRaw, ';', buffLen) + 1;
if (!s3End) {
return OxError(3, "Could not read Claw header");
return ox::Error(3, "Could not read Claw header");
}
auto const s3Size = static_cast<std::size_t>(s3End - buffRaw);
buffRaw += s3Size;
@ -48,7 +48,7 @@ Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept {
auto buffLen = buff.size();
const auto s1End = ox::strchr(buffRaw, ';', buffLen);
if (!s1End) {
return OxError(1, "Could not read Claw header");
return ox::Error(1, "Could not read Claw header");
}
auto const s1Size = static_cast<std::size_t>(s1End - buffRaw);
StringView const fmt(buffRaw, s1Size);
@ -57,7 +57,7 @@ Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept {
auto const s2End = ox::strchr(buffRaw, ';', buffLen);
if (!s2End) {
return OxError(2, "Could not read Claw header");
return ox::Error(2, "Could not read Claw header");
}
auto const s2Size = static_cast<std::size_t>(s2End - buffRaw);
StringView const typeName(buffRaw, s2Size);
@ -66,7 +66,7 @@ Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept {
auto const s3End = ox::strchr(buffRaw, ';', buffLen);
if (!s3End) {
return OxError(3, "Could not read Claw header");
return ox::Error(3, "Could not read Claw header");
}
auto const s3Size = static_cast<std::size_t>(s3End - buffRaw);
StringView const versionStr(buffRaw, s3Size);
@ -78,7 +78,7 @@ Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept {
} else if (fmt == "O1") {
hdr.fmt = ClawFormat::Organic;
} else {
return OxError(4, "Claw format does not match any supported format/version combo");
return ox::Error(4, "Claw format does not match any supported format/version combo");
}
hdr.typeName = typeName;
std::ignore = ox::atoi(versionStr).copyTo(hdr.typeVersion);
@ -97,7 +97,7 @@ Result<ModelObject> readClaw(TypeStore &ts, BufferView buff) noexcept {
auto const [t, tdErr] = ts.getLoad(
header.typeName, header.typeVersion, header.typeParams);
if (tdErr) {
return OxError(3, "Could not load type descriptor");
return ox::Error(3, "Could not load type descriptor");
}
ModelObject obj;
oxReturnError(obj.setType(t));
@ -122,9 +122,9 @@ Result<ModelObject> readClaw(TypeStore &ts, BufferView buff) noexcept {
#endif
}
case ClawFormat::None:
return OxError(1);
return ox::Error(1);
}
return OxError(1);
return ox::Error(1);
}
}

View File

@ -42,10 +42,10 @@ template<typename T>
Error readClaw(ox::BufferView buff, T &val) {
oxRequire(header, readClawHeader(buff));
if (header.typeName != getModelTypeName<T>()) {
return OxError(Error_ClawTypeMismatch, "Claw Read: Type mismatch");
return ox::Error(Error_ClawTypeMismatch, "Claw Read: Type mismatch");
}
if (header.typeVersion != getModelTypeVersion<T>()) {
return OxError(Error_ClawTypeVersionMismatch, "Claw Read: Type Version mismatch");
return ox::Error(Error_ClawTypeVersionMismatch, "Claw Read: Type Version mismatch");
}
switch (header.fmt) {
case ClawFormat::Metal:
@ -65,9 +65,9 @@ Error readClaw(ox::BufferView buff, T &val) {
#endif
}
case ClawFormat::None:
return OxError(1);
return ox::Error(1);
}
return OxError(1);
return ox::Error(1);
}
template<typename T>

View File

@ -66,7 +66,7 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestUnion> auto *obj) {
oxReturnError(io->field("Bool", &obj->Bool));
oxReturnError(io->field("Int", &obj->Int));
oxReturnError(io->fieldCString("String", &obj->String));
return OxError(0);
return ox::Error(0);
}
template<typename T>
@ -75,7 +75,7 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStructNest> auto *obj) {
oxReturnError(io->field("Bool", &obj->Bool));
oxReturnError(io->field("Int", &obj->Int));
oxReturnError(io->field("String", &obj->String));
return OxError(0);
return ox::Error(0);
}
template<typename T>
@ -100,7 +100,7 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) {
oxReturnError(io->field("List", obj->List, 4));
oxReturnError(io->field("EmptyStruct", &obj->EmptyStruct));
oxReturnError(io->field("Struct", &obj->Struct));
return OxError(0);
return ox::Error(0);
}
static std::map<ox::StringView, ox::Error(*)()> tests = {
@ -114,7 +114,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(ch.fmt == ox::ClawFormat::Organic, "Format wrong");
oxAssert(ch.typeName == "com.drinkingtea.ox.claw.test.Header", "Type name wrong");
oxAssert(ch.typeVersion == 2, "Type version wrong");
return OxError(0);
return ox::Error(0);
}
},
{
@ -126,7 +126,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(ch.fmt == ox::ClawFormat::Metal, "Format wrong");
oxAssert(ch.typeName == "com.drinkingtea.ox.claw.test.Header2", "Type name wrong");
oxAssert(ch.typeVersion == 3, "Type version wrong");
return OxError(0);
return ox::Error(0);
}
},
{
@ -146,7 +146,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
// doesn't segfault
TestStruct ts;
oxReturnError(ox::writeClaw(ts, ox::ClawFormat::Metal));
return OxError(0);
return ox::Error(0);
}
},
{
@ -191,7 +191,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(testIn.Struct.String == testOut.Struct.String, "Struct.String value mismatch");
oxAssert(testIn.Struct.Bool == testOut.Struct.Bool, "Struct.Bool value mismatch");
return OxError(0);
return ox::Error(0);
}
},
}

View File

@ -39,7 +39,7 @@ struct TypeInfoCatcher {
}
constexpr Error field(...) noexcept {
return OxError(0);
return ox::Error(0);
}
static constexpr auto opType() {
@ -82,7 +82,7 @@ ox::Error writeClawHeader(Writer_c auto &writer, const T *t, ClawFormat fmt) noe
oxReturnError(write(writer, "O1;"));
break;
default:
return OxError(1);
return ox::Error(1);
}
oxReturnError(write(writer, detail::getTypeName(t)));
oxReturnError(writer.put(';'));
@ -112,7 +112,7 @@ Result<Buffer> writeClaw(
}
#else
if (fmt != ClawFormat::Metal) {
return OxError(1, "OC is not supported in this build");
return ox::Error(1, "OC is not supported in this build");
}
oxReturnError(writeMC(bw, t));
#endif

View File

@ -197,7 +197,7 @@ Error Signal<Args...>::disconnectObject(const void *receiver) const noexcept {
--i;
}
}
return OxError(1, "Signal::disconnectObject: Receiver was not found among this Signal's slots");
return ox::Error(1, "Signal::disconnectObject: Receiver was not found among this Signal's slots");
}
template<class... Args>
@ -213,7 +213,7 @@ Error Signal<Args...>::emitCheckError(Args... args) const noexcept {
for (auto &f : m_slots) {
f->call(args...);
}
return OxError(0);
return ox::Error(0);
} catch (const ox::Exception &ex) {
return ox::Error(ex.file, ex.line, ex.errCode, ex.msg);
}
@ -385,7 +385,7 @@ Error Signal<Error(Args...)>::disconnectObject(const void *receiver) const noexc
--i;
}
}
return OxError(1, "Signal::disconnectObject: Receiver was not found among this Signal's slots");
return ox::Error(1, "Signal::disconnectObject: Receiver was not found among this Signal's slots");
}
template<class... Args>
@ -400,7 +400,7 @@ Error Signal<Error(Args...)>::emitCheckError(Args... args) const noexcept {
for (auto &f : m_slots) {
oxReturnError(f->call(ox::forward<Args>(args)...));
}
return OxError(0);
return ox::Error(0);
}
}

View File

@ -17,7 +17,7 @@ struct TestStruct: public ox::SignalHandler {
int value = 0;
ox::Error method(int i) noexcept {
value = i;
return OxError(0);
return ox::Error(0);
}
};
@ -27,13 +27,13 @@ std::map<ox::StringView, std::function<ox::Error()>> tests = {
[] {
ox::Signal<ox::Error(int)> signal;
signal.connect([](int i) -> ox::Error {
return OxError(i != 5);
return ox::Error(i != 5);
});
TestStruct ts;
signal.connect(&ts, &TestStruct::method);
oxReturnError(signal.emitCheckError(5));
oxReturnError(OxError(ts.value != 5));
return OxError(0);
oxReturnError(ox::Error(ts.value != 5));
return ox::Error(0);
}
},
};

View File

@ -207,12 +207,12 @@ Error FileStoreTemplate<size_t>::format(void *buffer, std::size_t bufferSize) {
auto fsData = nb->malloc(sizeof(FileStoreData)).value;
if (!fsData.valid()) {
oxTrace("ox.fs.FileStoreTemplate.format.fail", "Could not read data section of FileStoreData");
return OxError(1, "Could not read data section of FileStoreData");
return ox::Error(1, "Could not read data section of FileStoreData");
}
auto data = nb->template dataOf<FileStoreData>(fsData);
if (!data.valid()) {
oxTrace("ox.fs.FileStoreTemplate.format.fail", "Could not read data section of FileStoreData");
return OxError(1, "Could not read data section of FileStoreData");
return ox::Error(1, "Could not read data section of FileStoreData");
}
new (data) FileStoreData;
return {};
@ -223,14 +223,14 @@ Error FileStoreTemplate<size_t>::setSize(std::size_t size) {
if (m_buffSize >= size) {
return m_buffer->setSize(static_cast<size_t>(size));
}
return OxError(1);
return ox::Error(1);
}
template<typename size_t>
Error FileStoreTemplate<size_t>::incLinks(uint64_t id) {
oxRequireM(item, find(static_cast<size_t>(id)).validate());
++item->links;
return OxError(0);
return ox::Error(0);
}
template<typename size_t>
@ -240,7 +240,7 @@ Error FileStoreTemplate<size_t>::decLinks(uint64_t id) {
if (item->links == 0) {
oxReturnError(remove(item));
}
return OxError(0);
return ox::Error(0);
}
template<typename size_t>
@ -298,7 +298,7 @@ Error FileStoreTemplate<size_t>::write(uint64_t id64, const void *data, FsSize_t
dest->id.get(), dest.offset(), destData.size());
fsData->rootNode = dest.offset();
oxTracef("ox.fs.FileStoreTemplate.write", "Root inode: {}", dest->id.get());
return OxError(0);
return ox::Error(0);
}
} else {
oxTrace("ox.fs.FileStoreTemplate.write.fail", "Could not place item due to absence of FileStore header.");
@ -307,7 +307,7 @@ Error FileStoreTemplate<size_t>::write(uint64_t id64, const void *data, FsSize_t
}
oxReturnError(m_buffer->free(dest));
}
return OxError(1);
return ox::Error(1);
}
template<typename size_t>
@ -322,7 +322,7 @@ Error FileStoreTemplate<size_t>::read(uint64_t id, void *out, FsSize_t outSize,
// error check
if (!src.valid()) {
oxTracef("ox.fs.FileStoreTemplate.read.fail", "Could not find requested item: {}", id);
return OxError(1, "Could not find requested item");
return ox::Error(1, "Could not find requested item");
}
auto srcData = m_buffer->template dataOf<uint8_t>(src);
@ -335,7 +335,7 @@ Error FileStoreTemplate<size_t>::read(uint64_t id, void *out, FsSize_t outSize,
oxTracef("ox.fs.FileStoreTemplate.read.fail", "Could not read data section of item: {}", id);
oxTracef("ox.fs.FileStoreTemplate.read.fail",
"Item data section size: {}, Expected size: {}", srcData.size(), outSize);
return OxError(1, "Invalid inode");
return ox::Error(1, "Invalid inode");
}
ox::memcpy(out, srcData, srcData.size());
@ -353,7 +353,7 @@ Error FileStoreTemplate<size_t>::read(uint64_t id, FsSize_t readStart, FsSize_t
// error check
if (!src.valid()) {
oxTracef("ox.fs.FileStoreTemplate.read.fail", "Could not find requested item: {}", id);
return OxError(1);
return ox::Error(1);
}
auto srcData = m_buffer->template dataOf<uint8_t>(src);
@ -366,7 +366,7 @@ Error FileStoreTemplate<size_t>::read(uint64_t id, FsSize_t readStart, FsSize_t
oxTracef("ox.fs.FileStoreTemplate.read.fail", "Could not read data section of item: {}", id);
oxTracef("ox.fs.FileStoreTemplate.read.fail",
"Item data section size: {}, Expected size: {}", srcData.size(), readSize);
return OxError(1);
return ox::Error(1);
}
ox::memcpy(out, srcData.get() + readStart, readSize);
@ -386,7 +386,7 @@ Error FileStoreTemplate<size_t>::read(uint64_t id, FsSize_t readStart,
// error check
if (!src.valid()) {
oxTracef("ox.fs.FileStoreTemplate.read.fail", "Could not find requested item: {}", id);
return OxError(1);
return ox::Error(1);
}
auto srcData = m_buffer->template dataOf<uint8_t>(src);
@ -399,7 +399,7 @@ Error FileStoreTemplate<size_t>::read(uint64_t id, FsSize_t readStart,
oxTracef("ox.fs.FileStoreTemplate.read.fail", "Could not read data section of item: {}", id);
oxTracef("ox.fs.FileStoreTemplate.read.fail",
"Item data section size: {}, Expected size: {}", srcData.size(), readSize);
return OxError(1);
return ox::Error(1);
}
ox::memcpy(out, srcData.get() + readStart, readSize);
@ -427,20 +427,20 @@ Error FileStoreTemplate<size_t>::resize() {
oxTracef("ox.fs.FileStoreTemplate.resize", "resize to: {}", newSize);
oxReturnError(m_buffer->setSize(newSize));
oxTracef("ox.fs.FileStoreTemplate.resize", "resized to: {}", m_buffer->size());
return OxError(0);
return ox::Error(0);
}
template<typename size_t>
Error FileStoreTemplate<size_t>::resize(std::size_t size, void *newBuff) {
if (m_buffer->size() > size) {
return OxError(1);
return ox::Error(1);
}
m_buffSize = static_cast<size_t>(size);
if (newBuff) {
m_buffer = reinterpret_cast<Buffer*>(newBuff);
oxReturnError(m_buffer->setSize(static_cast<size_t>(size)));
}
return OxError(0);
return ox::Error(0);
}
template<typename size_t>
@ -479,14 +479,14 @@ Error FileStoreTemplate<size_t>::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()));
}
return OxError(0);
return ox::Error(0);
}
template<typename size_t>
Result<typename FileStoreTemplate<size_t>::InodeId_t> FileStoreTemplate<size_t>::generateInodeId() {
auto fsData = fileStoreData();
if (!fsData) {
return OxError(1);
return ox::Error(1);
}
for (auto i = 0; i < 100; i++) {
auto inode = static_cast<typename FileStoreTemplate<size_t>::InodeId_t>(fsData->random.gen() % MaxValue<InodeId_t>);
@ -494,7 +494,7 @@ Result<typename FileStoreTemplate<size_t>::InodeId_t> FileStoreTemplate<size_t>:
return inode;
}
}
return OxError(2);
return ox::Error(2);
}
template<typename size_t>
@ -503,10 +503,10 @@ Error FileStoreTemplate<size_t>::compact() {
return m_buffer->compact([this, &isFirstItem](uint64_t oldAddr, ItemPtr item) -> Error {
if (isFirstItem) {
isFirstItem = false;
return OxError(0);
return ox::Error(0);
}
if (!item.valid()) {
return OxError(1);
return ox::Error(1);
}
oxTracef("ox.fs.FileStoreTemplate.compact.moveItem", "Moving Item: {} from {} to {}", item->id.get(), oldAddr, item.offset());
// update rootInode if this is it
@ -524,7 +524,7 @@ Error FileStoreTemplate<size_t>::compact() {
parent->right = item;
}
}
return OxError(0);
return ox::Error(0);
});
}
@ -544,7 +544,7 @@ template<typename size_t>
Error FileStoreTemplate<size_t>::placeItem(ItemPtr item) {
auto fsData = fileStoreData();
if (!fsData) {
return OxError(1);
return ox::Error(1);
}
oxRequireM(root, m_buffer->ptr(fsData->rootNode).validate());
if (root->id == item->id) {
@ -552,7 +552,7 @@ Error FileStoreTemplate<size_t>::placeItem(ItemPtr item) {
item->left = root->left;
item->right = root->right;
oxTracef("ox.fs.FileStoreTemplate.placeItem", "Overwrote Root Item: {}", item->id.get());
return OxError(0);
return ox::Error(0);
} else {
return placeItem(root, item);
}
@ -562,7 +562,7 @@ template<typename size_t>
Error FileStoreTemplate<size_t>::placeItem(ItemPtr root, ItemPtr item, int depth) {
if (depth > 5000) {
oxTrace("ox.fs.FileStoreTemplate.placeItem.fail", "Excessive recursion depth, stopping before stack overflow.");
return OxError(2);
return ox::Error(2);
}
if (item->id > root->id) {
auto right = m_buffer->ptr(root->right);
@ -573,7 +573,7 @@ Error FileStoreTemplate<size_t>::placeItem(ItemPtr root, ItemPtr item, int depth
item->right = right->right;
}
oxTracef("ox.fs.FileStoreTemplate.placeItem", "Placed Item: {}", item->id.get());
return OxError(0);
return ox::Error(0);
} else {
return placeItem(right, item, depth + 1);
}
@ -586,13 +586,13 @@ Error FileStoreTemplate<size_t>::placeItem(ItemPtr root, ItemPtr item, int depth
item->right = left->right;
}
oxTracef("ox.fs.FileStoreTemplate.placeItem", "Placed Item: {}", item->id.get());
return OxError(0);
return ox::Error(0);
} else {
return placeItem(left, item, depth + 1);
}
} else {
oxTrace("ox.fs.FileStoreTemplate.placeItem.fail", "Cannot insert an item on itself.");
return OxError(1, "Cannot insert an item on itself.");
return ox::Error(1, "Cannot insert an item on itself.");
}
}
@ -600,7 +600,7 @@ template<typename size_t>
Error FileStoreTemplate<size_t>::unplaceItem(ItemPtr item) {
auto fsData = fileStoreData();
if (!fsData) {
return OxError(1);
return ox::Error(1);
}
oxRequireM(root, m_buffer->ptr(fsData->rootNode).validate());
if (root->id == item->id) {
@ -624,7 +624,7 @@ Error FileStoreTemplate<size_t>::unplaceItem(ItemPtr item) {
} else {
fsData->rootNode = 0;
}
return OxError(0);
return ox::Error(0);
} else {
return unplaceItem(root, item);
}
@ -634,7 +634,7 @@ template<typename size_t>
Error FileStoreTemplate<size_t>::unplaceItem(ItemPtr root, ItemPtr item, int depth) {
if (depth >= 5000) {
oxTrace("ox.fs.FileStoreTemplate.unplaceItem.fail", "Excessive recursion depth, stopping before stack overflow.");
return OxError(1, "Excessive recursion depth, stopping before stack overflow.");
return ox::Error(1, "Excessive recursion depth, stopping before stack overflow.");
}
if (item->id > root->id) {
auto right = m_buffer->ptr(root->right);
@ -653,7 +653,7 @@ Error FileStoreTemplate<size_t>::unplaceItem(ItemPtr root, ItemPtr item, int dep
return unplaceItem(left, item, depth + 1);
}
} else {
return OxError(1);
return ox::Error(1);
}
if (item->right) {
oxReturnError(placeItem(m_buffer->ptr(item->right)));
@ -661,7 +661,7 @@ Error FileStoreTemplate<size_t>::unplaceItem(ItemPtr root, ItemPtr item, int dep
if (item->left) {
oxReturnError(placeItem(m_buffer->ptr(item->left)));
}
return OxError(0);
return ox::Error(0);
}
template<typename size_t>
@ -669,9 +669,9 @@ Error FileStoreTemplate<size_t>::remove(ItemPtr item) {
if (item.valid()) {
oxReturnError(unplaceItem(item));
oxReturnError(m_buffer->free(item));
return OxError(0);
return ox::Error(0);
}
return OxError(1);
return ox::Error(1);
}
template<typename size_t>

View File

@ -55,7 +55,7 @@ struct OX_PACKED DirectoryEntry {
ox::strncpy(d->name, name.data(), ox::min(maxStrSz, name.len()));
return {};
}
return OxError(1);
return ox::Error(1);
}
ptrarith::Ptr<DirectoryEntryData, InodeId_t> data() noexcept {
@ -145,7 +145,7 @@ Error Directory<FileStore, InodeId_t>::init() noexcept {
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
if (!buff.valid()) {
m_size = 0;
return OxError(1);
return ox::Error(1);
}
new (buff) Buffer(Size);
m_size = Size;
@ -164,7 +164,7 @@ Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents) {
// if this is not the last item in the path and parents is disabled,
// return an error
if (!parents && path.hasNext()) {
return OxError(1);
return ox::Error(1);
}
childInode = m_fs.generateInodeId();
oxTracef("ox.fs.Directory.mkdir", "Generated Inode ID: {}", childInode.value);
@ -203,7 +203,7 @@ Error Directory<FileStore, InodeId_t>::write(PathIterator path, uint64_t inode64
return Directory(m_fs, nextChild).write(path.next(), inode);
} else {
oxTracef("ox.fs.Directory.write", "{} not found and not allowed to create it.", name);
return OxError(1, "File not found and not allowed to create it.");
return ox::Error(1, "File not found and not allowed to create it.");
}
} else {
oxTrace("ox.fs.Directory.write", path.fullPath());
@ -217,7 +217,7 @@ Error Directory<FileStore, InodeId_t>::write(PathIterator path, uint64_t inode64
auto old = m_fs.read(m_inodeId).template to<Buffer>();
if (!old.valid()) {
oxTrace("ox.fs.Directory.write.fail", "Could not read existing version of Directory");
return OxError(1, "Could not read existing version of Directory");
return ox::Error(1, "Could not read existing version of Directory");
}
const auto pathSize = name.len() + 1;
const auto entryDataSize = DirectoryEntry<InodeId_t>::DirectoryEntryData::spaceNeeded(pathSize);
@ -225,13 +225,13 @@ Error Directory<FileStore, InodeId_t>::write(PathIterator path, uint64_t inode64
auto cpy = ox_malloca(newSize, Buffer, *old, oldStat.size);
if (cpy == nullptr) {
oxTrace("ox.fs.Directory.write.fail", "Could not allocate memory for copy of Directory");
return OxError(1, "Could not allocate memory for copy of Directory");
return ox::Error(1, "Could not allocate memory for copy of Directory");
}
oxReturnError(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 OxError(1, "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()));
@ -259,7 +259,7 @@ Error Directory<FileStore, InodeId_t>::remove(PathIterator path) noexcept {
}
} else {
oxTrace("ox.fs.Directory.remove.fail", "Could not find directory buffer");
return OxError(1, "Could not find directory buffer");
return ox::Error(1, "Could not find directory buffer");
}
return {};
}
@ -271,7 +271,7 @@ Error Directory<FileStore, InodeId_t>::ls(F cb) noexcept {
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
if (!buff.valid()) {
oxTrace("ox.fs.Directory.ls.fail", "Could not directory buffer");
return OxError(1, "Could not directory buffer");
return ox::Error(1, "Could not directory buffer");
}
oxTrace("ox.fs.Directory.ls", "Found directory buffer.");
for (auto i = buff->iterator(); i.valid(); i.next()) {
@ -291,7 +291,7 @@ Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
if (!buff.valid()) {
oxTrace("ox.fs.Directory.findEntry.fail", "Could not findEntry directory buffer");
return OxError(2, "Could not findEntry directory buffer");
return ox::Error(2, "Could not findEntry directory buffer");
}
oxTracef("ox.fs.Directory.findEntry", "Found directory buffer, size: {}", buff.size());
for (auto i = buff->iterator(); i.valid(); i.next()) {
@ -307,7 +307,7 @@ Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry
}
}
oxTrace("ox.fs.Directory.findEntry.fail", "Entry not present");
return OxError(1, "Entry not present");
return ox::Error(1, "Entry not present");
}
template<typename FileStore, typename InodeId_t>

View File

@ -89,7 +89,7 @@ class FileAddress {
case FileAddressType::Inode:
return m_data.inode;
default:
return OxError(1);
return ox::Error(1);
}
}
@ -100,7 +100,7 @@ class FileAddress {
case FileAddressType::ConstPath:
return ox::CStringView(m_data.constPath);
default:
return OxError(1);
return ox::Error(1);
}
}

View File

@ -21,7 +21,7 @@ Result<const char*> MemFS::directAccess(const FileAddress &addr) const noexcept
case FileAddressType::Path:
return directAccess(StringView(addr.getPath().value));
default:
return OxError(1);
return ox::Error(1);
}
}
@ -33,7 +33,7 @@ Error FileSystem::read(const FileAddress &addr, void *buffer, std::size_t size)
case FileAddressType::Path:
return readFilePath(StringView(addr.getPath().value), buffer, size);
default:
return OxError(1);
return ox::Error(1);
}
}
@ -57,9 +57,9 @@ Error FileSystem::read(const FileAddress &addr, std::size_t readStart, std::size
return read(addr.getInode().value, readStart, readSize, buffer, size);
case FileAddressType::ConstPath:
case FileAddressType::Path:
return OxError(2, "Unsupported for path lookups");
return ox::Error(2, "Unsupported for path lookups");
default:
return OxError(1);
return ox::Error(1);
}
}
@ -71,7 +71,7 @@ Error FileSystem::remove(const FileAddress &addr, bool recursive) noexcept {
case FileAddressType::Path:
return remove(StringView(addr.getPath().value), recursive);
default:
return OxError(1);
return ox::Error(1);
}
}
@ -83,7 +83,7 @@ Error FileSystem::write(const FileAddress &addr, const void *buffer, uint64_t si
case FileAddressType::Path:
return writeFilePath(StringView(addr.getPath().value), buffer, size, fileType);
default:
return OxError(1);
return ox::Error(1);
}
}
@ -95,7 +95,7 @@ Result<FileStat> FileSystem::stat(const FileAddress &addr) const noexcept {
case FileAddressType::Path:
return statPath(StringView(addr.getPath().value));
default:
return OxError(1);
return ox::Error(1);
}
}

View File

@ -298,10 +298,10 @@ Error FileSystemTemplate<FileStore, Directory>::format(void *buff, uint64_t buff
if (!fs.read(fd.rootDirInode).valid()) {
oxTrace("ox.fs.FileSystemTemplate.format.error", "FileSystemTemplate::format did not correctly create root directory");
return OxError(1);
return ox::Error(1);
}
return OxError(0);
return ox::Error(0);
}
template<typename FileStore, typename Directory>
@ -318,7 +318,7 @@ Error FileSystemTemplate<FileStore, Directory>::move(StringViewCR src, StringVie
oxRequireM(inode, rootDir.find(src));
oxReturnError(rootDir.write(dest, inode));
oxReturnError(rootDir.remove(src));
return OxError(0);
return ox::Error(0);
}
template<typename FileStore, typename Directory>
@ -328,7 +328,7 @@ Error FileSystemTemplate<FileStore, Directory>::readFilePath(StringViewCR path,
Directory rootDir(m_fs, fd.rootDirInode);
oxRequire(s, stat(path));
if (s.size > buffSize) {
return OxError(1, "Buffer to small to load file");
return ox::Error(1, "Buffer to small to load file");
}
return readFileInodeRange(s.inode, 0, static_cast<size_t>(s.size), buffer, &buffSize);
}
@ -346,7 +346,7 @@ Error FileSystemTemplate<FileStore, Directory>::readFileInode(uint64_t inode, vo
oxTracef("ox.fs.FileSystemTemplate.readFileInode", "{}", inode);
oxRequire(s, stat(inode));
if (s.size > buffSize) {
return OxError(1, "Buffer to small to load file");
return ox::Error(1, "Buffer to small to load file");
}
return readFileInodeRange(inode, 0, static_cast<size_t>(s.size), buffer, &buffSize);
}
@ -360,7 +360,7 @@ template<typename FileStore, typename Directory>
Result<const char*> FileSystemTemplate<FileStore, Directory>::directAccessInode(uint64_t inode) const noexcept {
auto data = m_fs.read(inode);
if (!data.valid()) {
return OxError(1, "Data not valid");
return ox::Error(1, "Data not valid");
}
return reinterpret_cast<char*>(data.get());
}
@ -370,7 +370,7 @@ Result<Vector<String>> FileSystemTemplate<FileStore, Directory>::ls(StringViewCR
Vector<String> out;
oxReturnError(ls(path, [&out](StringViewCR name, typename FileStore::InodeId_t) {
out.emplace_back(name);
return OxError(0);
return ox::Error(0);
}));
return out;
}
@ -398,9 +398,9 @@ Error FileSystemTemplate<FileStore, Directory>::remove(StringViewCR path, bool r
}
} else {
oxTrace("FileSystemTemplate.remove.fail", "Tried to remove directory without recursive setting.");
return OxError(1);
return ox::Error(1);
}
return OxError(0);
return ox::Error(0);
}
template<typename FileStore, typename Directory>

View File

@ -39,7 +39,7 @@ Error PassThroughFS::mkdir(StringViewCR path, bool recursive) noexcept {
success = true;
} else {
success = std::filesystem::create_directories(p, ec);
oxReturnError(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed"));
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed"));
}
} else {
std::error_code ec;
@ -48,26 +48,26 @@ Error PassThroughFS::mkdir(StringViewCR path, bool recursive) noexcept {
success = true;
} else {
success = std::filesystem::create_directory(p, ec);
oxReturnError(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed"));
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed"));
}
}
return OxError(success ? 0 : 1);
return ox::Error(success ? 0 : 1);
}
Error PassThroughFS::move(StringViewCR src, StringViewCR dest) noexcept {
std::error_code ec;
std::filesystem::rename(m_path / stripSlash(src), m_path / stripSlash(dest), ec);
if (ec.value()) {
return OxError(1);
return ox::Error(1);
}
return OxError(0);
return ox::Error(0);
}
Result<Vector<String>> PassThroughFS::ls(StringViewCR dir) const noexcept {
Vector<String> out;
std::error_code ec;
const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec);
oxReturnError(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: ls failed"));
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: ls failed"));
for (const auto &p : di) {
const auto u8p = p.path().filename().u8string();
out.emplace_back(reinterpret_cast<const char*>(u8p.c_str()));
@ -77,20 +77,20 @@ Result<Vector<String>> PassThroughFS::ls(StringViewCR dir) const noexcept {
Error PassThroughFS::remove(StringViewCR path, bool recursive) noexcept {
if (recursive) {
return OxError(std::filesystem::remove_all(m_path / stripSlash(path)) != 0);
return ox::Error(std::filesystem::remove_all(m_path / stripSlash(path)) != 0);
} else {
return OxError(std::filesystem::remove(m_path / stripSlash(path)) != 0);
return ox::Error(std::filesystem::remove(m_path / stripSlash(path)) != 0);
}
}
Error PassThroughFS::resize(uint64_t, void*) noexcept {
// unsupported
return OxError(1, "resize is not supported by PassThroughFS");
return ox::Error(1, "resize is not supported by PassThroughFS");
}
Result<FileStat> PassThroughFS::statInode(uint64_t) const noexcept {
// unsupported
return OxError(1, "statInode(uint64_t) is not supported by PassThroughFS");
return ox::Error(1, "statInode(uint64_t) is not supported by PassThroughFS");
}
Result<FileStat> PassThroughFS::statPath(StringViewCR path) const noexcept {
@ -101,7 +101,7 @@ Result<FileStat> 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(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: stat failed"));
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(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<uint64_t> PassThroughFS::available() const noexcept {
std::error_code ec;
const auto s = std::filesystem::space(m_path, ec);
oxReturnError(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: could not get FS size"));
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: could not get FS size"));
return s.available;
}
Result<uint64_t> PassThroughFS::size() const noexcept {
std::error_code ec;
const auto s = std::filesystem::space(m_path, ec);
oxReturnError(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: could not get FS size"));
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: could not get FS size"));
return s.capacity;
}
@ -128,7 +128,7 @@ char *PassThroughFS::buff() noexcept {
}
Error PassThroughFS::walk(Error(*)(uint8_t, uint64_t, uint64_t)) noexcept {
return OxError(1, "walk(Error(*)(uint8_t, uint64_t, uint64_t)) is not supported by PassThroughFS");
return ox::Error(1, "walk(Error(*)(uint8_t, uint64_t, uint64_t)) is not supported by PassThroughFS");
}
bool PassThroughFS::valid() const noexcept {
@ -147,24 +147,24 @@ Error PassThroughFS::readFilePath(StringViewCR path, void *buffer, std::size_t b
file.seekg(0, std::ios::beg);
if (size > buffSize) {
oxTracef("ox.fs.PassThroughFS.read.error", "Read failed: Buffer too small: {}", path);
return OxError(1);
return ox::Error(1);
}
file.read(static_cast<char*>(buffer), static_cast<std::streamsize>(buffSize));
} catch (const std::fstream::failure &f) {
oxTracef("ox.fs.PassThroughFS.read.error", "Read of {} failed: {}", path, f.what());
return OxError(2);
return ox::Error(2);
}
return OxError(0);
return ox::Error(0);
}
Error PassThroughFS::readFileInode(uint64_t, void*, std::size_t) noexcept {
// unsupported
return OxError(1, "readFileInode(uint64_t, void*, std::size_t) is not supported by PassThroughFS");
return ox::Error(1, "readFileInode(uint64_t, void*, std::size_t) is not supported by PassThroughFS");
}
Error PassThroughFS::readFileInodeRange(uint64_t, std::size_t, std::size_t, void*, std::size_t*) noexcept {
// unsupported
return OxError(1, "read(uint64_t, std::size_t, std::size_t, void*, std::size_t*) is not supported by PassThroughFS");
return ox::Error(1, "read(uint64_t, std::size_t, std::size_t, void*, std::size_t*) is not supported by PassThroughFS");
}
Error PassThroughFS::writeFilePath(StringViewCR path, const void *buffer, uint64_t size, FileType) noexcept {
@ -174,14 +174,14 @@ Error PassThroughFS::writeFilePath(StringViewCR path, const void *buffer, uint64
f.write(static_cast<const char*>(buffer), static_cast<std::streamsize>(size));
} catch (const std::fstream::failure &f) {
oxTracef("ox.fs.PassThroughFS.read.error", "Write of {} failed: {}", path, f.what());
return OxError(1);
return ox::Error(1);
}
return OxError(0);
return ox::Error(0);
}
Error PassThroughFS::writeFileInode(uint64_t, const void*, uint64_t, FileType) noexcept {
// unsupported
return OxError(1, "writeFileInode(uint64_t, void*, uint64_t, uint8_t) is not supported by PassThroughFS");
return ox::Error(1, "writeFileInode(uint64_t, void*, uint64_t, uint8_t) is not supported by PassThroughFS");
}
std::string_view PassThroughFS::stripSlash(StringView path) noexcept {

View File

@ -92,11 +92,11 @@ template<typename F>
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(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: ls failed"));
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: ls failed"));
for (auto &p : di) {
oxReturnError(cb(p.path().filename().c_str(), 0));
}
return OxError(0);
return ox::Error(0);
}
}

View File

@ -36,9 +36,9 @@ Error PathIterator::dirPath(char *out, std::size_t outSize) {
if (idx >= 0 && size < outSize) {
ox::memcpy(out, m_path, size);
out[size] = 0;
return OxError(0);
return ox::Error(0);
} else {
return OxError(1);
return ox::Error(1);
}
}
@ -47,11 +47,11 @@ Error PathIterator::get(StringView &fileName) {
std::size_t size = 0;
if (m_iterator >= m_maxSize) {
oxTracef("ox.fs.PathIterator.get", "m_iterator ({}) >= m_maxSize ({})", m_iterator, m_maxSize);
return OxError(1);
return ox::Error(1);
}
if (!ox::strlen(&m_path[m_iterator])) {
oxTrace("ox.fs.PathIterator.get", "!ox::strlen(&m_path[m_iterator])");
return OxError(1);
return ox::Error(1);
}
auto start = m_iterator;
if (m_path[start] == '/') {
@ -67,7 +67,7 @@ Error PathIterator::get(StringView &fileName) {
size = end - start;
// cannot fit the output in the output parameter
if (size >= MaxFileNameLength || size == 0) {
return OxError(1);
return ox::Error(1);
}
fileName = ox::substr(m_path, start, start + size);
// truncate trailing /
@ -83,9 +83,9 @@ Error PathIterator::get(StringView &fileName) {
*/
Error PathIterator::next(StringView &fileName) {
std::size_t size = 0;
auto retval = OxError(1);
auto retval = ox::Error(1);
if (m_iterator < m_maxSize && ox::strlen(&m_path[m_iterator])) {
retval = OxError(0);
retval = ox::Error(0);
if (m_path[m_iterator] == '/') {
m_iterator++;
}
@ -100,7 +100,7 @@ Error PathIterator::next(StringView &fileName) {
size = end - start;
// cannot fit the output in the output parameter
if (size >= MaxFileNameLength) {
return OxError(1);
return ox::Error(1);
}
fileName = ox::substr(m_path, start, start + size);
// truncate trailing /
@ -115,10 +115,10 @@ Error PathIterator::next(StringView &fileName) {
Result<std::size_t> PathIterator::nextSize() const {
std::size_t size = 0;
auto retval = OxError(1);
auto retval = ox::Error(1);
auto it = m_iterator;
if (it < m_maxSize && ox::strlen(&m_path[it])) {
retval = OxError(0);
retval = ox::Error(0);
if (m_path[it] == '/') {
it++;
}

View File

@ -284,14 +284,14 @@ Result<typename NodeBuffer<size_t, Item>::ItemPtr> NodeBuffer<size_t, Item>::mal
addr = m_header.firstItem;
} else {
oxTrace("ox.ptrarith.NodeBuffer.malloc.fail", "NodeBuffer is in invalid state.");
return OxError(1, "NodeBuffer is in invalid state.");
return ox::Error(1, "NodeBuffer is in invalid state.");
}
}
oxTracef("ox.ptrarith.NodeBuffer.malloc", "buffer size: {}; addr: {}; fullSize: {}", m_header.size.get(), addr, fullSize);
auto out = ItemPtr(this, m_header.size, addr, fullSize);
if (!out.valid()) {
oxTrace("ox.ptrarith.NodeBuffer.malloc.fail", "Unknown");
return OxError(1, "NodeBuffer::malloc: unknown failure");
return ox::Error(1, "NodeBuffer::malloc: unknown failure");
}
ox::memset(out, 0, fullSize);
new (out) Item;
@ -304,7 +304,7 @@ Result<typename NodeBuffer<size_t, Item>::ItemPtr> NodeBuffer<size_t, Item>::mal
first->prev = out.offset();
} else {
oxTrace("ox.ptrarith.NodeBuffer.malloc.fail", "NodeBuffer malloc failed due to invalid first element pointer.");
return OxError(1, "NodeBuffer malloc failed due to invalid first element pointer.");
return ox::Error(1, "NodeBuffer malloc failed due to invalid first element pointer.");
}
if (oldLast.valid()) {
@ -314,7 +314,7 @@ Result<typename NodeBuffer<size_t, Item>::ItemPtr> NodeBuffer<size_t, Item>::mal
if (out.offset() != first.offset()) {
// if this is not the first allocation, there should be an oldLast
oxTrace("ox.ptrarith.NodeBuffer.malloc.fail", "NodeBuffer malloc failed due to invalid last element pointer.");
return OxError(1, "NodeBuffer malloc failed due to invalid last element pointer.");
return ox::Error(1, "NodeBuffer malloc failed due to invalid last element pointer.");
}
out->prev = out.offset();
}
@ -323,7 +323,7 @@ Result<typename NodeBuffer<size_t, Item>::ItemPtr> NodeBuffer<size_t, Item>::mal
return out;
}
oxTracef("ox.ptrarith.NodeBuffer.malloc.fail", "Insufficient space: {} needed, {} available", fullSize, available());
return OxError(1);
return ox::Error(1);
}
template<typename size_t, typename Item>
@ -346,15 +346,15 @@ Error NodeBuffer<size_t, Item>::free(ItemPtr item) noexcept {
} else {
if (!prev.valid()) {
oxTracef("ox.ptrarith.NodeBuffer.free.fail", "NodeBuffer free failed due to invalid prev element pointer: {}", prev.offset());
return OxError(1);
return ox::Error(1);
}
if (!next.valid()) {
oxTracef("ox.ptrarith.NodeBuffer.free.fail", "NodeBuffer free failed due to invalid next element pointer: {}", next.offset());
return OxError(1);
return ox::Error(1);
}
}
m_header.bytesUsed -= item.size();
return OxError(0);
return ox::Error(0);
}
template<typename size_t, typename Item>
@ -365,12 +365,12 @@ Error NodeBuffer<size_t, Item>::setSize(std::size_t size) noexcept {
oxTracef("ox.ptrarith.NodeBuffer.setSize", "end: {}", end);
if (end > size) {
// resizing to less than buffer size
return OxError(1);
return ox::Error(1);
} else {
m_header.size = static_cast<size_t>(size);
auto data = reinterpret_cast<uint8_t*>(this) + end;
ox::memset(data, 0, size - end);
return OxError(0);
return ox::Error(0);
}
}
@ -401,10 +401,10 @@ Error NodeBuffer<size_t, Item>::compact(F cb) noexcept {
auto dest = ptr(sizeof(*this));
while (dest.offset() <= src.offset()) {
if (!src.valid()) {
return OxError(1);
return ox::Error(1);
}
if (!dest.valid()) {
return OxError(2);
return ox::Error(2);
}
// move node
ox::memcpy(dest, src, src->fullSize());
@ -422,7 +422,7 @@ Error NodeBuffer<size_t, Item>::compact(F cb) noexcept {
src = ptr(dest->next);
dest = uninitializedPtr(dest.offset() + dest->fullSize());
}
return OxError(0);
return ox::Error(0);
}
template<typename size_t, typename Item>

View File

@ -254,7 +254,7 @@ constexpr Result<Ptr<T, size_t, minOffset>> Ptr<T, size_t, minOffset>::validate(
if (valid()) {
return *this;
}
return OxError(1);
return ox::Error(1);
}
}

View File

@ -52,7 +52,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
oxAssert(buffer->free(a1), "Free failed.");
oxAssert(buffer->free(a2), "Free failed.");
oxAssert(buffer->setSize(buffer->size() - buffer->available()), "Resize failed.");
return OxError(0);
return ox::Error(0);
}
},
{
@ -64,7 +64,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
oxAssert(it.next(buff) == 0 && buff == "usr", "PathIterator shows wrong next");
oxAssert(it.next(buff) == 0 && buff == "share", "PathIterator shows wrong next");
oxAssert(it.next(buff) == 0 && buff == "charset.gbag", "PathIterator shows wrong next");
return OxError(0);
return ox::Error(0);
}
},
{
@ -77,7 +77,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
oxExpect(buff, "usr");
oxAssert(it.next(buff), "PathIterator::next returned error");
oxExpect(buff, "share");
return OxError(0);
return ox::Error(0);
}
},
{
@ -87,7 +87,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
ox::PathIterator it(path.c_str(), path.len());
ox::StringView buff;
oxAssert(it.next(buff) == 0 && buff == "\0", "PathIterator shows wrong next");
return OxError(0);
return ox::Error(0);
}
},
{
@ -99,7 +99,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
oxAssert(it.next(buff) == 0 && buff == "usr", "PathIterator shows wrong next");
oxAssert(it.next(buff) == 0 && buff == "share", "PathIterator shows wrong next");
oxAssert(it.next(buff) == 0 && buff == "charset.gbag", "PathIterator shows wrong next");
return OxError(0);
return ox::Error(0);
}
},
{
@ -110,7 +110,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
ox::StringView buff;
oxAssert(it.next(buff) == 0 && buff == "usr", "PathIterator shows wrong next");
oxAssert(it.next(buff) == 0 && buff == "share", "PathIterator shows wrong next");
return OxError(0);
return ox::Error(0);
}
},
{
@ -120,7 +120,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
ox::PathIterator it(path.c_str(), path.len());
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
oxAssert(it.dirPath(buff, path.len()) == 0 && ox::strcmp(buff, "/usr/share/") == 0, "PathIterator shows incorrect dir path");
return OxError(0);
return ox::Error(0);
}
},
{
@ -130,7 +130,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
ox::PathIterator it(path, ox::strlen(path));
oxAssert(it.hasNext(), "PathIterator shows incorrect hasNext");
oxAssert(!it.next().hasNext(), "PathIterator shows incorrect hasNext");
return OxError(0);
return ox::Error(0);
}
},
{
@ -142,7 +142,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
auto subPtr = p.subPtr<uint64_t>(50);
oxAssert(subPtr.valid(), "Ptr::subPtr: Ptr subPtr is invalid.");
return OxError(0);
return ox::Error(0);
}
},
{
@ -155,7 +155,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
auto first = list->firstItem();
oxAssert(first.valid(), "NodeBuffer::insert: Could not access first item");
oxAssert(first->size() == 50, "NodeBuffer::insert: First item size invalid");
return OxError(0);
return ox::Error(0);
}
},
{
@ -176,7 +176,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
size_t str1ReadSize = 0;
oxAssert(fileStore.read(4, reinterpret_cast<void*>(str1Read), str1Len, &str1ReadSize), "FileStore::read 1 failed.");
return OxError(0);
return ox::Error(0);
}
},
{
@ -203,7 +203,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
oxTrace("ox.fs.test.Directory") << "write 3";
oxAssert(dir.write("/file2", 2), "Directory write of file2 failed");
return OxError(0);
return ox::Error(0);
}
},
{
@ -220,7 +220,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
oxAssert(fs.stat("/l1d1/l2d1/l3d1").error, "mkdir failed");
oxAssert(fs.mkdir("/l1d1/l2d2", true), "mkdir failed");
oxAssert(fs.stat("/l1d1/l2d2").error, "mkdir failed");
return OxError(0);
return ox::Error(0);
}
},
},

View File

@ -20,7 +20,7 @@ static ox::Result<Buff> loadFsBuff(const char *path) noexcept {
std::ifstream file(path, std::ios::binary | std::ios::ate);
if (!file.good()) {
oxErrorf("Could not find OxFS file: {}", path);
return OxError(1, "Could not find OxFS file");
return ox::Error(1, "Could not find OxFS file");
}
try {
const auto size = static_cast<std::size_t>(file.tellg());
@ -30,7 +30,7 @@ static ox::Result<Buff> loadFsBuff(const char *path) noexcept {
return Buff{buff, size};
} catch (const std::ios_base::failure &e) {
oxErrorf("Could not read OxFS file: {}", e.what());
return OxError(2, "Could not read OxFS file");
return ox::Error(2, "Could not read OxFS file");
}
}
@ -42,29 +42,29 @@ static ox::Result<ox::UniquePtr<ox::FileSystem>> loadFs(const char *path) noexce
static ox::Error runLs(ox::FileSystem *fs, ox::Span<const char*> args) noexcept {
if (args.size() < 2) {
oxErr("Must provide a directory to ls\n");
return OxError(1);
return ox::Error(1);
}
oxRequire(files, fs->ls(args[1]));
for (const auto &file : files) {
oxOutf("{}\n", file);
}
return OxError(0);
return ox::Error(0);
}
static ox::Error runRead(ox::FileSystem *fs, ox::Span<const char*> args) noexcept {
if (args.size() < 2) {
oxErr("Must provide a path to a file to read\n");
return OxError(1);
return ox::Error(1);
}
oxRequire(buff, fs->read(ox::StringView(args[1])));
std::ignore = fwrite(buff.data(), sizeof(decltype(buff)::value_type), buff.size(), stdout);
return OxError(0);
return ox::Error(0);
}
static ox::Error run(int argc, const char **argv) noexcept {
if (argc < 3) {
oxErr("OxFS file and subcommand arguments are required\n");
return OxError(1);
return ox::Error(1);
}
auto const args = ox::Span{argv, static_cast<size_t>(argc)};
auto const fsPath = args[1];
@ -75,7 +75,7 @@ static ox::Error run(int argc, const char **argv) noexcept {
} else if (subCmd == "read") {
return runRead(fs.get(), args + 2);
}
return OxError(1);
return ox::Error(1);
}
int main(int argc, const char **argv) {

View File

@ -34,7 +34,7 @@ class CirculerBuffer {
constexpr ox::Error put(char v) noexcept {
return write(&v, 1);
if (1 > avail()) {
return OxError(1, "Insufficient space in buffer");
return ox::Error(1, "Insufficient space in buffer");
}
m_buff[m_writePt] = v;
++m_writePt;
@ -43,7 +43,7 @@ class CirculerBuffer {
constexpr ox::Error write(const char *buff, std::size_t sz) noexcept {
if (sz > avail()) {
return OxError(1, "Insufficient space in buffer");
return ox::Error(1, "Insufficient space in buffer");
}
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
// write seg 1
@ -63,7 +63,7 @@ OX_ALLOW_UNSAFE_BUFFERS_END
constexpr ox::Error seekp(std::size_t bytesFwd) noexcept {
if (bytesFwd > avail()) {
return OxError(1, "Insufficient space in buffer to seek that far ahead");
return ox::Error(1, "Insufficient space in buffer to seek that far ahead");
}
m_writePt += bytesFwd;
if (m_writePt > m_buff.size()) {
@ -73,7 +73,7 @@ OX_ALLOW_UNSAFE_BUFFERS_END
}
constexpr ox::Error seekp(int, ios_base::seekdir) noexcept {
return OxError(1, "Unimplemented");
return ox::Error(1, "Unimplemented");
}
[[nodiscard]]

View File

@ -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<int>(socket(AF_INET, SOCK_STREAM, IPPROTO_TCP));
oxReturnError(OxError(static_cast<ox::ErrorCode>(connect(static_cast<Socket>(m_socket), reinterpret_cast<sockaddr*>(&addr), sizeof(addr)))));
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(connect(static_cast<Socket>(m_socket), reinterpret_cast<sockaddr*>(&addr), sizeof(addr)))));
return sendInit({.appName = ox::BasicString<128>(appName)});
}
@ -75,7 +75,7 @@ ox::Error LoggerConn::send(const char *buff, std::size_t len) const noexcept {
const auto sent = ::send(static_cast<Socket>(m_socket), buff, static_cast<LenType>(len), 0);
if (sent < 0) {
std::ignore = std::fprintf(stderr, "Could not send msg\n");
return OxError(1, "Could not send msg");
return ox::Error(1, "Could not send msg");
}
totalSent += static_cast<std::size_t>(sent);
}

View File

@ -110,7 +110,7 @@ constexpr Result<bool> FieldBitmapWriterBase<T>::get(std::size_t i) const noexce
if (i / 8 < m_mapLen) {
return (m_map[i / 8] >> (i % 8)) & 1;
} else {
return OxError(McPresenceMapOverflow);
return ox::Error(McPresenceMapOverflow);
}
}
@ -156,7 +156,7 @@ OX_ALLOW_UNSAFE_BUFFERS_BEGIN
OX_ALLOW_UNSAFE_BUFFERS_END
return {};
} else {
return OxError(McPresenceMapOverflow);
return ox::Error(McPresenceMapOverflow);
}
}

View File

@ -197,7 +197,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, bool *val) n
oxReturnError(result);
}
++m_field;
return OxError(0);
return ox::Error(0);
}
// array handler
@ -220,7 +220,7 @@ OX_ALLOW_UNSAFE_BUFFERS_END
}
} else {
oxTracef("ox.mc.read.field(T)", "{}, length: {}", name, valLen);
return OxError(McOutputBuffEnded);
return ox::Error(McOutputBuffEnded);
}
}
}
@ -256,7 +256,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, HashMap<Stri
}
}
++m_field;
return OxError(0);
return ox::Error(0);
}
template<Reader_c Reader>
@ -280,7 +280,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char *name, T *val)
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
oxRequire(len, arrayLength(name, false));
if (len > val->size()) {
return OxError(1, "Input array is too long");
return ox::Error(1, "Input array is too long");
}
}
return field(name, val->data(), val->size());
@ -330,7 +330,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, BasicString<
}
}
++m_field;
return OxError(0);
return ox::Error(0);
}
template<Reader_c Reader>
@ -361,7 +361,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::fieldCString(const char*, char
std::size_t bytesRead = 0;
oxRequire(size, mc::decodeInteger<StringLength>(m_reader, &bytesRead));
if (size > buffLen) {
return OxError(McOutputBuffEnded);
return ox::Error(McOutputBuffEnded);
}
// re-allocate in case too small
auto data = val;
@ -370,7 +370,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::fieldCString(const char*, char
data[size] = 0;
}
++m_field;
return OxError(0);
return ox::Error(0);
}
template<Reader_c Reader>
@ -388,7 +388,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::fieldCString(const char*, char
data[size] = 0;
}
++m_field;
return OxError(0);
return ox::Error(0);
}
template<Reader_c Reader>
@ -416,7 +416,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::fieldCString(const char*, char
}
}
++m_field;
return OxError(0);
return ox::Error(0);
}
template<Reader_c Reader>
@ -433,7 +433,7 @@ constexpr Result<ArrayLength> MetalClawReaderTemplate<Reader>::arrayLength(const
return out;
}
}
return OxError(1);
return ox::Error(1);
}
template<Reader_c Reader>
@ -464,7 +464,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::readInteger(I *val) noexcept {
}
}
++m_field;
return OxError(0);
return ox::Error(0);
}
template<Reader_c Reader>
@ -487,7 +487,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, CB cb) noexc
}
}
++m_field;
return OxError(0);
return ox::Error(0);
}
template<Reader_c Reader>

View File

@ -66,7 +66,7 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestUnion> auto *obj) noexcep
oxReturnError(io->field("Bool", &obj->Bool));
oxReturnError(io->field("Int", &obj->Int));
oxReturnError(io->fieldCString("CString", &obj->CString));
return OxError(0);
return ox::Error(0);
}
oxModelBegin(TestStructNest)
@ -102,7 +102,7 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) noexce
oxReturnError(io->field("Map", &obj->Map));
oxReturnError(io->field("Struct", &obj->Struct));
oxReturnError(io->field("EmptyStruct", &obj->EmptyStruct));
return OxError(0);
return ox::Error(0);
}
std::map<ox::StringView, ox::Error(*)()> tests = {
@ -116,7 +116,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
TestStruct ts;
oxReturnError(ox::writeMC(buff.data(), buff.size(), ts));
oxReturnError(ox::writeMC(ts));
return OxError(0);
return ox::Error(0);
}
},
@ -176,7 +176,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(testIn.Struct.Int == testOut.Struct.Int, "Struct.Int value mismatch");
oxAssert(testIn.Struct.IString == testOut.Struct.IString, "Struct.IString value mismatch");
oxAssert(testIn.Struct.Bool == testOut.Struct.Bool, "Struct.Bool value mismatch");
return OxError(0);
return ox::Error(0);
}
},
@ -189,28 +189,28 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
static constexpr auto check = [](McInt val, const ox::Vector<uint8_t, 9> &expected) {
if (val.length != expected.size()) {
std::cout << "val.length: " << val.length << ", expected: " << expected.size() << '\n';
return OxError(1);
return ox::Error(1);
}
for (std::size_t i = 0; i < expected.size(); i++) {
if (expected[i] != val.data[i]) {
std::cout << "decoded: " << static_cast<uint32_t>(val.data[i]) << ", expected: " << static_cast<uint32_t>(expected[i]) << '\n';
std::cout << "decoded: " << i << ": " << static_cast<uint32_t>(val.data[i]) << '\n';
return OxError(1);
return ox::Error(1);
}
}
return OxError(0);
return ox::Error(0);
};
constexpr auto check64 = [](McInt val, auto expected) {
if (val.length != 9) {
std::cout << "val.length: " << val.length << '\n';
return OxError(1);
return ox::Error(1);
}
ox::LittleEndian<decltype(expected)> decoded = *reinterpret_cast<decltype(expected)*>(&val.data[1]);
if (expected != decoded) {
std::cout << "decoded: " << decoded << ", expected: " << expected << '\n';
return OxError(1);
return ox::Error(1);
}
return OxError(0);
return ox::Error(0);
};
// signed positive
oxAssert(check(encodeInteger(int64_t(1)), {0b000'0001'0}), "Encode 1 fail");
@ -247,7 +247,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
// code deduplication
oxAssert(check64(encodeInteger(MaxValue<int64_t>), MaxValue<int64_t>), "Encode MaxValue<int64_t> fail");
oxAssert(check64(encodeInteger(MaxValue<uint64_t>), MaxValue<uint64_t>), "Encode MaxValue<uint64_t> fail");
return OxError(0);
return ox::Error(0);
}
},
@ -263,9 +263,9 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
oxReturnError(result.error);
if (result.value != val) {
std::cout << "Bad value: " << result.value << ", expected: " << val << '\n';
return OxError(1);
return ox::Error(1);
}
return OxError(0);
return ox::Error(0);
};
oxAssert(check(uint32_t(14)), "Decode of 14 failed.");
oxAssert(check(int8_t(-1)), "Decode of -1 failed.");
@ -291,7 +291,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(check(0xffffffff), "Decode of 0xffffffff failed.");
oxAssert(check(0xffffffffffff), "Decode of 0xffffffffffff failed.");
oxAssert(check(0xffffffffffffffff), "Decode of U64 max failed.");
return OxError(0);
return ox::Error(0);
}
},
@ -344,7 +344,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(testOutStructCopy.at("IString").unwrap()->get<ox::String>() == testIn.Struct.IString.c_str(), "testOut.Struct.IString (copy) failed");
oxAssert(testOutListCopy[0].get<uint32_t>() == testIn.List[0], "testOut.Struct.List[0] (copy) failed");
oxAssert(testOutListCopy[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] (copy) failed");
return OxError(0);
return ox::Error(0);
}
},
@ -454,10 +454,10 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
case ox::PrimitiveType::Union:
break;
}
return OxError(0);
return ox::Error(0);
}
));
return OxError(0);
return ox::Error(0);
}
},
}

View File

@ -122,7 +122,7 @@ class MetalClawWriter {
}
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
++m_field;
return OxError(0);
return ox::Error(0);
}
};
@ -184,7 +184,7 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const bool *val) noe
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), *val));
}
++m_field;
return OxError(0);
return ox::Error(0);
}
template<Writer_c Writer>
@ -201,7 +201,7 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const BasicString<Sm
}
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
++m_field;
return OxError(0);
return ox::Error(0);
}
template<Writer_c Writer>
@ -224,7 +224,7 @@ constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *c
}
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
++m_field;
return OxError(0);
return ox::Error(0);
}
template<Writer_c Writer>
@ -250,7 +250,7 @@ constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *v
}
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
++m_field;
return OxError(0);
return ox::Error(0);
}
template<Writer_c Writer>
@ -314,7 +314,7 @@ OX_ALLOW_UNSAFE_BUFFERS_END
}
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
++m_field;
return OxError(0);
return ox::Error(0);
}
template<Writer_c Writer>
@ -351,7 +351,7 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const HashMap<String
}
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
++m_field;
return OxError(0);
return ox::Error(0);
}
template<Writer_c Writer>

View File

@ -13,7 +13,7 @@
// oxModelFwdDecl is necessary because Apple-Clang is broken...
#define oxModelFwdDecl(modelName) constexpr ox::Error model(auto *io, ox::CommonPtrWith<modelName> auto *o) noexcept
#define oxModelBegin(modelName) constexpr ox::Error model(auto *io, [[maybe_unused]] ox::CommonPtrWith<modelName> auto *o) noexcept { oxReturnError(io->template setTypeInfo<modelName>());
#define oxModelEnd() return OxError(0); }
#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<modelName> auto *o) noexcept

View File

@ -244,7 +244,7 @@ constexpr Error model(TypeDescReader<T> *io, CommonPtrWith<DescriptorField> auto
// defaultValue is unused now, but placeholder for backwards compatibility
int defaultValue = 0;
oxReturnError(io->field("defaultValue", &defaultValue));
return OxError(0);
return ox::Error(0);
}
#endif

View File

@ -205,9 +205,9 @@ constexpr Error TypeDescWriter::field(StringViewCR name, T const*, std::size_t,
const auto t = type(p);
oxAssert(t != nullptr, "field(const char *name, T *val, std::size_t): Type not found or generated");
m_type->fieldList.emplace_back(t, String(name), detail::indirectionLevels_v<T> + 1, subscriptStack, buildTypeId(*t));
return OxError(0);
return ox::Error(0);
}
return OxError(1);
return ox::Error(1);
}
// array handler
@ -220,9 +220,9 @@ constexpr Error TypeDescWriter::field(StringViewCR name, T const*, std::size_t)
auto const lvls = detail::indirectionLevels_v<T> + 1;
SubscriptStack subscriptStack{lvls};
m_type->fieldList.emplace_back(t, String(name), lvls, subscriptStack, buildTypeId(*t));
return OxError(0);
return ox::Error(0);
}
return OxError(1);
return ox::Error(1);
}
template<typename T, bool force>
@ -231,9 +231,9 @@ constexpr Error TypeDescWriter::field(StringViewCR name, UnionView<T, force> val
const auto t = type(val);
oxAssert(t != nullptr, "field(const char *name, T val): Type not found or generated");
m_type->fieldList.emplace_back(t, String(name), 0, SubscriptStack{}, ox::String(t->typeName));
return OxError(0);
return ox::Error(0);
}
return OxError(1);
return ox::Error(1);
}
template<typename T>
@ -254,7 +254,7 @@ constexpr Error TypeDescWriter::field(StringViewCR name, const T *val) noexcept
return {};
}
}
return OxError(1);
return ox::Error(1);
}
template<typename ...Args>

View File

@ -31,25 +31,25 @@ class FieldCounter {
template<typename U>
constexpr ox::Error field(StringViewCR, U) noexcept {
++fields;
return OxError(0);
return ox::Error(0);
}
template<typename U>
constexpr ox::Error field(StringViewCR, U, std::size_t) noexcept {
++fields;
return OxError(0);
return ox::Error(0);
}
template<typename U, typename Handler>
constexpr Error field(StringViewCR, Handler) {
++fields;
return OxError(0);
return ox::Error(0);
}
template<typename ...Args>
constexpr Error fieldCString(Args&&...) noexcept {
++fields;
return OxError(0);
return ox::Error(0);
}
static constexpr auto opType() noexcept {

View File

@ -135,8 +135,8 @@ class ModelHandlerInterface {
return m_handler->field(name, &v->template get<ModelValueArray>());
}
oxErrf("invalid type: {}: {}\n", name, static_cast<int>(v->type()));
oxPanic(OxError(1), "invalid type");
return OxError(1, "invalid type");
oxPanic(ox::Error(1), "invalid type");
return ox::Error(1, "invalid type");
}
// array handler, with callback to allow handling individual elements

View File

@ -56,19 +56,19 @@ class MemberList {
template<typename T>
constexpr Error field(const char*, T *v) noexcept {
vars[m_i++] = static_cast<void*>(v);
return OxError(0);
return ox::Error(0);
}
template<typename T>
constexpr Error field(const char*, T *v, int) noexcept {
vars[m_i++] = static_cast<void*>(v);
return OxError(0);
return ox::Error(0);
}
template<typename U, bool force = false>
constexpr Error field(const char*, UnionView<U, force> u) noexcept {
vars[m_i++] = static_cast<void*>(u.get());
return OxError(0);
return ox::Error(0);
}
template<typename T>
@ -107,7 +107,7 @@ class Copier {
auto &dst = *cbit_cast<FT*>(m_dst->vars[m_i]);
dst = src;
++m_i;
return OxError(0);
return ox::Error(0);
}
}
@ -119,7 +119,7 @@ class Copier {
dst = src;
}
++m_i;
return OxError(0);
return ox::Error(0);
}
template<typename U, bool force = false>
@ -128,7 +128,7 @@ class Copier {
auto &src = *u.get();
dst = src;
++m_i;
return OxError(0);
return ox::Error(0);
}
template<typename T = void>
@ -168,7 +168,7 @@ class Mover {
dst = std::move(src);
src = FT{};
++m_i;
return OxError(0);
return ox::Error(0);
}
}
@ -181,7 +181,7 @@ class Mover {
src = FT{};
}
++m_i;
return OxError(0);
return ox::Error(0);
}
template<typename U, bool force = false>
@ -190,7 +190,7 @@ class Mover {
auto &src = *u.get();
dst = std::move(src);
++m_i;
return OxError(0);
return ox::Error(0);
}
template<typename T = void>
@ -228,10 +228,10 @@ class Equals {
const auto &dst = std::bit_cast<FT>(*m_other->vars[m_i]);
++m_i;
if (dst == src) {
return OxError(0);
return ox::Error(0);
} else {
this->value = false;
return OxError(1);
return ox::Error(1);
}
}
@ -242,11 +242,11 @@ class Equals {
const auto &dst = cbit_cast<FT*>(m_other->vars[m_i])[i];
if (!(dst == src)) {
this->value = false;
return OxError(1);
return ox::Error(1);
}
}
++m_i;
return OxError(0);
return ox::Error(0);
}
template<typename U, bool force = false>
@ -255,10 +255,10 @@ class Equals {
const auto &src = *u.get();
++m_i;
if (dst == src) {
return OxError(0);
return ox::Error(0);
} else {
this->value = false;
return OxError(1);
return ox::Error(1);
}
}

View File

@ -14,10 +14,10 @@ static_assert([]() -> ox::Error {
ox::ModelValue v;
oxReturnError(v.setType<int32_t>());
if (v.type() != ModelValue::Type::SignedInteger32) {
return OxError(1, "type is wrong");
return ox::Error(1, "type is wrong");
}
//oxReturnError(v.set<int32_t>(5));
return {};
}() == OxError(0));
}() == ox::Error(0));
}

View File

@ -168,7 +168,7 @@ class ModelValue {
constexpr const auto &get() const noexcept {
constexpr auto type = getType<T>();
if (m_type != type) [[unlikely]] {
oxPanic(OxError(1), "invalid cast");
oxPanic(ox::Error(1), "invalid cast");
}
return getValue<type>(*this);
}
@ -178,7 +178,7 @@ class ModelValue {
constexpr auto &get() noexcept {
constexpr auto type = getType<T>();
if (m_type != type) [[unlikely]] {
oxPanic(OxError(1), "invalid cast");
oxPanic(ox::Error(1), "invalid cast");
}
return getValue<type>(*this);
}
@ -634,7 +634,7 @@ class ModelObject {
if (m_fields.contains(k)) {
return *m_fields.at(k).value;
}
return OxError(1);
return ox::Error(1);
}
template<typename T>
@ -670,7 +670,7 @@ class ModelObject {
constexpr Error setType(const DescriptorType *type) noexcept {
if (type->primitiveType != PrimitiveType::Struct && type->primitiveType != PrimitiveType::Union) {
return OxError(1, "Cannot load a non-struct type to ModelObject");
return ox::Error(1, "Cannot load a non-struct type to ModelObject");
}
m_type = type;
for (const auto &f : type->fieldList) {
@ -790,7 +790,7 @@ class ModelUnion {
constexpr Error setType(const DescriptorType *type) noexcept {
if (type->primitiveType != PrimitiveType::Struct && type->primitiveType != PrimitiveType::Union) {
return OxError(1, "Cannot load a non-struct type to ModelUnion");
return ox::Error(1, "Cannot load a non-struct type to ModelUnion");
}
m_fields.clear();
m_fieldsOrder.clear();
@ -972,7 +972,7 @@ constexpr Error model(auto *h, CommonPtrWith<ModelObject> auto *obj) noexcept {
for (auto &f : obj->m_fieldsOrder) {
oxReturnError(h->field(f->name.c_str(), &f->value));
}
return OxError(0);
return ox::Error(0);
}
constexpr Error model(auto *h, CommonPtrWith<ModelUnion> auto *obj) noexcept {
@ -981,7 +981,7 @@ constexpr Error model(auto *h, CommonPtrWith<ModelUnion> auto *obj) noexcept {
for (auto &f : obj->m_fieldsOrder) {
oxReturnError(h->field(f->name.c_str(), &f->value));
}
return OxError(0);
return ox::Error(0);
}
constexpr ModelValue::ModelValue(const ModelValue &other) noexcept {
@ -1129,7 +1129,7 @@ constexpr Error ModelValue::setType(
oxReturnError(m_data.uni->setType(type));
}
oxAssert(m_type != Type::Undefined, "No type set");
return OxError(0);
return ox::Error(0);
}
template<typename T>
@ -1176,7 +1176,7 @@ template<typename T>
constexpr Error ModelValue::set(const T &v) noexcept {
constexpr auto type = getType<T>();
if (m_type != type) [[unlikely]] {
return OxError(1, "type mismatch");
return ox::Error(1, "type mismatch");
}
auto &value = getValue<type>(*this);
if constexpr(type == Type::Vector || type == Type::Object ||
@ -1184,14 +1184,14 @@ constexpr Error ModelValue::set(const T &v) noexcept {
safeDelete(&value);
}
value = v;
return OxError(0);
return ox::Error(0);
}
template<typename T>
constexpr Error ModelValue::set(T &&v) noexcept {
constexpr auto type = getType<T>();
if (m_type != type) [[unlikely]] {
return OxError(1, "type mismatch");
return ox::Error(1, "type mismatch");
}
auto &value = getValue<type>(*this);
if constexpr(type == Type::Vector || type == Type::Object ||
@ -1199,7 +1199,7 @@ constexpr Error ModelValue::set(T &&v) noexcept {
safeDelete(&value);
}
value = std::move(v);
return OxError(0);
return ox::Error(0);
}
constexpr ModelValue &ModelValue::operator=(ModelValue &other) noexcept {

View File

@ -41,7 +41,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
oxReturnError(v.setType<int32_t>());
//v.m_type = ox::ModelValue::getType<int32_t>();
if (v.type() != ox::ModelValue::Type::SignedInteger32) {
return OxError(1, "type is wrong");
return ox::Error(1, "type is wrong");
}
oxReturnError(v.set<int32_t>(5));
return ox::Error{};

View File

@ -38,17 +38,17 @@ struct TypeNameCatcher {
template<typename T>
constexpr Error field(const char*, T*, std::size_t) noexcept {
return OxError(0);
return ox::Error(0);
}
template<typename T>
constexpr Error field(const char*, T) noexcept {
return OxError(0);
return ox::Error(0);
}
template<typename ...Args>
constexpr Error fieldCString(Args&&...) noexcept {
return OxError(0);
return ox::Error(0);
}
static constexpr auto opType() noexcept {
@ -77,17 +77,17 @@ struct TypeInfoCatcher {
template<typename T>
constexpr Error field(const char*, T*, std::size_t) noexcept {
return OxError(0);
return ox::Error(0);
}
template<typename T>
constexpr Error field(const char*, T) noexcept {
return OxError(0);
return ox::Error(0);
}
template<typename T>
constexpr Error fieldCString(const char*, T) noexcept {
return OxError(0);
return ox::Error(0);
}
static constexpr auto opType() noexcept {

View File

@ -64,7 +64,7 @@ class TypeStore {
out = std::move(dt);
return out.get();
} else {
return OxError(1, "Type not available");
return ox::Error(1, "Type not available");
}
}
return val->get();
@ -102,7 +102,7 @@ class TypeStore {
protected:
virtual Result<UniquePtr<DescriptorType>> loadDescriptor(ox::StringView) noexcept {
return OxError(1);
return ox::Error(1);
}
Result<UniquePtr<DescriptorType>> loadDescriptor(ox::StringViewCR name, int version,

View File

@ -127,7 +127,7 @@ static constexpr Error parseField(const DescriptorField &field, Reader *rdr, Dat
}
}
walker->popNamePath();
return OxError(0);
return ox::Error(0);
}
template<typename Reader, typename FH>
@ -141,7 +141,7 @@ constexpr Error model(Reader *rdr, DataWalker<Reader, FH> *walker) noexcept {
for (const auto &field : fields) {
oxReturnError(parseField(field, rdr, walker));
}
return OxError(0);
return ox::Error(0);
}
template<typename Reader, typename Handler>

View File

@ -37,7 +37,7 @@ OrganicClawReader::OrganicClawReader(Json::Value json, int unionIdx) noexcept:
}
Error OrganicClawReader::field(const char *key, bool *val) noexcept {
auto err = OxError(0);
auto err = ox::Error(0);
if (targetValid()) {
const auto &jv = value(key);
if (jv.empty()) {
@ -45,7 +45,7 @@ Error OrganicClawReader::field(const char *key, bool *val) noexcept {
} else if (jv.isBool()) {
*val = jv.asBool();
} else {
err = OxError(1, "Type mismatch");
err = ox::Error(1, "Type mismatch");
}
}
++m_fieldIt;
@ -53,7 +53,7 @@ Error OrganicClawReader::field(const char *key, bool *val) noexcept {
}
Error OrganicClawReader::fieldCString(const char *key, char *val, std::size_t buffLen) noexcept {
auto err = OxError(0);
auto err = ox::Error(0);
const char *begin = nullptr, *end = nullptr;
const auto &jv = value(key);
if (targetValid()) {
@ -67,13 +67,13 @@ Error OrganicClawReader::fieldCString(const char *key, char *val, std::size_t bu
const auto strSize = static_cast<std::size_t>(end - begin);
auto data = val;
if (strSize >= buffLen) {
err = OxError(2, "String size exceeds capacity of destination");
err = ox::Error(2, "String size exceeds capacity of destination");
} else {
ox::memcpy(data, begin, static_cast<std::size_t>(strSize));
data[strSize] = 0;
}
} else {
err = OxError(1, "Type mismatch");
err = ox::Error(1, "Type mismatch");
}
}
++m_fieldIt;
@ -81,7 +81,7 @@ Error OrganicClawReader::fieldCString(const char *key, char *val, std::size_t bu
}
Error OrganicClawReader::fieldCString(const char *key, char **val) noexcept {
auto err = OxError(0);
auto err = ox::Error(0);
const char *begin = nullptr, *end = nullptr;
const auto &jv = value(key);
auto &data = *val;
@ -98,7 +98,7 @@ Error OrganicClawReader::fieldCString(const char *key, char **val) noexcept {
ox::memcpy(data, begin, static_cast<std::size_t>(strSize));
data[strSize] = 0;
} else {
err = OxError(1, "Type mismatch");
err = ox::Error(1, "Type mismatch");
}
}
++m_fieldIt;
@ -106,7 +106,7 @@ Error OrganicClawReader::fieldCString(const char *key, char **val) noexcept {
}
Error OrganicClawReader::fieldCString(const char *key, char **val, std::size_t buffLen) noexcept {
auto err = OxError(0);
auto err = ox::Error(0);
const char *begin = nullptr, *end = nullptr;
const auto &jv = value(key);
if (targetValid()) {
@ -126,7 +126,7 @@ Error OrganicClawReader::fieldCString(const char *key, char **val, std::size_t b
ox::memcpy(data, begin, static_cast<std::size_t>(strSize));
data[strSize] = nullptr;
} else {
err = OxError(1, "Type mismatch");
err = ox::Error(1, "Type mismatch");
}
}
++m_fieldIt;
@ -147,7 +147,7 @@ Result<std::size_t> OrganicClawReader::arrayLength(const char *key, bool) noexce
if (jv.isArray()) {
return jv.size();
}
return OxError(1, "Type mismatch");
return ox::Error(1, "Type mismatch");
}
[[nodiscard]]
@ -161,7 +161,7 @@ std::size_t OrganicClawReader::stringLength(const char *key) noexcept {
jv.getString(&begin, &end);
return static_cast<std::size_t>(end - begin);
}
return OxError(1, "Type mismatch");
return ox::Error(1, "Type mismatch");
}
OrganicClawReader OrganicClawReader::child(const char *key, int unionIdx) noexcept {

View File

@ -133,7 +133,7 @@ class OrganicClawReader {
template<typename T>
Error OrganicClawReader::field(const char *key, T *val) noexcept {
auto err = OxError(0);
auto err = ox::Error(0);
try {
if constexpr (is_integer_v<T>) {
if (targetValid()) {
@ -146,7 +146,7 @@ Error OrganicClawReader::field(const char *key, T *val) noexcept {
} else if (rightType) {
*val = static_cast<T>(jv.asUInt());
} else {
err = OxError(1, "Type mismatch");
err = ox::Error(1, "Type mismatch");
}
}
} else if constexpr (isVector_v<T>) {
@ -158,7 +158,7 @@ Error OrganicClawReader::field(const char *key, T *val) noexcept {
const auto&srcVal = value(key);
const auto srcSize = srcVal.size();
if (srcSize > val->size()) {
err = OxError(1, "Input array is too long");
err = ox::Error(1, "Input array is too long");
} else {
err = field(key, val->data(), val->size());
}
@ -169,11 +169,11 @@ Error OrganicClawReader::field(const char *key, T *val) noexcept {
ModelHandlerInterface handler(&reader);
err = model(&handler, val);
} else {
err = OxError(1, "Type mismatch");
err = ox::Error(1, "Type mismatch");
}
}
} catch (Json::LogicError const&) {
err = OxError(1, "error reading JSON data");
err = ox::Error(1, "error reading JSON data");
}
++m_fieldIt;
return err;
@ -181,7 +181,7 @@ Error OrganicClawReader::field(const char *key, T *val) noexcept {
template<typename U, bool force>
Error OrganicClawReader::field(const char *key, UnionView<U, force> val) noexcept {
auto err = OxError(0);
auto err = ox::Error(0);
if (targetValid()) {
const auto &jv = value(key);
if (jv.empty() || jv.isObject()) {
@ -189,7 +189,7 @@ Error OrganicClawReader::field(const char *key, UnionView<U, force> val) noexcep
ModelHandlerInterface handler(&reader);
err = model(&handler, val.get());
} else {
err = OxError(1, "Type mismatch");
err = ox::Error(1, "Type mismatch");
}
}
++m_fieldIt;
@ -198,7 +198,7 @@ Error OrganicClawReader::field(const char *key, UnionView<U, force> val) noexcep
template<std::size_t L>
Error OrganicClawReader::field(const char *key, BasicString<L> *val) noexcept {
auto err = OxError(0);
auto err = ox::Error(0);
if (targetValid()) {
const auto &jv = value(key);
if (jv.empty()) {
@ -206,7 +206,7 @@ Error OrganicClawReader::field(const char *key, BasicString<L> *val) noexcept {
} else if (jv.isString()) {
*val = jv.asString().c_str();
} else {
err = OxError(1, "Type mismatch");
err = ox::Error(1, "Type mismatch");
}
}
++m_fieldIt;
@ -215,7 +215,7 @@ Error OrganicClawReader::field(const char *key, BasicString<L> *val) noexcept {
template<std::size_t L>
Error OrganicClawReader::field(const char *key, IString<L> *val) noexcept {
auto err = OxError(0);
auto err = ox::Error(0);
if (targetValid()) {
const auto &jv = value(key);
if (jv.empty()) {
@ -223,7 +223,7 @@ Error OrganicClawReader::field(const char *key, IString<L> *val) noexcept {
} else if (jv.isString()) {
*val = jv.asString().c_str();
} else {
err = OxError(1, "Type mismatch");
err = ox::Error(1, "Type mismatch");
}
}
++m_fieldIt;
@ -235,11 +235,11 @@ template<typename T>
Error OrganicClawReader::field(const char *key, T *val, std::size_t valLen) noexcept {
const auto &srcVal = value(key);
if (!srcVal.isNull() && !srcVal.isArray()) {
return OxError(1, "Type mismatch");
return ox::Error(1, "Type mismatch");
}
auto srcSize = srcVal.size();
if (srcSize > valLen) {
return OxError(1);
return ox::Error(1);
}
OrganicClawReader r(srcVal);
ModelHandlerInterface handler{&r};
@ -248,14 +248,14 @@ OX_ALLOW_UNSAFE_BUFFERS_BEGIN
oxReturnError(handler.field("", &val[i]));
OX_ALLOW_UNSAFE_BUFFERS_END
}
return OxError(0);
return ox::Error(0);
}
template<typename T>
Error OrganicClawReader::field(const char *key, HashMap<String, T> *val) noexcept {
const auto &srcVal = value(key);
if (!srcVal.isObject()) {
return OxError(1, "Type mismatch");
return ox::Error(1, "Type mismatch");
}
auto keys = srcVal.getMemberNames();
auto srcSize = srcVal.size();
@ -265,7 +265,7 @@ Error OrganicClawReader::field(const char *key, HashMap<String, T> *val) noexcep
const auto k = keys[i].c_str();
oxReturnError(handler.field(k, &val->operator[](k)));
}
return OxError(0);
return ox::Error(0);
}
Error readOC(BufferView buff, auto &val) noexcept {
@ -277,7 +277,7 @@ Error readOC(BufferView buff, auto &val) noexcept {
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
if (!parser->parse(buff.data(), buff.data() + buff.size(), &doc, nullptr)) {
OX_ALLOW_UNSAFE_BUFFERS_END
return OxError(1, "Could not parse JSON");
return ox::Error(1, "Could not parse JSON");
}
OrganicClawReader reader(buff.data(), buff.size());
ModelHandlerInterface handler(&reader);
@ -285,7 +285,7 @@ OX_ALLOW_UNSAFE_BUFFERS_END
} catch (const Error &err) {
return err;
} catch (...) {
return OxError(1, "Unknown Error");
return ox::Error(1, "Unknown Error");
}
}

View File

@ -78,7 +78,7 @@ constexpr ox::Error model(auto *io, ox::CommonPtrWith<TestUnion> auto *obj) noex
oxReturnError(io->field("Bool", &obj->Bool));
oxReturnError(io->field("Int", &obj->Int));
oxReturnError(io->fieldCString("String", &obj->String));
return OxError(0);
return ox::Error(0);
}
constexpr ox::Error model(auto *io, ox::CommonPtrWith<TestStructNest> auto *obj) noexcept {
@ -86,7 +86,7 @@ constexpr ox::Error model(auto *io, ox::CommonPtrWith<TestStructNest> auto *obj)
oxReturnError(io->field("Bool", &obj->Bool));
oxReturnError(io->field("Int", &obj->Int));
oxReturnError(io->field("String", &obj->String));
return OxError(0);
return ox::Error(0);
}
constexpr ox::Error model(auto *io, ox::CommonPtrWith<TestStruct> auto *obj) noexcept {
@ -112,7 +112,7 @@ constexpr ox::Error model(auto *io, ox::CommonPtrWith<TestStruct> auto *obj) noe
oxReturnError(io->field("Map", &obj->Map));
oxReturnError(io->field("EmptyStruct", &obj->EmptyStruct));
oxReturnError(io->field("Struct", &obj->Struct));
return OxError(0);
return ox::Error(0);
}
TestStruct::TestStruct(TestStruct &&other) noexcept {
@ -184,7 +184,7 @@ const std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(testIn.Struct.String == testOut.Struct.String, "Struct.String value mismatch");
oxAssert(testIn.Struct.Bool == testOut.Struct.Bool, "Struct.Bool value mismatch");
return OxError(0);
return ox::Error(0);
}
},
@ -234,7 +234,7 @@ const std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(testOutStructCopy.get("String").unwrap()->get<ox::String>() == testIn.Struct.String.c_str(), "testOut.Struct.String (copy) failed");
oxAssert(testOutListCopy[0].get<uint32_t>() == testIn.List[0], "testOut.Struct.List[0] (copy) failed");
oxAssert(testOutListCopy[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] (copy) failed");
return OxError(0);
return ox::Error(0);
}
},
@ -341,10 +341,10 @@ const std::map<ox::StringView, ox::Error(*)()> tests = {
case ox::PrimitiveType::Union:
break;
}
return OxError(0);
return ox::Error(0);
}
));
return OxError(0);
return ox::Error(0);
}
},
}

View File

@ -23,7 +23,7 @@ Error OrganicClawWriter::fieldCString(const char *key, const char *const*val, in
value(key) = *val;
}
++m_fieldIt;
return OxError(0);
return ox::Error(0);
}
Error OrganicClawWriter::fieldCString(const char *key, const char *const*val) noexcept {

View File

@ -42,7 +42,7 @@ class OrganicClawWriter {
value(key) = *val;
}
++m_fieldIt;
return OxError(0);
return ox::Error(0);
}
Error field(const char *key, const int16_t *val) noexcept {
@ -50,7 +50,7 @@ class OrganicClawWriter {
value(key) = *val;
}
++m_fieldIt;
return OxError(0);
return ox::Error(0);
}
Error field(const char *key, const int32_t *val) noexcept {
@ -58,7 +58,7 @@ class OrganicClawWriter {
value(key) = *val;
}
++m_fieldIt;
return OxError(0);
return ox::Error(0);
}
Error field(const char *key, const int64_t *val) noexcept {
@ -66,7 +66,7 @@ class OrganicClawWriter {
value(key) = *val;
}
++m_fieldIt;
return OxError(0);
return ox::Error(0);
}
@ -75,7 +75,7 @@ class OrganicClawWriter {
value(key) = *val;
}
++m_fieldIt;
return OxError(0);
return ox::Error(0);
}
Error field(const char *key, const uint16_t *val) noexcept {
@ -83,7 +83,7 @@ class OrganicClawWriter {
value(key) = *val;
}
++m_fieldIt;
return OxError(0);
return ox::Error(0);
}
Error field(const char *key, const uint32_t *val) noexcept {
@ -91,7 +91,7 @@ class OrganicClawWriter {
value(key) = *val;
}
++m_fieldIt;
return OxError(0);
return ox::Error(0);
}
Error field(const char *key, const uint64_t *val) noexcept {
@ -99,7 +99,7 @@ class OrganicClawWriter {
value(key) = *val;
}
++m_fieldIt;
return OxError(0);
return ox::Error(0);
}
Error field(char const*key, bool const*val) noexcept {
@ -147,7 +147,7 @@ class OrganicClawWriter {
value(key) = val->c_str();
}
++m_fieldIt;
return OxError(0);
return ox::Error(0);
}
Error fieldCString(const char*, const char *const*val, int len) noexcept;
@ -207,7 +207,7 @@ OX_ALLOW_UNSAFE_BUFFERS_END
value(key) = w.m_json;
}
++m_fieldIt;
return OxError(0);
return ox::Error(0);
}
template<typename T>
@ -233,7 +233,7 @@ Error OrganicClawWriter::field(const char *key, const T *val) noexcept {
}
}
++m_fieldIt;
return OxError(0);
return ox::Error(0);
}
template<typename U, bool force>
@ -247,7 +247,7 @@ Error OrganicClawWriter::field(const char *key, UnionView<U, force> val) noexcep
}
}
++m_fieldIt;
return OxError(0);
return ox::Error(0);
}
Result<ox::Buffer> writeOC(const auto &val) noexcept {

View File

@ -22,9 +22,9 @@
namespace ox {
void panic(StringViewCR file, int line, StringViewCR panicMsg, const Error &err = OxError(0)) noexcept;
void panic(StringViewCR file, int line, StringViewCR panicMsg, const Error &err = ox::Error(0)) noexcept;
constexpr void constexprPanic(StringViewCR file, int line, StringViewCR panicMsg, const Error &err = OxError(0)) noexcept {
constexpr void constexprPanic(StringViewCR file, int line, StringViewCR panicMsg, const Error &err = ox::Error(0)) noexcept {
if (!std::is_constant_evaluated()) {
panic(file, line, panicMsg, err);
} else {

View File

@ -53,7 +53,7 @@ class BufferWriter {
base = static_cast<ox::Signed<std::size_t>>(m_it);
break;
default:
return OxError(1, "Invalid seekdir");
return ox::Error(1, "Invalid seekdir");
}
m_it = static_cast<std::size_t>(base + off);
return {};
@ -125,7 +125,7 @@ class CharBuffWriter {
base = static_cast<ox::Signed<std::size_t>>(m_it);
break;
default:
return OxError(1, "Invalid seekdir");
return ox::Error(1, "Invalid seekdir");
}
m_it = static_cast<std::size_t>(base + off);
return {};
@ -138,7 +138,7 @@ class CharBuffWriter {
constexpr ox::Error put(char val) noexcept {
if (m_it >= m_cap) [[unlikely]] {
return OxError(1, "Buffer overrun");
return ox::Error(1, "Buffer overrun");
}
m_buff[m_it] = val;
++m_it;
@ -149,7 +149,7 @@ class CharBuffWriter {
constexpr ox::Error write(const char *buff, std::size_t cnt) noexcept {
const auto end = m_it + cnt;
if (end > m_cap) [[unlikely]] {
return OxError(1, "Buffer overrun");
return ox::Error(1, "Buffer overrun");
}
if (buff) {
for (auto i = 0u; i < cnt; ++i) {
@ -179,7 +179,7 @@ class BufferReader {
constexpr ox::Result<char> peek() const noexcept {
if (m_it >= m_size) [[unlikely]] {
return OxError(1, "Peek failed: buffer overrun");
return ox::Error(1, "Peek failed: buffer overrun");
}
return m_buff[m_it];
}
@ -187,7 +187,7 @@ class BufferReader {
constexpr ox::Result<std::size_t> read(void *v, std::size_t sz) noexcept {
sz = ox::min(sz, m_size - m_it);
if (m_it + sz > m_size) [[unlikely]] {
return OxError(1, "Read failed: Buffer overrun");
return ox::Error(1, "Read failed: Buffer overrun");
}
ox::memcpy(v, &m_buff[m_it], sz);
m_it += sz;
@ -196,7 +196,7 @@ class BufferReader {
constexpr ox::Error seekg(std::size_t p) noexcept {
if (p > m_size) [[unlikely]] {
return OxError(1, "Seek failed: Buffer overrun");
return ox::Error(1, "Seek failed: Buffer overrun");
}
m_it = p;
return {};
@ -215,11 +215,11 @@ class BufferReader {
base = static_cast<ox::Signed<std::size_t>>(m_it);
break;
default:
return OxError(1, "Invalid seekdir");
return ox::Error(1, "Invalid seekdir");
}
auto const newIt = static_cast<std::size_t>(base + off);
if (newIt > m_size) [[unlikely]] {
return OxError(1, "Seek failed: Buffer overrun");
return ox::Error(1, "Seek failed: Buffer overrun");
}
m_it = newIt;
return {};

View File

@ -30,7 +30,6 @@ class exception {
#include "typetraits.hpp"
#include "utility.hpp"
#define OxError(...) ox::Error(__FILE__, __LINE__, __VA_ARGS__)
#define OxException(...) ox::Exception(__FILE__, __LINE__, __VA_ARGS__)
namespace ox {
@ -165,10 +164,10 @@ struct [[nodiscard]] Result {
constexpr Result(const Error &error) noexcept: value(), error(error) {
}
constexpr Result(const type &value, const Error &error = OxError(0)) noexcept: value(value), error(error) {
constexpr Result(const type &value, const Error &error = ox::Error(0)) noexcept: value(value), error(error) {
}
constexpr Result(type &&value, const Error &error = OxError(0)) noexcept: value(std::move(value)), error(error) {
constexpr Result(type &&value, const Error &error = ox::Error(0)) noexcept: value(std::move(value)), error(error) {
}
constexpr ~Result() noexcept = default;
@ -356,7 +355,7 @@ constexpr Error toError(const Result<T> &r) noexcept {
constexpr void primitiveAssert(const char *file, int line, bool pass, const char *msg) noexcept {
if constexpr(ox::defines::Debug) {
if (!pass) [[unlikely]] {
panic(file, line, msg, OxError(1));
panic(file, line, msg, ox::Error(1));
}
}
}

View File

@ -154,7 +154,7 @@ template<typename K, typename T>
constexpr Result<T*> HashMap<K, T>::at(MaybeView_t<K> const&k) noexcept {
auto p = access(m_pairs, k);
if (!p) {
return {nullptr, OxError(1, "value not found for given key")};
return {nullptr, ox::Error(1, "value not found for given key")};
}
return &p->value;
}
@ -163,7 +163,7 @@ template<typename K, typename T>
constexpr Result<const T*> HashMap<K, T>::at(MaybeView_t<K> const&k) const noexcept {
auto p = access(m_pairs, k);
if (!p) {
return {nullptr, OxError(1, "value not found for given key")};
return {nullptr, ox::Error(1, "value not found for given key")};
}
return &p->value;
}

View File

@ -77,7 +77,7 @@ static HeapSegment *findSegmentFor(std::size_t sz) noexcept {
return s;
}
}
oxPanic(OxError(1), "malloc: could not find segment");
oxPanic(ox::Error(1), "malloc: could not find segment");
return nullptr;
}
@ -102,7 +102,7 @@ void free(void *ptr) noexcept {
} else if (p.segment) {
p.segment->inUse = false;
} else {
oxPanic(OxError(1), "Bad heap free");
oxPanic(ox::Error(1), "Bad heap free");
}
}

View File

@ -174,7 +174,7 @@ constexpr Error IString<StrCap>::append(const char *str, std::size_t strLen) noe
auto const currentLen = len();
if (cap() < currentLen + strLen) {
strLen = cap() - currentLen;
err = OxError(1, "Insufficient space for full string");
err = ox::Error(1, "Insufficient space for full string");
}
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
ox::strncpy(m_buff.data() + currentLen, str, strLen);
@ -219,7 +219,7 @@ constexpr std::size_t IString<StrCap>::bytes() const noexcept {
template<std::size_t StrCap>
constexpr ox::Error IString<StrCap>::resize(size_t sz) noexcept {
if (sz > StrCap) [[unlikely]] {
return OxError(1, "Trying to extend IString beyond its cap");
return ox::Error(1, "Trying to extend IString beyond its cap");
}
for (auto i = m_size; i < sz; ++i) {
m_buff[i] = 0;
@ -231,7 +231,7 @@ constexpr ox::Error IString<StrCap>::resize(size_t sz) noexcept {
template<std::size_t StrCap>
constexpr ox::Error IString<StrCap>::unsafeResize(size_t sz) noexcept {
if (sz > StrCap) [[unlikely]] {
return OxError(1, "Trying to extend IString beyond its cap");
return ox::Error(1, "Trying to extend IString beyond its cap");
}
m_size = sz;
return {};

View File

@ -42,10 +42,10 @@ constexpr U *make(Args &&...args) noexcept {
try {
return new T(ox::forward<Args>(args)...);
} catch (std::exception const&ex) {
oxPanic(OxError(1, ex.what()), ex.what());
oxPanic(ox::Error(1, ex.what()), ex.what());
return nullptr;
} catch (...) {
oxPanic(OxError(2, "Allocation or constructor failed"), "Allocation or constructor failed");
oxPanic(ox::Error(2, "Allocation or constructor failed"), "Allocation or constructor failed");
return nullptr;
}
#else
@ -62,7 +62,7 @@ constexpr Result<T*> makeCatch(Args &&...args) noexcept {
} catch (const ox::Exception &ex) {
return ex.toError();
} catch (...) {
return OxError(1, "Allocation or constructor failed");
return ox::Error(1, "Allocation or constructor failed");
}
#else
return new T(ox::forward<Args>(args)...);

View File

@ -34,11 +34,11 @@ ox::Result<char> StreamReader::peek() const noexcept {
m_strm.get(c);
auto const ok = c != EOF;
if (ok && m_strm.unget()) [[unlikely]] {
return OxError(1, "Unable to unget character");
return ox::Error(1, "Unable to unget character");
}
return {static_cast<char>(c), OxError(!ok, "File peek failed")};
return {static_cast<char>(c), ox::Error(!ok, "File peek failed")};
} catch (std::exception const&) {
return OxError(1, "peek failed");
return ox::Error(1, "peek failed");
}
}
@ -50,7 +50,7 @@ ox::Error StreamReader::seekg(std::size_t p) noexcept {
try {
m_strm.seekg(static_cast<long long int>(p), std::ios_base::cur);
} catch (std::exception const&) {
return OxError(1, "seekg failed");
return ox::Error(1, "seekg failed");
}
return {};
}
@ -59,14 +59,14 @@ ox::Error StreamReader::seekg(int64_t p, ios_base::seekdir sd) noexcept {
try {
m_strm.seekg(p, sdMap(sd));
} catch (std::exception const&) {
return OxError(1, "seekg failed");
return ox::Error(1, "seekg failed");
}
return {};
}
ox::Result<std::size_t> StreamReader::tellg() noexcept {
const auto sz = m_strm.tellg();
return {static_cast<std::size_t>(sz), OxError(sz == -1)};
return {static_cast<std::size_t>(sz), ox::Error(sz == -1)};
}
}

View File

@ -140,7 +140,7 @@ template<typename K, typename T, size_t SmallSz>
constexpr Result<T*> SmallMap<K, T, SmallSz>::at(MaybeView_t<K> const&k) noexcept {
auto p = access(m_pairs, k);
if (!p) {
return {nullptr, OxError(1, "value not found for given key")};
return {nullptr, ox::Error(1, "value not found for given key")};
}
return &p->value;
}
@ -149,7 +149,7 @@ template<typename K, typename T, size_t SmallSz>
constexpr Result<const T*> SmallMap<K, T, SmallSz>::at(MaybeView_t<K> const&k) const noexcept {
auto p = access(m_pairs, k);
if (!p) {
return {nullptr, OxError(1, "value not found for given key")};
return {nullptr, ox::Error(1, "value not found for given key")};
}
return &p->value;
}

View File

@ -182,7 +182,7 @@ class BasicString {
// make sure last element is a null terminator
m_buff[currentLen + strLen] = 0;
// this can't fail, but it returns an Error to match BString::append
return OxError(0);
return ox::Error(0);
}
constexpr Error append(ox::StringView sv) noexcept {

View File

@ -109,7 +109,7 @@ constexpr ox::Result<int> atoi(ox::StringViewCR str) noexcept {
total += (str[s] - '0') * multiplier;
multiplier *= 10;
} else {
return OxError(1);
return ox::Error(1);
}
}
return total;

View File

@ -106,7 +106,7 @@ constexpr ox::Vector<ox::StringView, smallSz> split(StringViewCR str, StringView
[[nodiscard]]
constexpr ox::Result<std::size_t> lastIndexOf(ox::StringViewCR str, int character) noexcept {
ox::Result<std::size_t> retval = OxError(1, "Character not found");
ox::Result<std::size_t> retval = ox::Error(1, "Character not found");
for (auto i = static_cast<int>(str.bytes() - 1); i >= 0; --i) {
if (str[static_cast<std::size_t>(i)] == character) {
retval = static_cast<std::size_t>(i);

View File

@ -126,7 +126,7 @@ OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
OX_CLANG_NOWARN_END
ox::heapmgr::free(a1);
ox::heapmgr::free(a2);
return OxError(0);
return ox::Error(0);
}
},
{
@ -148,25 +148,25 @@ OX_CLANG_NOWARN_END
{
"ABCDEFG != HIJKLMN",
[]() {
return OxError(ox::memcmp("ABCDEFG", "HIJKLMN", 7) >= 0);
return ox::Error(ox::memcmp("ABCDEFG", "HIJKLMN", 7) >= 0);
}
},
{
"HIJKLMN != ABCDEFG",
[]() {
return OxError(ox::memcmp("HIJKLMN", "ABCDEFG", 7) <= 0);
return ox::Error(ox::memcmp("HIJKLMN", "ABCDEFG", 7) <= 0);
}
},
{
"ABCDEFG == ABCDEFG",
[]() {
return OxError(ox::memcmp("ABCDEFG", "ABCDEFG", 7) != 0);
return ox::Error(ox::memcmp("ABCDEFG", "ABCDEFG", 7) != 0);
}
},
{
"ABCDEFGHI == ABCDEFG",
[]() {
return OxError(ox::memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
return ox::Error(ox::memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
}
},
{
@ -182,7 +182,7 @@ OX_CLANG_NOWARN_END
oxAssert(s == "asdf", "String assign broken");
oxAssert(s != "aoeu", "String assign broken");
oxAssert(s.len() == 4, "String assign broken");
return OxError(0);
return ox::Error(0);
}
},
{
@ -216,7 +216,7 @@ OX_CLANG_NOWARN_END
oxAssert(
ox::String(ox::StringView("Write")) == ox::StringView("Write"),
"String / StringView comparison broken");
return OxError(0);
return ox::Error(0);
}
},
{
@ -227,14 +227,14 @@ OX_CLANG_NOWARN_END
oxAssert(v.empty(), "Vector::empty() is broken");
auto insertTest = [&v](int val, std::size_t size) {
v.push_back(val);
oxReturnError(OxError(v.size() != size, "Vector size incorrect"));
oxReturnError(OxError(v[v.size() - 1] != val, "Vector value wrong"));
return OxError(0);
oxReturnError(ox::Error(v.size() != size, "Vector size incorrect"));
oxReturnError(ox::Error(v[v.size() - 1] != val, "Vector value wrong"));
return ox::Error(0);
};
oxAssert(insertTest(42, 1), "Vector insertion failed");
oxAssert(insertTest(100, 2), "Vector insertion failed");
oxAssert(insertTest(102, 3), "Vector insertion failed");
return OxError(0);
return ox::Error(0);
}
},
{
@ -246,7 +246,7 @@ OX_CLANG_NOWARN_END
oxExpect(map.size(), 1u);
oxExpect(map["aoeu"], "");
oxExpect(map.size(), 2u);
return OxError(0);
return ox::Error(0);
}
},
{
@ -262,7 +262,7 @@ OX_CLANG_NOWARN_END
ii[5] = 100;
oxAssert(ii[4] == 42, "4 != 42");
oxAssert(ii[5] == 100, "5 != 100");
return OxError(0);
return ox::Error(0);
}
},
{
@ -278,7 +278,7 @@ OX_CLANG_NOWARN_END
ii[5] = 100;
oxAssert(ii[4] == 42, "4 != 42");
oxAssert(ii[5] == 100, "5 != 100");
return OxError(0);
return ox::Error(0);
}
},
{
@ -319,7 +319,7 @@ OX_CLANG_NOWARN_END
oxExpect(ox::serialize<uint32_t>(257).unwrap(), BA({1, 1, 0, 0}));
constexpr auto neg1 = static_cast<char>(-1); // ARM64 Linux assumes -1 literals are ints...
oxExpect(ox::serialize<uint32_t>(0xffff'ffff).unwrap(), BA({neg1, neg1, neg1, neg1}));
return OxError(0);
return ox::Error(0);
}
},
{
@ -336,7 +336,7 @@ OX_CLANG_NOWARN_END
oxAssert(w.write(qwerty.data(), qwerty.bytes()), "write failed");
oxExpect(b.size(), 14u);
oxExpect(ox::StringView(b.data(), b.size()), "asdfaoeuqwerty");
return OxError(0);
return ox::Error(0);
}
},
{
@ -359,7 +359,7 @@ OX_CLANG_NOWARN_END
oxExpect(ox::detail::fromHex("a0").unwrap(), 0xa0);
oxExpect(ox::detail::fromHex("93").unwrap(), 0x93);
oxExpect(ox::detail::fromHex("40").unwrap(), 0x40);
return OxError(0);
return ox::Error(0);
}
},
{
@ -379,7 +379,7 @@ OX_CLANG_NOWARN_END
oxExpect(ox::detail::toHex(0x93), "93");
oxExpect(ox::detail::toHex(0x40), "40");
oxExpect(ox::detail::toHex(0xf0), "f0");
return OxError(0);
return ox::Error(0);
}
},
{
@ -390,7 +390,7 @@ OX_CLANG_NOWARN_END
oxExpect(uuid.toString(), uuidStr);
oxExpect(ox::UUID{}.isNull(), true);
oxExpect(ox::UUID::fromString(uuidStr).value.isNull(), false);
return OxError(0);
return ox::Error(0);
}
},
{
@ -400,7 +400,7 @@ OX_CLANG_NOWARN_END
oxExpect(ox::UUID::generate().unwrap().toString(), "5c3f4b5e-ccbf-4727-7f03-3053dedc8827");
oxExpect(ox::UUID::generate().unwrap().toString(), "90d0274a-2774-4afa-88e5-0c1d60ba3abf");
oxExpect(ox::UUID::generate().unwrap().toString(), "7df77910-841c-48ba-ea2e-44521ac47c2e");
return OxError(0);
return ox::Error(0);
}
},
{
@ -467,7 +467,7 @@ OX_CLANG_NOWARN_END
sv = "";
list = ox::split(sv, '.');
oxExpect(list.size(), 0u);
return OxError(0);
return ox::Error(0);
}
},
};

View File

@ -21,7 +21,7 @@ void UUID::seedGenerator(const RandomSeed &seed) noexcept {
// UUID v4
Result<UUID> UUID::generate() noexcept {
if (!s_seeded) {
return OxError(1, "UUID generator not seeded.");
return ox::Error(1, "UUID generator not seeded.");
}
UUID out;
for (auto &v : out.m_value) {

View File

@ -56,10 +56,10 @@ constexpr ox::Result<uint8_t> fromHex(ox::StringViewCR v) noexcept {
return out;
}();
if (!detail::isHexChar(v[0]) || !detail::isHexChar(v[1])) {
return OxError(1, "Invalid UUID");
return ox::Error(1, "Invalid UUID");
}
if (v.len() != 2) {
return OxError(2);
return ox::Error(2);
}
uint8_t out = 0;
out += static_cast<uint8_t>(valMap[static_cast<unsigned char>(v[0])] * 16);
@ -130,7 +130,7 @@ class UUID {
static constexpr ox::Result<ox::UUID> fromString(ox::StringViewCR s) noexcept {
if (s.len() < 36) {
return OxError(1, "Insufficient data to contain a complete UUID");
return ox::Error(1, "Insufficient data to contain a complete UUID");
}
UUID out;
auto valueI = 0u;
@ -141,7 +141,7 @@ class UUID {
}
const auto seg = substr(s, i, i + 2);
if (seg.len() != 2) {
return OxError(1, "Invalid UUID");
return ox::Error(1, "Invalid UUID");
}
oxRequire(val, detail::fromHex(seg));
out.m_value[valueI] = val;

View File

@ -439,7 +439,7 @@ constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::at(size_t i) noexcep
if (i < size()) [[likely]] {
return &operator[](i);
}
return OxError(1, "Vector: Invalid index");
return ox::Error(1, "Vector: Invalid index");
}
template<typename T, std::size_t SmallVectorSize, typename Allocator>
@ -447,13 +447,13 @@ constexpr Result<T const*> Vector<T, SmallVectorSize, Allocator>::at(size_t i) c
if (i < size()) [[likely]] {
return &operator[](i);
}
return OxError(1, "Vector: Invalid index");
return ox::Error(1, "Vector: Invalid index");
}
template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::front() noexcept {
if (!m_size) {
return {nullptr, OxError(1)};
return {nullptr, ox::Error(1)};
}
return &m_items[0];
}
@ -461,7 +461,7 @@ constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::front() noexcept {
template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr Result<const T*> Vector<T, SmallVectorSize, Allocator>::front() const noexcept {
if (!m_size) {
return {nullptr, OxError(1)};
return {nullptr, ox::Error(1)};
}
return &m_items[0];
}
@ -469,7 +469,7 @@ constexpr Result<const T*> Vector<T, SmallVectorSize, Allocator>::front() const
template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::back() noexcept {
if (!m_size) {
return {nullptr, OxError(1)};
return {nullptr, ox::Error(1)};
}
return &m_items[m_size - 1];
}
@ -477,7 +477,7 @@ constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::back() noexcept {
template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr Result<const T*> Vector<T, SmallVectorSize, Allocator>::back() const noexcept {
if (!m_size) {
return {nullptr, OxError(1)};
return {nullptr, ox::Error(1)};
}
return &m_items[m_size - 1];
}
@ -634,7 +634,7 @@ template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr Result<typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>>
Vector<T, SmallVectorSize, Allocator>::erase(std::size_t pos) noexcept(useNoexcept) {
if (pos >= m_size) {
return OxError(1, "Vector::erase failed: pos is greater than Vector size");
return ox::Error(1, "Vector::erase failed: pos is greater than Vector size");
}
--m_size;
for (auto i = pos; i < m_size; ++i) {
@ -648,12 +648,12 @@ template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr Error Vector<T, SmallVectorSize, Allocator>::unordered_erase(std::size_t pos)
noexcept(useNoexcept) {
if (pos >= m_size) {
return OxError(1);
return ox::Error(1);
}
--m_size;
m_items[pos] = std::move(m_items[m_size]);
m_items[m_size].~T();
return OxError(0);
return ox::Error(0);
}
template<typename T, std::size_t SmallVectorSize, typename Allocator>