From f71a1aa667189295a7cf1a20327785769197c332 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sun, 12 Jun 2016 13:31:21 +0300 Subject: [PATCH] Implement move semantics on the Sqrat object wrapper. --- include/sqrat/sqratObject.h | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/include/sqrat/sqratObject.h b/include/sqrat/sqratObject.h index 20f503cb..47f1332f 100644 --- a/include/sqrat/sqratObject.h +++ b/include/sqrat/sqratObject.h @@ -83,6 +83,21 @@ public: sq_addref(vm, &obj); } +#ifdef SCRAT_USE_CXX11_OPTIMIZATIONS + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Move constructor + /// + /// \param so Object to move + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + Object(Object&& so) : vm(so.vm), obj(so.obj), release(so.release) { + sq_resetobject(&so.GetObject()); + so.release = false; + } + +#endif // SCRAT_USE_CXX11_OPTIMIZATIONS + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Constructs an Object from a Squirrel object /// @@ -140,6 +155,30 @@ public: return *this; } +#ifdef SCRAT_USE_CXX11_OPTIMIZATIONS + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Assignment operator + /// + /// \param so Object to move + /// + /// \return The Object itself + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + Object& operator=(Object&& so) { + if(release) { + Release(); + } + vm = so.vm; + obj = so.obj; + release = so.release; + sq_resetobject(&so.GetObject()); + so.release = false; + return *this; + } + +#endif // SCRAT_USE_CXX11_OPTIMIZATIONS + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Gets the Squirrel VM for this Object (reference) ///