#ifndef __RETRO_IOBJ_HPP__ #define __RETRO_IOBJ_HPP__ #include "RetroTypes.hpp" namespace Retro { class IObj { public: virtual ~IObj() {} }; class TObjOwnerDerivedFromIObjUntyped : public IObj { protected: IObj* m_objPtr; TObjOwnerDerivedFromIObjUntyped(IObj* 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__