diff --git a/deps/ox/src/ox/fs/filesystem/filelocation.hpp b/deps/ox/src/ox/fs/filesystem/filelocation.hpp index 2c1edbd7..b2376384 100644 --- a/deps/ox/src/ox/fs/filesystem/filelocation.hpp +++ b/deps/ox/src/ox/fs/filesystem/filelocation.hpp @@ -25,7 +25,7 @@ enum class FileAddressType: int8_t { class FileAddress { template - friend constexpr Error model(T*, CommonPtrWith auto*) noexcept; + friend constexpr Error model(T *h, CommonPtrWith auto *fa) noexcept; public: static constexpr auto TypeName = "net.drinkingtea.ox.FileAddress"; @@ -80,7 +80,6 @@ class FileAddress { } } - [[nodiscard]] constexpr Result getInode() const noexcept { switch (m_type) { case FileAddressType::Inode: @@ -127,45 +126,6 @@ constexpr FileAddress::~FileAddress() noexcept { cleanup(); } -template<> -constexpr const char *getModelTypeName() noexcept { - return FileAddress::Data::TypeName; -} - -template<> -constexpr const char *getModelTypeName() noexcept { - return FileAddress::TypeName; -} - -template -constexpr Error model(T *io, CommonPtrWith auto *obj) noexcept { - oxReturnError(io->template setTypeInfo()); - oxReturnError(io->fieldCString("path", &obj->path)); - oxReturnError(io->fieldCString("constPath", &obj->path)); - oxReturnError(io->field("inode", &obj->inode)); - return OxError(0); -} - -template -constexpr Error model(T *io, CommonPtrWith auto *fa) noexcept { - oxReturnError(io->template setTypeInfo()); - 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(fa->m_type); - oxReturnError(io->field("type", &type)); - fa->m_type = static_cast(type); - oxReturnError(io->field("data", UnionView(&fa->m_data, static_cast(fa->m_type)))); - } else if constexpr(T::opType() == OpType::Write) { - auto type = static_cast(fa->m_type); - oxReturnError(io->field("type", &type)); - oxReturnError(io->field("data", UnionView(&fa->m_data, static_cast(fa->m_type)))); - } - return OxError(0); -} - constexpr void FileAddress::cleanup() noexcept { if (m_type == FileAddressType::Path) { safeDeleteArray(m_data.path); @@ -178,4 +138,43 @@ constexpr void FileAddress::clear() noexcept { m_type = FileAddressType::None; } +template<> +constexpr const char *getModelTypeName() noexcept { + return FileAddress::Data::TypeName; +} + +template<> +constexpr const char *getModelTypeName() noexcept { + return FileAddress::TypeName; +} + +template +constexpr Error model(T *h, CommonPtrWith auto *obj) noexcept { + oxReturnError(h->template setTypeInfo()); + oxReturnError(h->fieldCString("path", &obj->path)); + oxReturnError(h->fieldCString("constPath", &obj->path)); + oxReturnError(h->field("inode", &obj->inode)); + return {}; +} + +template +constexpr Error model(T *h, CommonPtrWith auto *fa) noexcept { + oxReturnError(h->template setTypeInfo()); + 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(fa->m_type); + oxReturnError(h->field("type", &type)); + fa->m_type = static_cast(type); + oxReturnError(h->field("data", UnionView(&fa->m_data, static_cast(fa->m_type)))); + } else if constexpr(T::opType() == OpType::Write) { + auto type = static_cast(fa->m_type); + oxReturnError(h->field("type", &type)); + oxReturnError(h->field("data", UnionView(&fa->m_data, static_cast(fa->m_type)))); + } + return {}; +} + }