mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
55 lines
645 B
C++
55 lines
645 B
C++
#pragma once
|
|
|
|
#include "Common/CompatVtable.h"
|
|
|
|
template <typename Intf>
|
|
class CompatWeakPtr
|
|
{
|
|
public:
|
|
CompatWeakPtr(Intf* intf = nullptr) : m_intf(intf)
|
|
{
|
|
}
|
|
|
|
Intf& operator*() const
|
|
{
|
|
return *m_intf;
|
|
}
|
|
|
|
const Vtable<Intf>* operator->() const
|
|
{
|
|
return &CompatVtable<Vtable<Intf>>::getOrigVtable(*m_intf->lpVtbl);
|
|
}
|
|
|
|
operator Intf*() const
|
|
{
|
|
return m_intf;
|
|
}
|
|
|
|
Intf* get() const
|
|
{
|
|
return m_intf;
|
|
}
|
|
|
|
Intf* const& getRef() const
|
|
{
|
|
return m_intf;
|
|
}
|
|
|
|
Intf*& getRef()
|
|
{
|
|
return m_intf;
|
|
}
|
|
|
|
void release()
|
|
{
|
|
if (m_intf)
|
|
{
|
|
m_intf->lpVtbl->Release(m_intf);
|
|
m_intf = nullptr;
|
|
}
|
|
}
|
|
|
|
protected:
|
|
Intf* m_intf;
|
|
};
|