EHS/src/BaseObj.cpp
Karutoh bcd71cf2b5
All checks were successful
Build & Release / Windows-AMD64-Build (push) Successful in 1m8s
Build & Release / Linux-AMD64-Build (push) Successful in 1m30s
Build & Release / Linux-AARCH64-Build (push) Successful in 3m21s
Adjusted workflow.
2024-02-05 22:25:30 -08:00

154 lines
2.8 KiB
C++

#include "ehs/BaseObj.h"
namespace ehs
{
BaseObj::~BaseObj()
{
delete[] hierarchy;
}
BaseObj::BaseObj()
: hierarchy(nullptr), hierarchySize(0)
{
AddType("BaseObj");
}
BaseObj::BaseObj(BaseObj&& base) noexcept
: hierarchy(base.hierarchy), hierarchySize(base.hierarchySize)
{
base.hierarchy = nullptr;
base.hierarchySize = 0;
}
BaseObj::BaseObj(const BaseObj& base)
: hierarchy(new Type[base.hierarchySize]), hierarchySize(base.hierarchySize)
{
for (UInt_64 i = 0; i < hierarchySize; i++)
hierarchy[i] = base.hierarchy[i];
}
BaseObj& BaseObj::operator=(BaseObj&& base) noexcept
{
if (this == &base)
return *this;
delete[] hierarchy;
hierarchy = base.hierarchy;
hierarchySize = base.hierarchySize;
base.hierarchy = nullptr;
base.hierarchySize = 0;
return *this;
}
BaseObj& BaseObj::operator=(const BaseObj& base)
{
if (this == &base)
return *this;
delete[] hierarchy;
hierarchy = new Type[base.hierarchySize];
for (UInt_64 i = 0; i < base.hierarchySize; i++)
hierarchy[i] = base.hierarchy[i];
hierarchySize = base.hierarchySize;
return *this;
}
bool BaseObj::operator==(const BaseObj& base) const
{
if (hierarchySize != base.hierarchySize)
return false;
for (UInt_64 i = 0; i < hierarchySize; i++)
if (hierarchy[i] != base.hierarchy[i])
return false;
return true;
}
bool BaseObj::operator!=(const BaseObj& base) const
{
if (hierarchySize != base.hierarchySize)
return true;
for (UInt_64 i = 0; i < hierarchySize; i++)
if (hierarchy[i] != base.hierarchy[i])
return true;
return false;
}
const Type* BaseObj::GetHierarchy() const
{
return hierarchy;
}
UInt_64 BaseObj::GetHierarchySize() const
{
return hierarchySize;
}
bool BaseObj::HasType(UInt_64 typeHashId) const
{
for (UInt_64 i = 0; i < hierarchySize; i++)
if (hierarchy[i] == typeHashId)
return true;
return false;
}
bool BaseObj::HasType(const Char_8* typeId) const
{
return HasType(Type::GenHash(typeId, Type::CalcSize(typeId)));
}
Type BaseObj::GetType() const
{
return hierarchy[0];
}
UInt_64 BaseObj::GetTypeIdSize() const
{
return hierarchy[0].GetSize();
}
const Char_8* BaseObj::GetTypeId() const
{
return hierarchy[0].GetId();
}
UInt_64 BaseObj::GetTypeHashId() const
{
return hierarchy[0].GetHashId();
}
BaseObj* BaseObj::Clone() const
{
return new BaseObj(*this);
}
void BaseObj::AddType(const Char_8* const id)
{
Type newType(id);
for (UInt_64 i = 0; i < hierarchySize; i++)
if (hierarchy[i] == newType)
return;
Type* result = new Type[hierarchySize + 1];
result[0] = (Type&&)newType;
for (UInt_64 i = 0; i < hierarchySize; i++)
result[i + 1] = (Type&&)hierarchy[i];
hierarchySize++;
delete[] hierarchy;
hierarchy = result;
}
}