60 lines
1.1 KiB
C++
60 lines
1.1 KiB
C++
#pragma once
|
|
|
|
typedef struct WrenHandle WrenHandle;
|
|
|
|
namespace wren {
|
|
class VM;
|
|
|
|
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*() 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
|