[ox/fs] Some cleanup for FileAddress
This commit is contained in:
parent
115941a787
commit
a4fac4c1d3
81
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
81
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
@ -25,7 +25,7 @@ enum class FileAddressType: int8_t {
|
|||||||
class FileAddress {
|
class FileAddress {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
friend constexpr Error model(T*, CommonPtrWith<FileAddress> auto*) noexcept;
|
friend constexpr Error model(T *h, CommonPtrWith<FileAddress> auto *fa) noexcept;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr auto TypeName = "net.drinkingtea.ox.FileAddress";
|
static constexpr auto TypeName = "net.drinkingtea.ox.FileAddress";
|
||||||
@ -80,7 +80,6 @@ class FileAddress {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
constexpr Result<uint64_t> getInode() const noexcept {
|
constexpr Result<uint64_t> getInode() const noexcept {
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case FileAddressType::Inode:
|
case FileAddressType::Inode:
|
||||||
@ -127,45 +126,6 @@ constexpr FileAddress::~FileAddress() noexcept {
|
|||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
|
||||||
constexpr const char *getModelTypeName<FileAddress::Data>() noexcept {
|
|
||||||
return FileAddress::Data::TypeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
constexpr const char *getModelTypeName<FileAddress>() noexcept {
|
|
||||||
return FileAddress::TypeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
constexpr Error model(T *io, CommonPtrWith<FileAddress::Data> auto *obj) noexcept {
|
|
||||||
oxReturnError(io->template setTypeInfo<FileAddress::Data>());
|
|
||||||
oxReturnError(io->fieldCString("path", &obj->path));
|
|
||||||
oxReturnError(io->fieldCString("constPath", &obj->path));
|
|
||||||
oxReturnError(io->field("inode", &obj->inode));
|
|
||||||
return OxError(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
constexpr Error model(T *io, CommonPtrWith<FileAddress> auto *fa) noexcept {
|
|
||||||
oxReturnError(io->template setTypeInfo<FileAddress>());
|
|
||||||
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(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(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))));
|
|
||||||
}
|
|
||||||
return OxError(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr void FileAddress::cleanup() noexcept {
|
constexpr void FileAddress::cleanup() noexcept {
|
||||||
if (m_type == FileAddressType::Path) {
|
if (m_type == FileAddressType::Path) {
|
||||||
safeDeleteArray(m_data.path);
|
safeDeleteArray(m_data.path);
|
||||||
@ -178,4 +138,43 @@ constexpr void FileAddress::clear() noexcept {
|
|||||||
m_type = FileAddressType::None;
|
m_type = FileAddressType::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
constexpr const char *getModelTypeName<FileAddress::Data>() noexcept {
|
||||||
|
return FileAddress::Data::TypeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
constexpr const char *getModelTypeName<FileAddress>() noexcept {
|
||||||
|
return FileAddress::TypeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
constexpr Error model(T *h, CommonPtrWith<FileAddress::Data> auto *obj) noexcept {
|
||||||
|
oxReturnError(h->template setTypeInfo<FileAddress::Data>());
|
||||||
|
oxReturnError(h->fieldCString("path", &obj->path));
|
||||||
|
oxReturnError(h->fieldCString("constPath", &obj->path));
|
||||||
|
oxReturnError(h->field("inode", &obj->inode));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
constexpr Error model(T *h, CommonPtrWith<FileAddress> auto *fa) noexcept {
|
||||||
|
oxReturnError(h->template setTypeInfo<FileAddress>());
|
||||||
|
if constexpr(T::opType() == OpType::Reflect) {
|
||||||
|
int8_t type = 0;
|
||||||
|
oxReturnError(h->field("type", &type));
|
||||||
|
oxReturnError(h->field("data", UnionView(&fa->m_data, 0)));
|
||||||
|
} else if constexpr(T::opType() == OpType::Read) {
|
||||||
|
auto type = static_cast<int8_t>(fa->m_type);
|
||||||
|
oxReturnError(h->field("type", &type));
|
||||||
|
fa->m_type = static_cast<FileAddressType>(type);
|
||||||
|
oxReturnError(h->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
|
||||||
|
} else if constexpr(T::opType() == OpType::Write) {
|
||||||
|
auto type = static_cast<int8_t>(fa->m_type);
|
||||||
|
oxReturnError(h->field("type", &type));
|
||||||
|
oxReturnError(h->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user