#ifndef __RETRO_IOBJ_HPP__ #define __RETRO_IOBJ_HPP__ #include "RetroTypes.hpp" namespace Retro { 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__