From 10559aa21683e965313808615ccc5bb65b0c6c69 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 24 Mar 2022 20:45:22 -0500 Subject: [PATCH] [ox/fs] Add FileAddress::FileAddress(ox::String) and FileAddress::operator==(ox::String) (synced from 803cd2808741acc12ba5f23d51aac5ee6a3b407c) --- src/ox/fs/filesystem/filelocation.cpp | 15 +++++++++++++++ src/ox/fs/filesystem/filelocation.hpp | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/src/ox/fs/filesystem/filelocation.cpp b/src/ox/fs/filesystem/filelocation.cpp index 76d76bd34..4290beed8 100644 --- a/src/ox/fs/filesystem/filelocation.cpp +++ b/src/ox/fs/filesystem/filelocation.cpp @@ -28,6 +28,13 @@ FileAddress::FileAddress(uint64_t inode) noexcept { m_type = FileAddressType::Inode; } +FileAddress::FileAddress(const ox::String &path) noexcept { + auto pathSize = path.bytes() + 1; + m_data.path = new char[pathSize]; + memcpy(m_data.path, path.c_str(), pathSize); + m_type = FileAddressType::Path; +} + FileAddress::FileAddress(char *path) noexcept { auto pathSize = ox_strlen(path) + 1; m_data.path = new char[pathSize]; @@ -93,6 +100,14 @@ FileAddress &FileAddress::operator=(FileAddress &&other) noexcept { return *this; } +bool FileAddress::operator==(const ox::String &path) const noexcept { + auto [p, err] = getPath(); + if (err) { + return false; + } + return path == p; +} + void FileAddress::cleanup() noexcept { if (m_type == FileAddressType::Path) { safeDeleteArray(m_data.path); diff --git a/src/ox/fs/filesystem/filelocation.hpp b/src/ox/fs/filesystem/filelocation.hpp index 414c5e2b2..20441f646 100644 --- a/src/ox/fs/filesystem/filelocation.hpp +++ b/src/ox/fs/filesystem/filelocation.hpp @@ -54,6 +54,8 @@ class FileAddress { FileAddress(uint64_t inode) noexcept; + FileAddress(const ox::String &path) noexcept; + FileAddress(char *path) noexcept; FileAddress(const char *path) noexcept; @@ -64,6 +66,8 @@ class FileAddress { FileAddress &operator=(FileAddress &&other) noexcept; + bool operator==(const ox::String &path) const noexcept; + [[nodiscard]] constexpr FileAddressType type() const noexcept { switch (m_type) {