2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _IOBJ
|
|
|
|
#define _IOBJ
|
2022-08-13 01:26:00 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
2022-10-06 09:23:45 +00:00
|
|
|
#include "Kyoto/SObjectTag.hpp"
|
2022-08-13 01:26:00 +00:00
|
|
|
#include "rstl/auto_ptr.hpp"
|
|
|
|
|
2022-10-06 09:23:45 +00:00
|
|
|
extern const SObjectTag gkInvalidObjectTag;
|
|
|
|
|
2022-08-13 01:26:00 +00:00
|
|
|
class IObj {
|
|
|
|
public:
|
|
|
|
virtual ~IObj() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CObjOwnerDerivedFromIObjUntyped : public IObj {
|
|
|
|
public:
|
2023-01-14 07:55:03 +00:00
|
|
|
~CObjOwnerDerivedFromIObjUntyped() {}
|
2022-08-13 01:26:00 +00:00
|
|
|
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:
|
2023-01-14 07:55:03 +00:00
|
|
|
~TObjOwnerDerivedFromIObj() {
|
|
|
|
if (Owned()) {
|
|
|
|
delete Owned();
|
|
|
|
}
|
|
|
|
}
|
2022-08-13 01:26:00 +00:00
|
|
|
T* Owned() { return static_cast< T* >(m_objPtr); }
|
2022-09-13 04:26:54 +00:00
|
|
|
|
2023-01-14 07:55:03 +00:00
|
|
|
static rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > > GetNewDerivedObject(T* obj) {
|
2023-10-12 12:14:12 +00:00
|
|
|
return rs_new TObjOwnerDerivedFromIObj< T >(obj);
|
2022-09-13 04:26:54 +00:00
|
|
|
}
|
2023-01-14 07:55:03 +00:00
|
|
|
static rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > >
|
2022-09-18 06:05:46 +00:00
|
|
|
GetNewDerivedObject(const rstl::auto_ptr< T >& obj) {
|
2023-10-12 12:14:12 +00:00
|
|
|
return rs_new TObjOwnerDerivedFromIObj< T >(obj);
|
2022-09-13 04:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TObjOwnerDerivedFromIObj(T* obj) : CObjOwnerDerivedFromIObjUntyped(obj) {}
|
|
|
|
TObjOwnerDerivedFromIObj(const rstl::auto_ptr< T >& obj) : CObjOwnerDerivedFromIObjUntyped(obj) {}
|
2022-08-13 01:26:00 +00:00
|
|
|
};
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _IOBJ
|