From 3ca90d06985225fd64a50c40a67974e0829372bc Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sun, 12 Jun 2016 13:43:19 +0300 Subject: [PATCH] Implement move semantics on the Sqrat table wrapper. --- include/sqrat/sqratTable.h | 131 +++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/include/sqrat/sqratTable.h b/include/sqrat/sqratTable.h index 27fe8988..03eb1a89 100644 --- a/include/sqrat/sqratTable.h +++ b/include/sqrat/sqratTable.h @@ -66,6 +66,19 @@ public: TableBase(const Object& obj) : Object(obj) { } +#ifdef SCRAT_USE_CXX11_OPTIMIZATIONS + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Construct the TableBase from an Object that already exists + /// + /// \param obj An Object that should already represent a Squirrel table + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + TableBase(Object&& obj) : Object(std::move(obj)) { + } + +#endif // SCRAT_USE_CXX11_OPTIMIZATIONS + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Construct the TableBase from a HSQOBJECT and HSQUIRRELVM that already exist /// @@ -76,6 +89,58 @@ public: TableBase(HSQOBJECT o, HSQUIRRELVM v = DefaultVM::Get()) : Object(o, v) { } + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Copy constructor + /// + /// \param st TableBase to copy + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + TableBase(const TableBase& st) : Object(st) { + } + +#ifdef SCRAT_USE_CXX11_OPTIMIZATIONS + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Move constructor + /// + /// \param st TableBase to move + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + TableBase(TableBase&& st) : Object(std::move(st)) { + } + +#endif // SCRAT_USE_CXX11_OPTIMIZATIONS + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Assignment operator + /// + /// \param st TableBase to copy + /// + /// \return The TableBase itself + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + TableBase& operator=(const TableBase& st) { + Object::operator = (st); + return *this; + } + +#ifdef SCRAT_USE_CXX11_OPTIMIZATIONS + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Assignment operator + /// + /// \param st TableBase to move + /// + /// \return The TableBase itself + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + TableBase& operator=(TableBase&& st) { + Object::operator = (std::move(st)); + return *this; + } + +#endif // SCRAT_USE_CXX11_OPTIMIZATIONS + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Binds a Table or Class to the Table (can be used to facilitate namespaces) /// @@ -428,6 +493,19 @@ public: Table(const Object& obj) : TableBase(obj) { } +#ifdef SCRAT_USE_CXX11_OPTIMIZATIONS + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Construct the Table from an Object that already exists + /// + /// \param obj An Object that should already represent a Squirrel table + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + Table(Object&& obj) : TableBase(std::move(obj)) { + } + +#endif // SCRAT_USE_CXX11_OPTIMIZATIONS + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Construct the Table from a HSQOBJECT and HSQUIRRELVM that already exist /// @@ -437,6 +515,59 @@ public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Table(HSQOBJECT o, HSQUIRRELVM v = DefaultVM::Get()) : TableBase(o, v) { } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Copy constructor + /// + /// \param st Table to copy + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + Table(const Table& st) : TableBase(st) { + } + +#ifdef SCRAT_USE_CXX11_OPTIMIZATIONS + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Move constructor + /// + /// \param st Table to move + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + Table(Table&& st) : TableBase(std::move(st)) { + } + +#endif // SCRAT_USE_CXX11_OPTIMIZATIONS + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Assignment operator + /// + /// \param st Table to copy + /// + /// \return The Table itself + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + Table& operator=(const Table& st) { + TableBase::operator = (st); + return *this; + } + +#ifdef SCRAT_USE_CXX11_OPTIMIZATIONS + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Assignment operator + /// + /// \param st Table to move + /// + /// \return The Table itself + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + Table& operator=(Table&& st) { + TableBase::operator = (std::move(st)); + return *this; + } + +#endif // SCRAT_USE_CXX11_OPTIMIZATIONS + }; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////