From 1d57db6836fd577e66bafc84095d672d288e4552 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 8 Mar 2021 22:47:50 -0800 Subject: Move the ComPtr wrapper to a common header --- alc/backends/dsound.cpp | 64 +------------------------------------------------ 1 file changed, 1 insertion(+), 63 deletions(-) (limited to 'alc/backends/dsound.cpp') diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index 34fe25f4..72f9c47a 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -47,6 +47,7 @@ #include "alcmain.h" #include "alu.h" #include "compat.h" +#include "comptr.h" #include "core/logging.h" #include "dynload.h" #include "ringbuffer.h" @@ -107,69 +108,6 @@ HRESULT (WINAPI *pDirectSoundCaptureEnumerateW)(LPDSENUMCALLBACKW pDSEnumCallbac #endif -template -class ComPtr { - T *mPtr{nullptr}; - -public: - ComPtr() noexcept = default; - ComPtr(const ComPtr &rhs) : mPtr{rhs.mPtr} { if(mPtr) mPtr->AddRef(); } - ComPtr(ComPtr&& rhs) noexcept : mPtr{rhs.mPtr} { rhs.mPtr = nullptr; } - ComPtr(std::nullptr_t) noexcept { } - explicit ComPtr(T *ptr) noexcept : mPtr{ptr} { } - ~ComPtr() { if(mPtr) mPtr->Release(); } - - ComPtr& operator=(const ComPtr &rhs) - { - if(!rhs.mPtr) - { - if(mPtr) - mPtr->Release(); - mPtr = nullptr; - } - else - { - rhs.mPtr->AddRef(); - try { - if(mPtr) - mPtr->Release(); - mPtr = rhs.mPtr; - } - catch(...) { - rhs.mPtr->Release(); - throw; - } - } - return *this; - } - ComPtr& operator=(ComPtr&& rhs) - { - if(mPtr) - mPtr->Release(); - mPtr = rhs.mPtr; - rhs.mPtr = nullptr; - return *this; - } - - operator bool() const noexcept { return mPtr != nullptr; } - - T& operator*() const noexcept { return *mPtr; } - T* operator->() const noexcept { return mPtr; } - T* get() const noexcept { return mPtr; } - T** getPtr() noexcept { return &mPtr; } - - T* release() noexcept - { - T *ret{mPtr}; - mPtr = nullptr; - return ret; - } - - void swap(ComPtr &rhs) noexcept { std::swap(mPtr, rhs.mPtr); } - void swap(ComPtr&& rhs) noexcept { std::swap(mPtr, rhs.mPtr); } -}; - - #define MONO SPEAKER_FRONT_CENTER #define STEREO (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT) #define QUAD (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT) -- cgit v1.2.3