|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
|
|
|
|
|
|
explicit unique_resource_t(Ressource&& res, Deleter&& deleter, bool shouldrun = true) noexcept : m_deleter(std::move(deleter)) |
|
|
|
|
|
|
|
|
explicit unique_resource_t(Ressource&& res, Deleter&& deleter, bool shouldrun = true) noexcept : m_resource(std::move(res)), |
|
|
|
|
|
m_deleter(std::move(deleter)), |
|
|
|
|
|
m_execute_on_destruction(true) |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
static_cast<void>(res); |
|
|
static_cast<void>(res); |
|
|
static_cast<void>(shouldrun); |
|
|
static_cast<void>(shouldrun); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
~unique_resource_t() |
|
|
~unique_resource_t() |
|
|
{ |
|
|
{ |
|
|
m_deleter(); |
|
|
|
|
|
|
|
|
if( m_execute_on_destruction == true ) |
|
|
|
|
|
{ |
|
|
|
|
|
m_deleter(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Ressource& release() noexcept |
|
|
|
|
|
{ |
|
|
|
|
|
m_execute_on_destruction = false; |
|
|
|
|
|
return m_resource; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
|
|
|
|
|
|
|
|
|
Ressource m_resource; |
|
|
Deleter m_deleter; |
|
|
Deleter m_deleter; |
|
|
|
|
|
bool m_execute_on_destruction; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|