Improve Handle class.
This commit is contained in:
parent
79f59f5d36
commit
59140c6c4b
1 changed files with 35 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue