2015-08-21 00:06:39 +00:00
|
|
|
#ifndef __RETRO_IOBJ_HPP__
|
|
|
|
#define __RETRO_IOBJ_HPP__
|
|
|
|
|
|
|
|
#include "RetroTypes.hpp"
|
|
|
|
|
|
|
|
namespace Retro
|
|
|
|
{
|
|
|
|
|
|
|
|
class IObj
|
|
|
|
{
|
2015-08-23 06:42:29 +00:00
|
|
|
public:
|
2016-02-05 01:27:03 +00:00
|
|
|
virtual ~IObj() = default;
|
2015-08-21 00:06:39 +00:00
|
|
|
};
|
|
|
|
|
2015-08-22 02:59:57 +00:00
|
|
|
class TObjOwnerDerivedFromIObjUntyped : public IObj
|
|
|
|
{
|
|
|
|
protected:
|
2016-02-05 01:27:03 +00:00
|
|
|
void* m_objPtr;
|
|
|
|
TObjOwnerDerivedFromIObjUntyped(void* objPtr) : m_objPtr(objPtr) {}
|
2015-08-22 02:59:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
class TObjOwnerDerivedFromIObj : public TObjOwnerDerivedFromIObjUntyped
|
|
|
|
{
|
|
|
|
TObjOwnerDerivedFromIObj(T* objPtr) : TObjOwnerDerivedFromIObjUntyped(objPtr) {}
|
|
|
|
public:
|
|
|
|
static std::unique_ptr<TObjOwnerDerivedFromIObj<T>> GetNewDerivedObject(std::unique_ptr<T>&& obj)
|
|
|
|
{
|
|
|
|
return std::unique_ptr<TObjOwnerDerivedFromIObj<T>>
|
2016-02-05 01:27:03 +00:00
|
|
|
(new TObjOwnerDerivedFromIObj<T>(obj.release()));
|
2015-08-22 02:59:57 +00:00
|
|
|
}
|
|
|
|
~TObjOwnerDerivedFromIObj() {delete static_cast<T*>(m_objPtr);}
|
2016-02-06 00:34:40 +00:00
|
|
|
T* GetObj() {return static_cast<T*>(m_objPtr);}
|
2015-08-22 02:59:57 +00:00
|
|
|
};
|
|
|
|
|
2015-08-21 00:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __RETRO_IOBJ_HPP__
|