2022-08-13 01:26:00 +00:00
|
|
|
#ifndef _IOBJ_HPP
|
|
|
|
#define _IOBJ_HPP
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
#include "rstl/auto_ptr.hpp"
|
|
|
|
|
|
|
|
class IObj {
|
|
|
|
public:
|
|
|
|
virtual ~IObj() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CObjOwnerDerivedFromIObjUntyped : public IObj {
|
|
|
|
public:
|
|
|
|
template < typename T >
|
|
|
|
CObjOwnerDerivedFromIObjUntyped(T* obj) : m_objPtr(obj) {}
|
|
|
|
template < typename T >
|
|
|
|
CObjOwnerDerivedFromIObjUntyped(const rstl::auto_ptr< T >& obj) : m_objPtr(obj.release()) {}
|
|
|
|
|
2022-09-13 04:26:54 +00:00
|
|
|
void* GetContents() { return m_objPtr; }
|
|
|
|
|
2022-08-13 01:26:00 +00:00
|
|
|
protected:
|
|
|
|
void* m_objPtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
class TObjOwnerDerivedFromIObj : public CObjOwnerDerivedFromIObjUntyped {
|
|
|
|
public:
|
|
|
|
~TObjOwnerDerivedFromIObj() override { delete Owned(); }
|
|
|
|
T* Owned() { return static_cast< T* >(m_objPtr); }
|
2022-09-13 04:26:54 +00:00
|
|
|
|
|
|
|
static inline rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > > GetNewDerivedObject(T* obj) {
|
|
|
|
return new TObjOwnerDerivedFromIObj< T >(obj);
|
|
|
|
}
|
|
|
|
static inline rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > > GetNewDerivedObject(const rstl::auto_ptr< T >& obj) {
|
|
|
|
return new TObjOwnerDerivedFromIObj< T >(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TObjOwnerDerivedFromIObj(T* obj) : CObjOwnerDerivedFromIObjUntyped(obj) {}
|
|
|
|
TObjOwnerDerivedFromIObj(const rstl::auto_ptr< T >& obj) : CObjOwnerDerivedFromIObjUntyped(obj) {}
|
2022-08-13 01:26:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|