[ox/fs] Add modelWrite to FileAddress and add copy constructor and assignment

This commit is contained in:
2019-10-27 16:22:37 -05:00
parent 656039e011
commit 79a1a6f896
2 changed files with 60 additions and 1 deletions

View File

@@ -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;
}
}