1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-07 01:29:15 +01:00
dxvk/src/util/com/com_object.h

43 lines
838 B
C
Raw Normal View History

2017-10-11 00:41:56 +02:00
#pragma once
#include <atomic>
#include "com_include.h"
#define COM_QUERY_IFACE(riid, ppvObject, Iface) \
2017-10-11 15:31:36 +02:00
do { \
if (riid == __uuidof(Iface)) { \
this->AddRef(); \
*ppvObject = static_cast<Iface*>(this); \
return S_OK; \
} \
} while (0)
2017-10-11 00:41:56 +02:00
namespace dxvk {
template<typename... Base>
class ComObject : public Base... {
public:
virtual ~ComObject() { }
ULONG AddRef() {
2017-10-11 00:41:56 +02:00
return ++m_refCount;
}
ULONG Release() {
2017-10-11 00:41:56 +02:00
ULONG refCount = --m_refCount;
if (refCount == 0)
delete this;
return refCount;
}
private:
std::atomic<ULONG> m_refCount = { 0ul };
};
}