From 4a424aa2b399f90c3bcdf482ff06bcc975ba46a0 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 21 Aug 2015 16:59:57 -1000 Subject: [PATCH] Minor IObj additions --- Runtime/IObj.hpp | 31 +++++++++++++++++++++++++++++++ Runtime/IVParamObj.hpp | 1 + 2 files changed, 32 insertions(+) diff --git a/Runtime/IObj.hpp b/Runtime/IObj.hpp index 537897439..51b4e478b 100644 --- a/Runtime/IObj.hpp +++ b/Runtime/IObj.hpp @@ -10,6 +10,37 @@ class IObj { }; +class TObjOwnerDerivedFromIObjUntyped : public IObj +{ +protected: + void* m_objPtr; + TObjOwnerDerivedFromIObjUntyped(void* objPtr) : m_objPtr(objPtr) {} +}; + +template +class TObjOwnerDerivedFromIObj : public TObjOwnerDerivedFromIObjUntyped +{ + TObjOwnerDerivedFromIObj(T* objPtr) : TObjOwnerDerivedFromIObjUntyped(objPtr) {} +public: + static std::unique_ptr> GetNewDerivedObject(std::unique_ptr&& obj) + { + std::unique_ptr movedObjPtr = std::move(obj); + return std::unique_ptr> + (new TObjOwnerDerivedFromIObj(movedObjPtr.release())); + } + ~TObjOwnerDerivedFromIObj() {delete static_cast(m_objPtr);} +}; + +template +class TToken +{ +public: + static std::unique_ptr> GetIObjObjectFor(std::unique_ptr&& obj) + { + return TObjOwnerDerivedFromIObj::GetNewDerivedObject(std::move(obj)); + } +}; + } #endif // __RETRO_IOBJ_HPP__ diff --git a/Runtime/IVParamObj.hpp b/Runtime/IVParamObj.hpp index 7bcf0ce45..294e0c654 100644 --- a/Runtime/IVParamObj.hpp +++ b/Runtime/IVParamObj.hpp @@ -1,6 +1,7 @@ #ifndef __RETRO_IVPARAMOBJ_HPP__ #define __RETRO_IVPARAMOBJ_HPP__ +#include #include "IObj.hpp" namespace Retro