[ox/fs] Add FileAddress::FileAddress(ox::String) and FileAddress::operator==(ox::String)

This commit is contained in:
Gary Talent 2022-03-24 20:45:22 -05:00
parent 6e742e5d45
commit 803cd28087
2 changed files with 19 additions and 0 deletions

View File

@ -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);

View File

@ -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) {