[ox] Add StringView, Writer system, Preloader system

This commit is contained in:
2022-11-30 01:45:11 -06:00
parent 98f35140fe
commit cbb496c59f
64 changed files with 2343 additions and 417 deletions

View File

@@ -28,10 +28,10 @@ FileAddress::FileAddress(uint64_t inode) noexcept {
m_type = FileAddressType::Inode;
}
FileAddress::FileAddress(const ox::String &path) noexcept {
FileAddress::FileAddress(ox::CRStringView path) noexcept {
auto pathSize = path.bytes();
m_data.path = new char[pathSize];
memcpy(m_data.path, path.c_str(), pathSize);
memcpy(m_data.path, path.data(), pathSize);
m_type = FileAddressType::Path;
}
@@ -98,7 +98,7 @@ FileAddress &FileAddress::operator=(FileAddress &&other) noexcept {
return *this;
}
bool FileAddress::operator==(const ox::String &path) const noexcept {
bool FileAddress::operator==(CRStringView path) const noexcept {
auto [p, err] = getPath();
if (err) {
return false;

View File

@@ -57,7 +57,11 @@ class FileAddress {
FileAddress(uint64_t inode) noexcept;
FileAddress(const ox::String &path) noexcept;
FileAddress(CRStringView path) noexcept;
template<std::size_t SmallStrSz>
FileAddress(const ox::BasicString<SmallStrSz> &path) noexcept: FileAddress(StringView(path)) {
}
FileAddress(char *path) noexcept;
@@ -69,7 +73,7 @@ class FileAddress {
FileAddress &operator=(FileAddress &&other) noexcept;
bool operator==(const ox::String &path) const noexcept;
bool operator==(CRStringView path) const noexcept;
[[nodiscard]]
constexpr FileAddressType type() const noexcept {
@@ -82,6 +86,7 @@ class FileAddress {
}
}
[[nodiscard]]
constexpr Result<uint64_t> getInode() const noexcept {
switch (m_type) {
case FileAddressType::Inode:
@@ -141,16 +146,16 @@ constexpr Error model(T *io, CommonPtrWith<FileAddress::Data> auto *obj) noexcep
template<typename T>
constexpr Error model(T *io, CommonPtrWith<FileAddress> auto *fa) noexcept {
io->template setTypeInfo<FileAddress>();
if constexpr(ox_strcmp(T::opType(), OpType::Reflect) == 0) {
if constexpr(T::opType() == OpType::Reflect) {
int8_t type = 0;
oxReturnError(io->field("type", &type));
oxReturnError(io->field("data", UnionView(&fa->m_data, 0)));
} else if constexpr(ox_strcmp(T::opType(), OpType::Read) == 0) {
} else if constexpr(T::opType() == OpType::Read) {
auto type = static_cast<int8_t>(fa->m_type);
oxReturnError(io->field("type", &type));
fa->m_type = static_cast<FileAddressType>(type);
oxReturnError(io->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
} else if constexpr(ox_strcmp(T::opType(), OpType::Write) == 0) {
} else if constexpr(T::opType() == OpType::Write) {
auto type = static_cast<int8_t>(fa->m_type);
oxReturnError(io->field("type", &type));
oxReturnError(io->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));

View File

@@ -62,8 +62,8 @@ static ox::Error runRead(ox::FileSystem *fs, int argc, const char **argv) noexce
}
static ox::Error run(int argc, const char **argv) noexcept {
if (argc < 2) {
oxErr("Subcommand and OxFS file arguments are required\n");
if (argc < 3) {
oxErr("OxFS file and subcommand arguments are required\n");
return OxError(1);
}
const auto fsPath = argv[1];