1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-30 13:24:10 +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 {
/**
* \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
*
* Implements automatic reference
* counting for COM objects.
*/
template<typename T>
template<typename T, bool Public = true>
class Com {
public:
@ -80,8 +95,7 @@ namespace dxvk {
bool operator != (std::nullptr_t) const { return m_ptr != nullptr; }
T* ref() const {
this->incRef();
return m_ptr;
return dxvk::ref(m_ptr);
}
T* ptr() const {
@ -93,22 +107,23 @@ namespace dxvk {
T* m_ptr = nullptr;
void incRef() const {
if (m_ptr != nullptr)
m_ptr->AddRef();
if (m_ptr != nullptr) {
if constexpr (Public)
m_ptr->AddRef();
else
m_ptr->AddRefPrivate();
}
}
void decRef() const {
if (m_ptr != nullptr)
m_ptr->Release();
if (m_ptr != nullptr) {
if constexpr (Public)
m_ptr->Release();
else
m_ptr->ReleasePrivate();
}
}
};
template<typename T>
T* ref(T* object) {
if (object != nullptr)
object->AddRef();
return object;
}
}