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

This commit is contained in:
Gary Talent 2024-01-19 20:22:52 -06:00
parent c2e34b6456
commit 08be822bdd
2 changed files with 34 additions and 3 deletions

View File

@ -88,6 +88,32 @@ FileAddress &FileAddress::operator=(FileAddress &&other) noexcept {
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 {
auto [p, err] = getPath();
if (err) {

View File

@ -22,6 +22,9 @@ enum class FileAddressType: int8_t {
Inode,
};
template<typename T>
constexpr Error model(T *h, CommonPtrWith<class FileAddress> auto *fa) noexcept;
class FileAddress {
template<typename T>
@ -67,6 +70,8 @@ class FileAddress {
FileAddress &operator=(FileAddress &&other) noexcept;
bool operator==(const FileAddress &other) const noexcept;
bool operator==(CRStringView path) const noexcept;
[[nodiscard]]
@ -89,12 +94,12 @@ class FileAddress {
}
}
constexpr Result<ox::StringView> getPath() const noexcept {
constexpr Result<ox::CStringView> getPath() const noexcept {
switch (m_type) {
case FileAddressType::Path:
return ox::StringView(m_data.path);
return ox::CStringView(m_data.path);
case FileAddressType::ConstPath:
return ox::StringView(m_data.constPath);
return ox::CStringView(m_data.constPath);
default:
return OxError(1);
}