From 59140c6c4b714368345709290cf9f773ed16ab2e Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 28 Apr 2020 15:13:29 +0200 Subject: [PATCH] Improve Handle class. --- src/wren/handle.hpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/wren/handle.hpp b/src/wren/handle.hpp index 325844e..f4fcf7e 100644 --- a/src/wren/handle.hpp +++ b/src/wren/handle.hpp @@ -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