libobs: Update to latest version of ComPtr.hpp

This commit is contained in:
jp9000
2015-02-08 15:41:47 -08:00
parent 5dfecab15c
commit 0c30dca526

View File

@@ -19,7 +19,9 @@
/* Oh no I have my own com pointer class, the world is ending, how dare you
* write your own! */
template<typename T> class ComPtr {
template<class T> class ComPtr {
protected:
T *ptr;
inline void Kill()
@@ -38,11 +40,11 @@ template<typename T> class ComPtr {
}
public:
inline ComPtr() : ptr(NULL) {}
inline ComPtr(T *p) : ptr(p) {if (ptr) ptr->AddRef();}
inline ComPtr(const ComPtr &c) : ptr(c.ptr) {if (ptr) ptr->AddRef();}
inline ComPtr(ComPtr &&c) : ptr(c.ptr) {c.ptr = NULL;}
inline ~ComPtr() {Kill();}
inline ComPtr() : ptr(NULL) {}
inline ComPtr(T *p) : ptr(p) {if (ptr) ptr->AddRef();}
inline ComPtr(const ComPtr<T> &c) : ptr(c.ptr) {if (ptr) ptr->AddRef();}
inline ComPtr(ComPtr<T> &&c) : ptr(c.ptr) {c.ptr = NULL;}
inline ~ComPtr() {Kill();}
inline void Clear()
{
@@ -52,19 +54,19 @@ public:
}
}
inline ComPtr &operator=(T *p)
inline ComPtr<T> &operator=(T *p)
{
Replace(p);
return *this;
}
inline ComPtr &operator=(const ComPtr &c)
inline ComPtr<T> &operator=(const ComPtr<T> &c)
{
Replace(c.ptr);
return *this;
}
inline ComPtr &operator=(ComPtr &&c)
inline ComPtr<T> &operator=(ComPtr<T> &&c)
{
if (this != &c) {
Kill();
@@ -75,13 +77,37 @@ public:
return *this;
}
inline T *Detach()
{
T *out = ptr;
ptr = nullptr;
return out;
}
inline void CopyTo(T **out)
{
if (out) {
if (ptr) ptr->AddRef();
*out = ptr;
}
}
inline ULONG Release()
{
ULONG ref;
if (!ptr) return 0;
ref = ptr->Release();
ptr = nullptr;
return ref;
}
inline T **Assign() {Clear(); return &ptr;}
inline void Set(T *p) {Kill(); ptr = p;}
inline T *Get() const {return ptr;}
/* nabbed this one from virtualdub */
inline T **operator~() {return Assign();}
inline T **operator&() {return Assign();}
inline operator T*() const {return ptr;}
inline T *operator->() const {return ptr;}
@@ -91,3 +117,20 @@ public:
inline bool operator!() const {return !ptr;}
};
template<class T> class ComQIPtr : public ComPtr<T> {
public:
inline ComQIPtr(IUnknown *unk)
{
this->ptr = nullptr;
unk->QueryInterface(__uuidof(T), (void**)&this->ptr);
}
inline ComPtr<T> &operator=(IUnknown *unk)
{
ComPtr<T>::Clear();
unk->QueryInterface(__uuidof(T), (void**)&this->ptr);
return *this;
}
};