metaforce/Runtime/IObj.hpp

33 lines
847 B
C++
Raw Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
2015-08-21 00:06:39 +00:00
#include "RetroTypes.hpp"
2018-12-08 05:30:43 +00:00
namespace urde {
2015-08-21 00:06:39 +00:00
2018-12-08 05:30:43 +00:00
class IObj {
2015-08-23 06:42:29 +00:00
public:
2018-12-08 05:30:43 +00:00
virtual ~IObj() = default;
2015-08-21 00:06:39 +00:00
};
2018-12-08 05:30:43 +00:00
class TObjOwnerDerivedFromIObjUntyped : public IObj {
2015-08-22 02:59:57 +00:00
protected:
2018-12-08 05:30:43 +00:00
void* m_objPtr;
2018-01-14 06:44:22 +00:00
public:
2018-12-08 05:30:43 +00:00
TObjOwnerDerivedFromIObjUntyped(void* objPtr) : m_objPtr(objPtr) {}
2015-08-22 02:59:57 +00:00
};
2018-12-08 05:30:43 +00:00
template <class T>
class TObjOwnerDerivedFromIObj : public TObjOwnerDerivedFromIObjUntyped {
TObjOwnerDerivedFromIObj(T* objPtr) : TObjOwnerDerivedFromIObjUntyped(objPtr) {}
2015-08-22 02:59:57 +00:00
public:
2018-12-08 05:30:43 +00:00
static std::unique_ptr<TObjOwnerDerivedFromIObj<T>> GetNewDerivedObject(std::unique_ptr<T>&& obj) {
return std::unique_ptr<TObjOwnerDerivedFromIObj<T>>(new TObjOwnerDerivedFromIObj<T>(obj.release()));
}
~TObjOwnerDerivedFromIObj() override { std::default_delete<T>()(static_cast<T*>(m_objPtr)); }
2018-12-08 05:30:43 +00:00
T* GetObj() { return static_cast<T*>(m_objPtr); }
2015-08-22 02:59:57 +00:00
};
2018-12-08 05:30:43 +00:00
} // namespace urde