diff --git a/source/scriptinterface/ScriptInterface.h b/source/scriptinterface/ScriptInterface.h index c48c2679da..a905ac2495 100644 --- a/source/scriptinterface/ScriptInterface.h +++ b/source/scriptinterface/ScriptInterface.h @@ -394,6 +394,25 @@ private: struct CustomType { + // TODO: Move assignment operator and move constructor only have to be + // explicitly defined for Visual Studio. VS2013 is still behind on C++11 support + // What's missing is what they call "Rvalue references v3.0", see + // https://msdn.microsoft.com/en-us/library/hh567368.aspx#rvref + CustomType() {} + CustomType& operator=(CustomType&& other) + { + m_Prototype = std::move(other.m_Prototype); + m_Class = std::move(other.m_Class); + m_Constructor = std::move(other.m_Constructor); + return *this; + } + CustomType(CustomType&& other) + { + m_Prototype = std::move(other.m_Prototype); + m_Class = std::move(other.m_Class); + m_Constructor = std::move(other.m_Constructor); + } + DefPersistentRooted m_Prototype; JSClass* m_Class; JSNative m_Constructor; diff --git a/source/scriptinterface/ScriptVal.h b/source/scriptinterface/ScriptVal.h index 5092f557f9..d39ab259d9 100644 --- a/source/scriptinterface/ScriptVal.h +++ b/source/scriptinterface/ScriptVal.h @@ -79,6 +79,21 @@ public: m_Val.reset(new JS::PersistentRooted(cx, val)); } + // TODO: Move assignment operator and move constructor only have to be + // explicitly defined for Visual Studio. VS2013 is still behind on C++11 support + // What's missing is what they call "Rvalue references v3.0", see + // https://msdn.microsoft.com/en-us/library/hh567368.aspx#rvref + DefPersistentRooted& operator=(DefPersistentRooted&& other) + { + m_Val = std::move(other.m_Val); + return *this; + } + + DefPersistentRooted(DefPersistentRooted&& other) + { + m_Val = std::move(other.m_Val); + } + private: std::unique_ptr > m_Val; }; diff --git a/source/simulation2/system/ComponentManager.cpp b/source/simulation2/system/ComponentManager.cpp index 0e8ad0992d..67441335e9 100644 --- a/source/simulation2/system/ComponentManager.cpp +++ b/source/simulation2/system/ComponentManager.cpp @@ -244,7 +244,7 @@ void CComponentManager::Script_RegisterComponentType_Common(ScriptInterface::CxP } // Construct a new ComponentType, using the wrapper's alloc functions - componentManager->m_ComponentTypesById[cid] = { + ComponentType ct( CT_Script, iid, ctWrapper.alloc, @@ -252,7 +252,8 @@ void CComponentManager::Script_RegisterComponentType_Common(ScriptInterface::CxP cname, schema, DefPersistentRooted(cx, ctor) - }; + ); + componentManager->m_ComponentTypesById[cid] = std::move(ct); componentManager->m_CurrentComponent = cid; // needed by Subscribe @@ -542,7 +543,7 @@ void CComponentManager::ResetState() void CComponentManager::RegisterComponentType(InterfaceId iid, ComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, const char* name, const std::string& schema) { - ComponentType c = { CT_Native, iid, alloc, dealloc, name, schema, DefPersistentRooted() }; + ComponentType c(CT_Native, iid, alloc, dealloc, name, schema, std::move(DefPersistentRooted())); m_ComponentTypesById.insert(std::make_pair(cid, std::move(c))); m_ComponentTypeIdsByName[name] = cid; } @@ -550,7 +551,7 @@ void CComponentManager::RegisterComponentType(InterfaceId iid, ComponentTypeId c void CComponentManager::RegisterComponentTypeScriptWrapper(InterfaceId iid, ComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, const char* name, const std::string& schema) { - ComponentType c = { CT_ScriptWrapper, iid, alloc, dealloc, name, schema, DefPersistentRooted() }; + ComponentType c(CT_ScriptWrapper, iid, alloc, dealloc, name, schema, std::move(DefPersistentRooted())); m_ComponentTypesById.insert(std::make_pair(cid, std::move(c))); m_ComponentTypeIdsByName[name] = cid; // TODO: merge with RegisterComponentType diff --git a/source/simulation2/system/ComponentManager.h b/source/simulation2/system/ComponentManager.h index 4ff4b20217..5f09d22928 100644 --- a/source/simulation2/system/ComponentManager.h +++ b/source/simulation2/system/ComponentManager.h @@ -71,6 +71,46 @@ private: std::string name; std::string schema; // RelaxNG fragment DefPersistentRooted ctor; // only valid if type == CT_Script + + // TODO: Constructor, move assignment operator and move constructor only have to be + // explicitly defined for Visual Studio. VS2013 is still behind on C++11 support + // What's missing is what they call "Rvalue references v3.0", see + // https://msdn.microsoft.com/en-us/library/hh567368.aspx#rvref + ComponentType() {} + ComponentType (EComponentTypeType type, InterfaceId iid, AllocFunc alloc, + DeallocFunc dealloc, std::string name, std::string schema, DefPersistentRooted ctor) : + type(type), + iid(iid), + alloc(alloc), + dealloc(dealloc), + name(name), + schema(schema), + ctor(std::move(ctor)) + { + } + + ComponentType& operator= (ComponentType&& other) + { + type = std::move(other.type); + iid = std::move(other.iid); + alloc = std::move(other.alloc); + dealloc = std::move(other.dealloc); + name = std::move(other.name); + schema = std::move(other.schema); + ctor = std::move(other.ctor); + return *this; + } + + ComponentType(ComponentType&& other) + { + type = std::move(other.type); + iid = std::move(other.iid); + alloc = std::move(other.alloc); + dealloc = std::move(other.dealloc); + name = std::move(other.name); + schema = std::move(other.schema); + ctor = std::move(other.ctor); + } }; struct FindJSONFilesCallbackData