[ox] Rename ValErr to Result

This commit is contained in:
Gary Talent 2020-10-16 19:43:10 -05:00
parent faadcae7e9
commit 6b720042d0
23 changed files with 68 additions and 68 deletions

View File

@ -12,7 +12,7 @@ namespace ox {
namespace detail {
ValErr<ClawHeader> readHeader(const char *buff, std::size_t buffLen) noexcept {
Result<ClawHeader> readHeader(const char *buff, std::size_t buffLen) noexcept {
const auto s1End = ox_strchr(buff, ';', buffLen);
if (!s1End) {
return OxError(1);
@ -57,7 +57,7 @@ ValErr<ClawHeader> readHeader(const char *buff, std::size_t buffLen) noexcept {
}
ValErr<Vector<char>> stripClawHeader(const char *buff, std::size_t buffLen) noexcept {
Result<Vector<char>> stripClawHeader(const char *buff, std::size_t buffLen) noexcept {
auto header = detail::readHeader(buff, buffLen);
oxReturnError(header);
Vector<char> out(header.value.dataSize);

View File

@ -27,11 +27,11 @@ struct ClawHeader {
std::size_t dataSize = 0;
};
ValErr<ClawHeader> readHeader(const char *buff, std::size_t buffLen) noexcept;
Result<ClawHeader> readHeader(const char *buff, std::size_t buffLen) noexcept;
}
ValErr<Vector<char>> stripClawHeader(const char *buff, std::size_t buffLen) noexcept;
Result<Vector<char>> stripClawHeader(const char *buff, std::size_t buffLen) noexcept;
template<typename T>
Error readClaw(char *buff, std::size_t buffLen, T *val) {

View File

@ -65,7 +65,7 @@ constexpr const char *getTypeName(T *t) noexcept {
}
template<typename T>
ValErr<String> writeClawHeader(T *t, ClawFormat fmt) noexcept {
Result<String> writeClawHeader(T *t, ClawFormat fmt) noexcept {
String out;
switch (fmt) {
case ClawFormat::Metal:
@ -90,7 +90,7 @@ ValErr<String> writeClawHeader(T *t, ClawFormat fmt) noexcept {
}
template<typename T>
ValErr<Vector<char>> writeClaw(T *t, ClawFormat fmt) {
Result<Vector<char>> writeClaw(T *t, ClawFormat fmt) {
auto [header, headerErr] = detail::writeClawHeader(t, fmt);
oxReturnError(headerErr);
const auto [data, dataErr] = fmt == ClawFormat::Metal ? writeMC(t) : writeOC(t);

View File

@ -110,7 +110,7 @@ class FileStoreTemplate {
FsSize_t readSize, T *data,
FsSize_t *size) const;
ValErr<StatInfo> stat(InodeId_t id);
Result<StatInfo> stat(InodeId_t id);
Error resize();
@ -126,7 +126,7 @@ class FileStoreTemplate {
Error walk(Error(*cb)(uint8_t, uint64_t, uint64_t));
ValErr<InodeId_t> generateInodeId();
Result<InodeId_t> generateInodeId();
bool valid() const;
@ -435,17 +435,17 @@ Error FileStoreTemplate<size_t>::resize(std::size_t size, void *newBuff) {
}
template<typename size_t>
ValErr<StatInfo> FileStoreTemplate<size_t>::stat(InodeId_t id) {
Result<StatInfo> FileStoreTemplate<size_t>::stat(InodeId_t id) {
auto inode = find(id);
if (inode.valid()) {
return ValErr<StatInfo>({
return Result<StatInfo>({
id,
inode->links,
inode->size(),
inode->fileType,
});
}
return ValErr<StatInfo>({}, OxError(0));
return Result<StatInfo>({}, OxError(0));
}
template<typename size_t>
@ -477,7 +477,7 @@ Error FileStoreTemplate<size_t>::walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) {
}
template<typename size_t>
ValErr<typename FileStoreTemplate<size_t>::InodeId_t> FileStoreTemplate<size_t>::generateInodeId() {
Result<typename FileStoreTemplate<size_t>::InodeId_t> FileStoreTemplate<size_t>::generateInodeId() {
auto fsData = fileStoreData();
if (fsData) {
for (auto i = 0; i < 100; i++) {

View File

@ -113,9 +113,9 @@ class Directory {
template<typename F>
Error ls(F cb) noexcept;
ValErr<typename FileStore::InodeId_t> findEntry(const FileName &name) const noexcept;
Result<typename FileStore::InodeId_t> findEntry(const FileName &name) const noexcept;
ValErr<typename FileStore::InodeId_t> find(PathIterator name, FileName *nameBuff = nullptr) const noexcept;
Result<typename FileStore::InodeId_t> find(PathIterator name, FileName *nameBuff = nullptr) const noexcept;
};
@ -314,7 +314,7 @@ ox::Error Directory<FileStore, InodeId_t>::ls(F cb) noexcept {
}
template<typename FileStore, typename InodeId_t>
ValErr<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry(const FileName &name) const noexcept {
Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry(const FileName &name) const noexcept {
oxTrace("ox::fs::Directory::findEntry") << name.c_str();
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
if (!buff.valid()) {
@ -339,7 +339,7 @@ ValErr<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry
}
template<typename FileStore, typename InodeId_t>
ValErr<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::find(PathIterator path, FileName *nameBuff) const noexcept {
Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::find(PathIterator path, FileName *nameBuff) const noexcept {
// reuse nameBuff if it has already been allocated, as it is a rather large variable
if (nameBuff == nullptr) {
nameBuff = reinterpret_cast<FileName*>(ox_alloca(sizeof(FileName)));

View File

@ -68,7 +68,7 @@ class FileAddress {
}
}
ValErr<uint64_t> getInode() const noexcept {
Result<uint64_t> getInode() const noexcept {
switch (m_type) {
case FileAddressType::Inode:
return m_data.inode;
@ -77,7 +77,7 @@ class FileAddress {
}
}
ValErr<const char*> getPath() const noexcept {
Result<const char*> getPath() const noexcept {
switch (m_type) {
case FileAddressType::Path:
return m_data.path;

View File

@ -10,7 +10,7 @@
namespace ox {
ValErr<uint8_t*> FileSystem::read(FileAddress addr) {
Result<uint8_t*> FileSystem::read(FileAddress addr) {
switch (addr.type()) {
case FileAddressType::Inode:
return read(addr.getInode().value);
@ -70,7 +70,7 @@ ox::Error FileSystem::write(FileAddress addr, void *buffer, uint64_t size, uint8
}
}
ox::ValErr<FileStat> FileSystem::stat(FileAddress addr) {
ox::Result<FileStat> FileSystem::stat(FileAddress addr) {
switch (addr.type()) {
case FileAddressType::Inode:
return stat(addr.getInode().value);

View File

@ -32,19 +32,19 @@ class FileSystem {
virtual Error read(const char *path, void *buffer, std::size_t buffSize) = 0;
virtual ValErr<uint8_t*> read(const char *path) = 0;
virtual Result<uint8_t*> read(const char *path) = 0;
virtual Error read(uint64_t inode, void *buffer, std::size_t size) = 0;
virtual Error read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) = 0;
virtual ValErr<uint8_t*> read(uint64_t inode) = 0;
virtual Result<uint8_t*> read(uint64_t inode) = 0;
Error read(FileAddress addr, void *buffer, std::size_t size);
Error read(FileAddress addr, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size);
ValErr<uint8_t*> read(FileAddress addr);
Result<uint8_t*> read(FileAddress addr);
virtual Error remove(const char *path, bool recursive = false) = 0;
@ -58,11 +58,11 @@ class FileSystem {
Error write(FileAddress addr, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile);
virtual ValErr<FileStat> stat(uint64_t inode) = 0;
virtual Result<FileStat> stat(uint64_t inode) = 0;
virtual ValErr<FileStat> stat(const char *path) = 0;
virtual Result<FileStat> stat(const char *path) = 0;
ValErr<FileStat> stat(FileAddress addr);
Result<FileStat> stat(FileAddress addr);
[[nodiscard]] virtual uint64_t spaceNeeded(uint64_t size) = 0;
@ -113,13 +113,13 @@ class FileSystemTemplate: public FileSystem {
Error read(const char *path, void *buffer, std::size_t buffSize) override;
ValErr<uint8_t*> read(const char*) override;
Result<uint8_t*> read(const char*) override;
Error read(uint64_t inode, void *buffer, std::size_t size) override;
Error read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) override;
ValErr<uint8_t*> read(uint64_t) override;
Result<uint8_t*> read(uint64_t) override;
template<typename F>
Error ls(const char *dir, F cb);
@ -137,9 +137,9 @@ class FileSystemTemplate: public FileSystem {
Error write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) override;
ValErr<FileStat> stat(uint64_t inode) override;
Result<FileStat> stat(uint64_t inode) override;
ValErr<FileStat> stat(const char *path) override;
Result<FileStat> stat(const char *path) override;
uint64_t spaceNeeded(uint64_t size) override;
@ -154,14 +154,14 @@ class FileSystemTemplate: public FileSystem {
bool valid() const override;
private:
ValErr<FileSystemData> fileSystemData() const noexcept;
Result<FileSystemData> fileSystemData() const noexcept;
/**
* Finds the inode ID at the given path.
*/
ValErr<uint64_t> find(const char *path) const noexcept;
Result<uint64_t> find(const char *path) const noexcept;
ValErr<Directory> rootDir() const noexcept;
Result<Directory> rootDir() const noexcept;
};
@ -236,7 +236,7 @@ ox::Error FileSystemTemplate<FileStore, Directory>::read(const char *path, void
}
template<typename FileStore, typename Directory>
ValErr<uint8_t*> FileSystemTemplate<FileStore, Directory>::read(const char *path) {
Result<uint8_t*> FileSystemTemplate<FileStore, Directory>::read(const char *path) {
auto fd = fileSystemData();
oxReturnError(fd.error);
Directory rootDir(m_fs, fd.value.rootDirInode);
@ -256,7 +256,7 @@ ox::Error FileSystemTemplate<FileStore, Directory>::read(uint64_t inode, std::si
}
template<typename FileStore, typename Directory>
ValErr<uint8_t*> FileSystemTemplate<FileStore, Directory>::read(uint64_t inode) {
Result<uint8_t*> FileSystemTemplate<FileStore, Directory>::read(uint64_t inode) {
auto data = m_fs.read(inode);
if (!data.valid()) {
return OxError(1);
@ -328,7 +328,7 @@ ox::Error FileSystemTemplate<FileStore, Directory>::write(uint64_t inode, void *
}
template<typename FileStore, typename Directory>
ValErr<FileStat> FileSystemTemplate<FileStore, Directory>::stat(uint64_t inode) {
Result<FileStat> FileSystemTemplate<FileStore, Directory>::stat(uint64_t inode) {
auto s = m_fs.stat(inode);
FileStat out;
out.inode = s.value.inode;
@ -339,7 +339,7 @@ ValErr<FileStat> FileSystemTemplate<FileStore, Directory>::stat(uint64_t inode)
}
template<typename FileStore, typename Directory>
ValErr<FileStat> FileSystemTemplate<FileStore, Directory>::stat(const char *path) {
Result<FileStat> FileSystemTemplate<FileStore, Directory>::stat(const char *path) {
auto inode = find(path);
if (inode.error) {
return {{}, inode.error};
@ -378,7 +378,7 @@ bool FileSystemTemplate<FileStore, Directory>::valid() const {
}
template<typename FileStore, typename Directory>
ValErr<typename FileSystemTemplate<FileStore, Directory>::FileSystemData> FileSystemTemplate<FileStore, Directory>::fileSystemData() const noexcept {
Result<typename FileSystemTemplate<FileStore, Directory>::FileSystemData> FileSystemTemplate<FileStore, Directory>::fileSystemData() const noexcept {
FileSystemData fd;
auto err = m_fs.read(InodeFsData, &fd, sizeof(fd));
if (err != 0) {
@ -388,7 +388,7 @@ ValErr<typename FileSystemTemplate<FileStore, Directory>::FileSystemData> FileSy
}
template<typename FileStore, typename Directory>
ValErr<uint64_t> FileSystemTemplate<FileStore, Directory>::find(const char *path) const noexcept {
Result<uint64_t> FileSystemTemplate<FileStore, Directory>::find(const char *path) const noexcept {
auto fd = fileSystemData();
if (fd.error) {
return {0, fd.error};
@ -406,7 +406,7 @@ ValErr<uint64_t> FileSystemTemplate<FileStore, Directory>::find(const char *path
}
template<typename FileStore, typename Directory>
ValErr<Directory> FileSystemTemplate<FileStore, Directory>::rootDir() const noexcept {
Result<Directory> FileSystemTemplate<FileStore, Directory>::rootDir() const noexcept {
auto fd = fileSystemData();
if (fd.error) {
return {{}, fd.error};

View File

@ -64,7 +64,7 @@ Error PassThroughFS::read(const char *path, void *buffer, std::size_t buffSize)
return OxError(0);
}
ValErr<uint8_t*> PassThroughFS::read(const char*) {
Result<uint8_t*> PassThroughFS::read(const char*) {
return OxError(1);
}
@ -78,7 +78,7 @@ Error PassThroughFS::read(uint64_t, std::size_t, std::size_t, void*, std::size_t
return OxError(1);
}
ValErr<uint8_t*> PassThroughFS::read(uint64_t) {
Result<uint8_t*> PassThroughFS::read(uint64_t) {
return OxError(1);
}
@ -112,12 +112,12 @@ Error PassThroughFS::write(uint64_t, void*, uint64_t, uint8_t) {
return OxError(1);
}
ValErr<FileStat> PassThroughFS::stat(uint64_t) {
Result<FileStat> PassThroughFS::stat(uint64_t) {
// unsupported
return {{}, OxError(1)};
}
ValErr<FileStat> PassThroughFS::stat(const char *path) {
Result<FileStat> PassThroughFS::stat(const char *path) {
std::error_code ec;
const auto p = m_path / stripSlash(path);
uint8_t type = std::filesystem::is_directory(p, ec) ?

View File

@ -43,13 +43,13 @@ class PassThroughFS: public FileSystem {
ox::Error read(const char *path, void *buffer, std::size_t buffSize) override;
ox::ValErr<uint8_t*> read(const char*) override;
ox::Result<uint8_t*> read(const char*) override;
ox::Error read(uint64_t inode, void *buffer, std::size_t size) override;
ox::Error read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) override;
ox::ValErr<uint8_t*> read(uint64_t) override;
ox::Result<uint8_t*> read(uint64_t) override;
template<typename F>
ox::Error ls(const char *dir, F cb);
@ -62,9 +62,9 @@ class PassThroughFS: public FileSystem {
ox::Error write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) override;
ox::ValErr<FileStat> stat(uint64_t inode) override;
ox::Result<FileStat> stat(uint64_t inode) override;
ox::ValErr<FileStat> stat(const char *path) override;
ox::Result<FileStat> stat(const char *path) override;
uint64_t spaceNeeded(uint64_t size) override;

View File

@ -140,7 +140,7 @@ Error PathIterator::next(BString<MaxFileNameLength> *fileName) {
return next(fileName->data(), fileName->cap());
}
ValErr<std::size_t> PathIterator::nextSize() const {
Result<std::size_t> PathIterator::nextSize() const {
std::size_t size = 0;
auto retval = OxError(1);
auto it = m_iterator;

View File

@ -59,7 +59,7 @@ class PathIterator {
/**
* @return 0 if no error
*/
ValErr<std::size_t> nextSize() const;
Result<std::size_t> nextSize() const;
bool hasNext() const;

View File

@ -114,7 +114,7 @@ static_assert(countBytes(0b01111111) == 8);
static_assert(countBytes(0b11111111) == 9);
template<typename I>
ValErr<I> decodeInteger(uint8_t buff[9], std::size_t buffLen, std::size_t *bytesRead) noexcept {
Result<I> decodeInteger(uint8_t buff[9], std::size_t buffLen, std::size_t *bytesRead) noexcept {
const auto bytes = countBytes(buff[0]);
if (bytes == 9) {
*bytesRead = bytes;
@ -144,7 +144,7 @@ ValErr<I> decodeInteger(uint8_t buff[9], std::size_t buffLen, std::size_t *bytes
}
template<typename I>
ValErr<I> decodeInteger(McInt m) noexcept {
Result<I> decodeInteger(McInt m) noexcept {
std::size_t bytesRead;
return decodeInteger<I>(m.data, 9, &bytesRead);
}

View File

@ -18,7 +18,7 @@ FieldPresenceIndicator::FieldPresenceIndicator(uint8_t *mask, std::size_t maxLen
m_maskLen = maxLen;
}
ValErr<bool> FieldPresenceIndicator::get(std::size_t i) const {
Result<bool> FieldPresenceIndicator::get(std::size_t i) const {
if (i / 8 < m_maskLen) {
return (m_mask[i / 8] >> (i % 8)) & 1;
} else {

View File

@ -22,7 +22,7 @@ class FieldPresenceIndicator {
public:
FieldPresenceIndicator(uint8_t *mask, std::size_t maxLen);
ValErr<bool> get(std::size_t i) const;
Result<bool> get(std::size_t i) const;
Error set(std::size_t i, bool on);

View File

@ -109,7 +109,7 @@ Error MetalClawReader::field(const char*, SerStr val) {
return OxError(0);
}
ValErr<ArrayLength> MetalClawReader::arrayLength(const char*, bool pass) {
Result<ArrayLength> MetalClawReader::arrayLength(const char*, bool pass) {
if ((m_unionIdx == -1 || m_unionIdx == m_field) && m_fieldPresence.get(m_field)) {
// read the length
if (m_buffIt >= m_buffLen) {

View File

@ -81,7 +81,7 @@ class MetalClawReader {
* Reads an array length from the current location in the buffer.
* @param pass indicates that the parsing should iterate past the array length
*/
ValErr<ArrayLength> arrayLength(const char *name, bool pass = true);
Result<ArrayLength> arrayLength(const char *name, bool pass = true);
/**
* Reads an string length from the current location in the buffer.

View File

@ -228,7 +228,7 @@ void MetalClawWriter::setTypeInfo(const char*, int fields) {
}
template<typename T>
ValErr<Vector<char>> writeMC(T *val) {
Result<Vector<char>> writeMC(T *val) {
Vector<char> buff(10 * units::MB);
MetalClawWriter writer(bit_cast<uint8_t*>(buff.data()), buff.size());
oxReturnError(model(&writer, val));

View File

@ -234,7 +234,7 @@ void TypeDescWriter::setTypeInfo(const char *name, int) {
}
template<typename T>
ValErr<DescriptorType*> buildTypeDef(T *val) {
Result<DescriptorType*> buildTypeDef(T *val) {
TypeDescWriter writer;
Error err = model(&writer, val);
return {writer.definition(), err};

View File

@ -208,7 +208,7 @@ Error OrganicClawReader::field(const char *key, SerStr val) {
return err;
}
ValErr<std::size_t> OrganicClawReader::arrayLength(const char *key, bool) {
Result<std::size_t> OrganicClawReader::arrayLength(const char *key, bool) {
const auto &jv = value(key);
if (jv.empty()) {
return 0;

View File

@ -72,7 +72,7 @@ class OrganicClawReader {
* Reads an array length from the current location in the buffer.
* @param pass indicates that the parsing should iterate past the array length
*/
ValErr<std::size_t> arrayLength(const char *key, bool pass = true);
Result<std::size_t> arrayLength(const char *key, bool pass = true);
/**
* Reads an string length from the current location in the buffer.
@ -195,7 +195,7 @@ Error readOC(const char *json, std::size_t jsonSize, T *val) noexcept {
}
template<typename T>
ValErr<std::unique_ptr<T>> readOC(const char *json) {
Result<std::unique_ptr<T>> readOC(const char *json) {
auto val = std::make_unique<T>();
oxReturnError(readOC(json, ox_strlen(json), val.get()));
return {std::move(val), OxError(0)};

View File

@ -21,7 +21,7 @@ namespace ox {
class OrganicClawWriter {
template<typename T>
friend ValErr<Vector<char>> writeOC(T *val);
friend Result<Vector<char>> writeOC(T *val);
protected:
Json::Value m_json;
@ -149,7 +149,7 @@ Error OrganicClawWriter::field(const char *key, ox::HashMap<String, T> *val) {
}
template<typename T>
ValErr<Vector<char>> writeOC(T *val) {
Result<Vector<char>> writeOC(T *val) {
OrganicClawWriter writer;
oxReturnError(model(&writer, val));
Json::StreamWriterBuilder jsonBuilder;

View File

@ -57,18 +57,18 @@ constexpr Error _error(const char *file, uint32_t line, uint64_t errCode, const
}
template<typename T>
struct [[nodiscard]] ValErr {
struct [[nodiscard]] Result {
T value;
Error error;
constexpr ValErr() noexcept: error(0) {
constexpr Result() noexcept: error(0) {
}
constexpr ValErr(Error error) noexcept: value(ox::move(value)), error(error) {
constexpr Result(Error error) noexcept: value(ox::move(value)), error(error) {
this->error = error;
}
constexpr ValErr(T value, Error error = OxError(0)) noexcept: value(ox::move(value)), error(error) {
constexpr Result(T value, Error error = OxError(0)) noexcept: value(ox::move(value)), error(error) {
}
explicit constexpr operator const T&() const noexcept {
@ -97,7 +97,7 @@ constexpr Error toError(ox::Error e) noexcept {
}
template<typename T>
constexpr Error toError(const ox::ValErr<T> &ve) noexcept {
constexpr Error toError(const ox::Result<T> &ve) noexcept {
return ve.error;
}