[ox/fs] Add FileAddress::FileAddress(ox::String) and FileAddress::operator==(ox::String)
This commit is contained in:
parent
6e742e5d45
commit
803cd28087
15
deps/ox/src/ox/fs/filesystem/filelocation.cpp
vendored
15
deps/ox/src/ox/fs/filesystem/filelocation.cpp
vendored
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user