[ox/fs] Add modelWrite to FileAddress and add copy constructor and assignment
This commit is contained in:
29
deps/ox/src/ox/fs/filesystem/filelocation.cpp
vendored
29
deps/ox/src/ox/fs/filesystem/filelocation.cpp
vendored
@@ -15,6 +15,13 @@ FileAddress::FileAddress() {
|
||||
m_type = FileAddressType::Inode;
|
||||
}
|
||||
|
||||
FileAddress::FileAddress(const FileAddress &other) {
|
||||
operator=(other);
|
||||
}
|
||||
|
||||
FileAddress::FileAddress(std::nullptr_t) {
|
||||
}
|
||||
|
||||
FileAddress::FileAddress(uint64_t inode) {
|
||||
m_data.inode = inode;
|
||||
m_type = FileAddressType::Inode;
|
||||
@@ -32,9 +39,29 @@ FileAddress::FileAddress(const char *path) {
|
||||
|
||||
FileAddress::~FileAddress() {
|
||||
if (m_type == FileAddressType::Path) {
|
||||
delete m_data.path;
|
||||
delete[] m_data.path;
|
||||
m_data.path = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
const FileAddress &FileAddress::operator=(const FileAddress &other) {
|
||||
m_type = other.m_type;
|
||||
switch (m_type) {
|
||||
case FileAddressType::Path:
|
||||
{
|
||||
auto strSize = ox_strlen(other.m_data.path) + 1;
|
||||
m_data.path = new char[strSize];
|
||||
ox_memcpy(m_data.path, other.m_data.path, strSize);
|
||||
break;
|
||||
}
|
||||
case FileAddressType::ConstPath:
|
||||
case FileAddressType::Inode:
|
||||
m_data = other.m_data;
|
||||
break;
|
||||
case FileAddressType::None:
|
||||
break;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user