#ifndef __PSHAG_IOBJ_HPP__ #define __PSHAG_IOBJ_HPP__ #include "RetroTypes.hpp" namespace pshag { class IObj { public: virtual ~IObj() = default; }; 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) { return std::unique_ptr> (new TObjOwnerDerivedFromIObj(obj.release())); } ~TObjOwnerDerivedFromIObj() {delete static_cast(m_objPtr);} T* GetObj() {return static_cast(m_objPtr);} }; } #endif // __PSHAG_IOBJ_HPP__