Minor IObj additions

This commit is contained in:
Jack Andersen 2015-08-21 16:59:57 -10:00
parent b51911ed3d
commit 4a424aa2b3
2 changed files with 32 additions and 0 deletions

View File

@ -10,6 +10,37 @@ class IObj
{ {
}; };
class TObjOwnerDerivedFromIObjUntyped : public IObj
{
protected:
void* m_objPtr;
TObjOwnerDerivedFromIObjUntyped(void* objPtr) : m_objPtr(objPtr) {}
};
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)
{
std::unique_ptr<T> movedObjPtr = std::move(obj);
return std::unique_ptr<TObjOwnerDerivedFromIObj<T>>
(new TObjOwnerDerivedFromIObj<T>(movedObjPtr.release()));
}
~TObjOwnerDerivedFromIObj() {delete static_cast<T*>(m_objPtr);}
};
template<class T>
class TToken
{
public:
static std::unique_ptr<TObjOwnerDerivedFromIObj<T>> GetIObjObjectFor(std::unique_ptr<T>&& obj)
{
return TObjOwnerDerivedFromIObj<T>::GetNewDerivedObject(std::move(obj));
}
};
} }
#endif // __RETRO_IOBJ_HPP__ #endif // __RETRO_IOBJ_HPP__

View File

@ -1,6 +1,7 @@
#ifndef __RETRO_IVPARAMOBJ_HPP__ #ifndef __RETRO_IVPARAMOBJ_HPP__
#define __RETRO_IVPARAMOBJ_HPP__ #define __RETRO_IVPARAMOBJ_HPP__
#include <memory>
#include "IObj.hpp" #include "IObj.hpp"
namespace Retro namespace Retro