1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-02 19:24:12 +01:00

[util] Add support for private references in Com<...> wrapper

This commit is contained in:
Philip Rebohle 2019-05-14 14:52:22 +02:00
parent 54d3103b04
commit 61b97e5dd1
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99

View File

@ -4,13 +4,28 @@
namespace dxvk { namespace dxvk {
/**
* \brief Increment public ref count
*
* If the pointer is not \c nullptr, this
* calls \c AddRef for the given object.
* \returns Pointer to the object
*/
template<typename T>
T* ref(T* object) {
if (object != nullptr)
object->AddRef();
return object;
}
/** /**
* \brief COM pointer * \brief COM pointer
* *
* Implements automatic reference * Implements automatic reference
* counting for COM objects. * counting for COM objects.
*/ */
template<typename T> template<typename T, bool Public = true>
class Com { class Com {
public: public:
@ -80,8 +95,7 @@ namespace dxvk {
bool operator != (std::nullptr_t) const { return m_ptr != nullptr; } bool operator != (std::nullptr_t) const { return m_ptr != nullptr; }
T* ref() const { T* ref() const {
this->incRef(); return dxvk::ref(m_ptr);
return m_ptr;
} }
T* ptr() const { T* ptr() const {
@ -93,22 +107,23 @@ namespace dxvk {
T* m_ptr = nullptr; T* m_ptr = nullptr;
void incRef() const { void incRef() const {
if (m_ptr != nullptr) if (m_ptr != nullptr) {
if constexpr (Public)
m_ptr->AddRef(); m_ptr->AddRef();
else
m_ptr->AddRefPrivate();
}
} }
void decRef() const { void decRef() const {
if (m_ptr != nullptr) if (m_ptr != nullptr) {
if constexpr (Public)
m_ptr->Release(); m_ptr->Release();
else
m_ptr->ReleasePrivate();
}
} }
}; };
template<typename T>
T* ref(T* object) {
if (object != nullptr)
object->AddRef();
return object;
}
} }