Improve Handle class.

This commit is contained in:
King_DuckZ 2020-04-28 15:13:29 +02:00
parent 79f59f5d36
commit 59140c6c4b

View file

@ -7,20 +7,54 @@ namespace wren {
class Handle {
public:
Handle() noexcept;
Handle (const Handle&) = delete;
Handle (Handle&& other) noexcept;
explicit Handle (VM* vm, WrenHandle* handle) noexcept :
m_handle(handle),
m_vm(vm)
{
}
Handle& operator= (const Handle&) = delete;
Handle& operator= (Handle&& other) noexcept;
~Handle() noexcept;
void release() noexcept;
operator WrenHandle*() { return m_handle; }
operator WrenHandle*() const { return m_handle; }
operator bool() const { return nullptr != m_handle; }
private:
WrenHandle* m_handle;
VM* m_vm;
};
inline Handle::Handle() noexcept :
m_handle(nullptr),
m_vm(nullptr)
{
}
inline Handle::Handle (Handle&& other) noexcept :
m_handle(other.m_handle),
m_vm(other.m_vm)
{
other.m_handle = nullptr;
other.m_vm = nullptr;
}
inline Handle& Handle::operator= (Handle&& other) noexcept {
{
auto tmp = other.m_handle;
other.m_handle = m_handle;
m_handle = tmp;
}
{
auto tmp = other.m_vm;
other.m_vm = m_vm;
m_vm = tmp;
}
return *this;
}
} //namespace wren