[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;
|
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 {
|
FileAddress::FileAddress(char *path) noexcept {
|
||||||
auto pathSize = ox_strlen(path) + 1;
|
auto pathSize = ox_strlen(path) + 1;
|
||||||
m_data.path = new char[pathSize];
|
m_data.path = new char[pathSize];
|
||||||
@ -93,6 +100,14 @@ FileAddress &FileAddress::operator=(FileAddress &&other) noexcept {
|
|||||||
return *this;
|
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 {
|
void FileAddress::cleanup() noexcept {
|
||||||
if (m_type == FileAddressType::Path) {
|
if (m_type == FileAddressType::Path) {
|
||||||
safeDeleteArray(m_data.path);
|
safeDeleteArray(m_data.path);
|
||||||
|
@ -54,6 +54,8 @@ class FileAddress {
|
|||||||
|
|
||||||
FileAddress(uint64_t inode) noexcept;
|
FileAddress(uint64_t inode) noexcept;
|
||||||
|
|
||||||
|
FileAddress(const ox::String &path) noexcept;
|
||||||
|
|
||||||
FileAddress(char *path) noexcept;
|
FileAddress(char *path) noexcept;
|
||||||
|
|
||||||
FileAddress(const char *path) noexcept;
|
FileAddress(const char *path) noexcept;
|
||||||
@ -64,6 +66,8 @@ class FileAddress {
|
|||||||
|
|
||||||
FileAddress &operator=(FileAddress &&other) noexcept;
|
FileAddress &operator=(FileAddress &&other) noexcept;
|
||||||
|
|
||||||
|
bool operator==(const ox::String &path) const noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr FileAddressType type() const noexcept {
|
constexpr FileAddressType type() const noexcept {
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user