[ox/fs] Add comparison operator for FileAddress
This commit is contained in:
parent
10a12f2ab2
commit
0626c2a815
26
deps/ox/src/ox/fs/filesystem/filelocation.cpp
vendored
26
deps/ox/src/ox/fs/filesystem/filelocation.cpp
vendored
@ -88,6 +88,32 @@ FileAddress &FileAddress::operator=(FileAddress &&other) noexcept {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileAddress::operator==(FileAddress const&other) const noexcept {
|
||||||
|
if (m_type != other.m_type) {
|
||||||
|
auto const aIsPath =
|
||||||
|
m_type == FileAddressType::Path || m_type == FileAddressType::ConstPath;
|
||||||
|
auto const bIsPath =
|
||||||
|
other.m_type == FileAddressType::Path || other.m_type == FileAddressType::ConstPath;
|
||||||
|
if (!(aIsPath && bIsPath)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (m_type) {
|
||||||
|
case FileAddressType::ConstPath:
|
||||||
|
case FileAddressType::Path: {
|
||||||
|
auto const a = getPath();
|
||||||
|
auto const b = other.getPath();
|
||||||
|
return (other.m_type == FileAddressType::ConstPath || other.m_type == FileAddressType::Path)
|
||||||
|
&& (a.value == b.value);
|
||||||
|
}
|
||||||
|
case FileAddressType::Inode:
|
||||||
|
return m_data.inode == other.m_data.inode;
|
||||||
|
case FileAddressType::None:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool FileAddress::operator==(CRStringView path) const noexcept {
|
bool FileAddress::operator==(CRStringView path) const noexcept {
|
||||||
auto [p, err] = getPath();
|
auto [p, err] = getPath();
|
||||||
if (err) {
|
if (err) {
|
||||||
|
11
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
11
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
@ -22,6 +22,9 @@ enum class FileAddressType: int8_t {
|
|||||||
Inode,
|
Inode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
constexpr Error model(T *h, CommonPtrWith<class FileAddress> auto *fa) noexcept;
|
||||||
|
|
||||||
class FileAddress {
|
class FileAddress {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -67,6 +70,8 @@ class FileAddress {
|
|||||||
|
|
||||||
FileAddress &operator=(FileAddress &&other) noexcept;
|
FileAddress &operator=(FileAddress &&other) noexcept;
|
||||||
|
|
||||||
|
bool operator==(const FileAddress &other) const noexcept;
|
||||||
|
|
||||||
bool operator==(CRStringView path) const noexcept;
|
bool operator==(CRStringView path) const noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
@ -89,12 +94,12 @@ class FileAddress {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Result<ox::StringView> getPath() const noexcept {
|
constexpr Result<ox::CStringView> getPath() const noexcept {
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case FileAddressType::Path:
|
case FileAddressType::Path:
|
||||||
return ox::StringView(m_data.path);
|
return ox::CStringView(m_data.path);
|
||||||
case FileAddressType::ConstPath:
|
case FileAddressType::ConstPath:
|
||||||
return ox::StringView(m_data.constPath);
|
return ox::CStringView(m_data.constPath);
|
||||||
default:
|
default:
|
||||||
return OxError(1);
|
return OxError(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user