This commit is contained in:
ZY4N
2025-03-23 21:11:22 +01:00
parent 510398423a
commit c609d49f0d
49 changed files with 1412 additions and 924 deletions

View File

@@ -0,0 +1,67 @@
#ifndef INCLUDE_RESOURCE_HANDLE_IMPLEMENTATION
# error Never include this file directly include 'resource_handle.hpp'
#endif
zgl::resource_handle::resource_handle(id_type id, reference_counter* manager)
: m_id{ id }, m_counter{ manager } {}
zgl::resource_handle::resource_handle(const resource_handle& other) noexcept
: m_id{ other.m_id }, m_counter{ other.m_counter }
{
if (m_id != 0 and m_counter != nullptr)
{
m_counter->add_reference(m_id);
}
}
zgl::resource_handle& zgl::resource_handle::operator=(
const resource_handle& other
) noexcept {
if (&other != this)
{
this->~resource_handle();
m_id = other.m_id;
m_counter = other.m_counter;
if (m_id != 0 and m_counter != nullptr)
{
m_counter->add_reference(m_id);
}
}
return *this;
}
zgl::resource_handle::resource_handle(resource_handle&& other) noexcept
: m_id{ other.m_id }, m_counter{ other.m_counter }
{
other.m_id = 0;
other.m_counter = nullptr;
}
zgl::resource_handle& zgl::resource_handle::resource_handle::operator=(
resource_handle&& other
) noexcept {
if (&other != this)
{
this->~resource_handle();
m_id = other.m_id;
m_counter = other.m_counter;
other.m_id = 0;
other.m_counter = nullptr;
}
return *this;
}
zgl::resource_handle::~resource_handle()
{
if (m_id != 0 and m_counter != nullptr)
{
m_counter->remove_reference(m_id);
}
}