[ox] Make ValErr::operator T() explicit
This commit is contained in:
parent
2b536ff053
commit
c27cc56e31
14
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
14
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
@ -167,19 +167,19 @@ ox::Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents
|
|||||||
oxReturnError(childInode.error);
|
oxReturnError(childInode.error);
|
||||||
|
|
||||||
// initialize the directory
|
// initialize the directory
|
||||||
Directory<FileStore, InodeId_t> child(m_fs, childInode);
|
Directory<FileStore, InodeId_t> child(m_fs, childInode.value);
|
||||||
oxReturnError(child.init());
|
oxReturnError(child.init());
|
||||||
|
|
||||||
auto err = write(name->c_str(), childInode);
|
auto err = write(name->c_str(), childInode.value);
|
||||||
if (err) {
|
if (err) {
|
||||||
oxLogError(err);
|
oxLogError(err);
|
||||||
// could not index the directory, delete it
|
// could not index the directory, delete it
|
||||||
oxLogError(m_fs.remove(childInode));
|
oxLogError(m_fs.remove(childInode.value));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory<FileStore, InodeId_t> child(m_fs, childInode);
|
Directory<FileStore, InodeId_t> child(m_fs, childInode.value);
|
||||||
if (path.hasNext()) {
|
if (path.hasNext()) {
|
||||||
oxReturnError(child.mkdir(path.next(), parents, nameBuff));
|
oxReturnError(child.mkdir(path.next(), parents, nameBuff));
|
||||||
}
|
}
|
||||||
@ -189,8 +189,6 @@ ox::Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents
|
|||||||
|
|
||||||
template<typename FileStore, typename InodeId_t>
|
template<typename FileStore, typename InodeId_t>
|
||||||
ox::Error Directory<FileStore, InodeId_t>::write(PathIterator path, InodeId_t inode, FileName *nameBuff) noexcept {
|
ox::Error Directory<FileStore, InodeId_t>::write(PathIterator path, InodeId_t inode, FileName *nameBuff) noexcept {
|
||||||
InodeId_t nextChild = 0;
|
|
||||||
|
|
||||||
// reuse nameBuff if it has already been allocated, as it is a rather large variable
|
// reuse nameBuff if it has already been allocated, as it is a rather large variable
|
||||||
if (nameBuff == nullptr) {
|
if (nameBuff == nullptr) {
|
||||||
nameBuff = reinterpret_cast<FileName*>(ox_alloca(sizeof(FileName)));
|
nameBuff = reinterpret_cast<FileName*>(ox_alloca(sizeof(FileName)));
|
||||||
@ -203,7 +201,9 @@ ox::Error Directory<FileStore, InodeId_t>::write(PathIterator path, InodeId_t in
|
|||||||
oxTrace("ox::fs::Directory::write") << "Attempting to write to next sub-Directory: "
|
oxTrace("ox::fs::Directory::write") << "Attempting to write to next sub-Directory: "
|
||||||
<< name->c_str() << " of " << path.fullPath();
|
<< name->c_str() << " of " << path.fullPath();
|
||||||
|
|
||||||
nextChild = findEntry(*name);
|
auto [nextChild, err] = findEntry(*name);
|
||||||
|
oxReturnError(err);
|
||||||
|
|
||||||
oxTrace("ox::fs::Directory::write") << name->c_str() << ": " << nextChild;
|
oxTrace("ox::fs::Directory::write") << name->c_str() << ": " << nextChild;
|
||||||
|
|
||||||
if (nextChild) {
|
if (nextChild) {
|
||||||
|
20
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
20
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@ -184,8 +184,8 @@ ox::Error FileSystemTemplate<FileStore, Directory>::move(const char *src, const
|
|||||||
auto fd = fileSystemData();
|
auto fd = fileSystemData();
|
||||||
oxReturnError(fd.error);
|
oxReturnError(fd.error);
|
||||||
Directory rootDir(m_fs, fd.value.rootDirInode);
|
Directory rootDir(m_fs, fd.value.rootDirInode);
|
||||||
auto inode = rootDir.find(src);
|
auto [inode, err] = rootDir.find(src);
|
||||||
oxReturnError(inode.error);
|
oxReturnError(err);
|
||||||
oxReturnError(rootDir.write(dest, inode));
|
oxReturnError(rootDir.write(dest, inode));
|
||||||
oxReturnError(rootDir.remove(src));
|
oxReturnError(rootDir.remove(src));
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
@ -196,8 +196,8 @@ ox::Error FileSystemTemplate<FileStore, Directory>::read(const char *path, void
|
|||||||
auto fd = fileSystemData();
|
auto fd = fileSystemData();
|
||||||
oxReturnError(fd.error);
|
oxReturnError(fd.error);
|
||||||
Directory rootDir(m_fs, fd.value.rootDirInode);
|
Directory rootDir(m_fs, fd.value.rootDirInode);
|
||||||
auto inode = rootDir.find(path);
|
auto [inode, err] = rootDir.find(path);
|
||||||
oxReturnError(inode.error);
|
oxReturnError(err);
|
||||||
return read(inode, buffer, buffSize);
|
return read(inode, buffer, buffSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,12 +227,12 @@ ox::Error FileSystemTemplate<FileStore, Directory>::remove(const char *path, boo
|
|||||||
Directory rootDir(m_fs, fd.value.rootDirInode);
|
Directory rootDir(m_fs, fd.value.rootDirInode);
|
||||||
auto inode = rootDir.find(path);
|
auto inode = rootDir.find(path);
|
||||||
oxReturnError(inode.error);
|
oxReturnError(inode.error);
|
||||||
auto st = stat(inode);
|
auto st = stat(inode.value);
|
||||||
oxReturnError(st.error);
|
oxReturnError(st.error);
|
||||||
if (st.value.fileType == FileType_NormalFile || recursive) {
|
if (st.value.fileType == FileType_NormalFile || recursive) {
|
||||||
if (auto err = rootDir.remove(path)) {
|
if (auto err = rootDir.remove(path)) {
|
||||||
// removal failed, try putting the index back
|
// removal failed, try putting the index back
|
||||||
oxLogError(rootDir.write(path, inode));
|
oxLogError(rootDir.write(path, inode.value));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -255,9 +255,11 @@ ox::Error FileSystemTemplate<FileStore, Directory>::resize(uint64_t size, void *
|
|||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
ox::Error FileSystemTemplate<FileStore, Directory>::write(const char *path, void *buffer, uint64_t size, uint8_t fileType) {
|
ox::Error FileSystemTemplate<FileStore, Directory>::write(const char *path, void *buffer, uint64_t size, uint8_t fileType) {
|
||||||
auto inode = find(path);
|
auto [inode, err] = find(path);
|
||||||
if (inode.error) {
|
if (err) {
|
||||||
inode.value = m_fs.generateInodeId();
|
auto generated = m_fs.generateInodeId();
|
||||||
|
oxReturnError(generated.error);
|
||||||
|
inode = generated.value;
|
||||||
}
|
}
|
||||||
auto rootDir = this->rootDir();
|
auto rootDir = this->rootDir();
|
||||||
oxReturnError(rootDir.error);
|
oxReturnError(rootDir.error);
|
||||||
|
2
deps/ox/src/ox/fs/test/tests.cpp
vendored
2
deps/ox/src/ox/fs/test/tests.cpp
vendored
@ -182,7 +182,7 @@ map<string, int(*)(string)> tests = {
|
|||||||
|
|
||||||
oxTrace("ox::fs::test::Directory") << "find";
|
oxTrace("ox::fs::test::Directory") << "find";
|
||||||
oxAssert(dir.find("file1").error, "Could not find file1");
|
oxAssert(dir.find("file1").error, "Could not find file1");
|
||||||
oxAssert(dir.find("file1") == 1, "Could not find file1");
|
oxAssert(dir.find("file1").value == 1, "Could not find file1");
|
||||||
|
|
||||||
oxTrace("ox::fs::test::Directory") << "write 2";
|
oxTrace("ox::fs::test::Directory") << "write 2";
|
||||||
oxAssert(dir.write("/file3", 3) == 0, "Directory write of file3 failed");
|
oxAssert(dir.write("/file3", 3) == 0, "Directory write of file3 failed");
|
||||||
|
18
deps/ox/src/ox/mc/read.cpp
vendored
18
deps/ox/src/ox/mc/read.cpp
vendored
@ -61,8 +61,9 @@ Error MetalClawReader::field(const char*, uint64_t *val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Error MetalClawReader::field(const char*, bool *val) {
|
Error MetalClawReader::field(const char*, bool *val) {
|
||||||
*val = m_fieldPresence.get(m_field++);
|
auto valErr = m_fieldPresence.get(m_field++);
|
||||||
return OxError(0);
|
*val = valErr.value;
|
||||||
|
return OxError(valErr.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
Error MetalClawReader::field(const char*, SerStr val) {
|
Error MetalClawReader::field(const char*, SerStr val) {
|
||||||
@ -72,9 +73,9 @@ Error MetalClawReader::field(const char*, SerStr val) {
|
|||||||
return OxError(MC_BUFFENDED);
|
return OxError(MC_BUFFENDED);
|
||||||
}
|
}
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
auto size = mc::decodeInteger<StringLength>(&m_buff[m_buffIt], m_buffLen - m_buffIt, &bytesRead);
|
auto [size, err] = mc::decodeInteger<StringLength>(&m_buff[m_buffIt], m_buffLen - m_buffIt, &bytesRead);
|
||||||
m_buffIt += bytesRead;
|
m_buffIt += bytesRead;
|
||||||
oxReturnError(size.error);
|
oxReturnError(err);
|
||||||
|
|
||||||
// read the string
|
// read the string
|
||||||
if (val.cap() > -1 && static_cast<StringLength>(val.cap()) >= size) {
|
if (val.cap() > -1 && static_cast<StringLength>(val.cap()) >= size) {
|
||||||
@ -101,7 +102,7 @@ Error MetalClawReader::field(const char*, SerStr val) {
|
|||||||
return OxError(MC_BUFFENDED);
|
return OxError(MC_BUFFENDED);
|
||||||
}
|
}
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
len = mc::decodeInteger<StringLength>(&m_buff[m_buffIt], m_buffLen - m_buffIt, &bytesRead);
|
auto [len, _] = mc::decodeInteger<StringLength>(&m_buff[m_buffIt], m_buffLen - m_buffIt, &bytesRead);
|
||||||
if (pass) {
|
if (pass) {
|
||||||
m_buffIt += sizeof(ArrayLength);
|
m_buffIt += sizeof(ArrayLength);
|
||||||
}
|
}
|
||||||
@ -113,7 +114,8 @@ Error MetalClawReader::field(const char*, SerStr val) {
|
|||||||
if (m_fieldPresence.get(m_field)) {
|
if (m_fieldPresence.get(m_field)) {
|
||||||
// read the length
|
// read the length
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
return mc::decodeInteger<StringLength>(&m_buff[m_buffIt], m_buffLen - m_buffIt, &bytesRead);
|
auto [len, _] = mc::decodeInteger<StringLength>(&m_buff[m_buffIt], m_buffLen - m_buffIt, &bytesRead);
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -130,11 +132,11 @@ MetalClawReader MetalClawReader::child() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MetalClawReader::fieldPresent() const {
|
bool MetalClawReader::fieldPresent() const {
|
||||||
return m_fieldPresence.get(m_field);
|
return m_fieldPresence.get(m_field).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MetalClawReader::fieldPresent(int fieldNo) const {
|
bool MetalClawReader::fieldPresent(int fieldNo) const {
|
||||||
return m_fieldPresence.get(fieldNo);
|
return m_fieldPresence.get(fieldNo).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalClawReader::nextField() noexcept {
|
void MetalClawReader::nextField() noexcept {
|
||||||
|
6
deps/ox/src/ox/mc/read.hpp
vendored
6
deps/ox/src/ox/mc/read.hpp
vendored
@ -151,10 +151,10 @@ Error MetalClawReader::field(const char*, T *val, std::size_t valLen) {
|
|||||||
oxReturnError(len.error);
|
oxReturnError(len.error);
|
||||||
|
|
||||||
// read the list
|
// read the list
|
||||||
if (valLen >= len) {
|
if (valLen >= len.value) {
|
||||||
auto reader = child();
|
auto reader = child();
|
||||||
reader.setTypeInfo("List", len);
|
reader.setTypeInfo("List", len.value);
|
||||||
for (std::size_t i = 0; i < len; i++) {
|
for (std::size_t i = 0; i < len.value; i++) {
|
||||||
err |= reader.field("", &val[i]);
|
err |= reader.field("", &val[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
18
deps/ox/src/ox/std/error.hpp
vendored
18
deps/ox/src/ox/std/error.hpp
vendored
@ -61,23 +61,29 @@ struct ValErr {
|
|||||||
T value;
|
T value;
|
||||||
Error error;
|
Error error;
|
||||||
|
|
||||||
inline constexpr ValErr() = default;
|
constexpr ValErr() noexcept: error(0) {
|
||||||
|
|
||||||
inline constexpr ValErr(T value, Error error = OxError(0)): value(ox::move(value)), error(error) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline constexpr operator const T&() const {
|
constexpr ValErr(T value, Error error = OxError(0)) noexcept: value(ox::move(value)), error(error) {
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit constexpr operator const T&() const noexcept {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline constexpr operator T&() {
|
explicit constexpr operator T&() noexcept {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline constexpr bool ok() const {
|
constexpr bool ok() const noexcept {
|
||||||
return error == 0;
|
return error == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr ox::Error get(T *val) noexcept {
|
||||||
|
*val = value;
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace error {
|
namespace error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user