X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fwx_ptr.h;h=fcca8b18bafb602744c9befb8ab5971bace1a7a7;hb=5ee919f413a6c1048aecf83676d42ab3fd94e06e;hp=96459183ee070832a3e887e53d9def687f490399;hpb=e6c2c489924fbe2f8db70030f1774541a819d46c;p=dcpomatic.git diff --git a/src/wx/wx_ptr.h b/src/wx/wx_ptr.h index 96459183e..fcca8b18b 100644 --- a/src/wx/wx_ptr.h +++ b/src/wx/wx_ptr.h @@ -62,16 +62,40 @@ public: } } - T* operator->() { + wx_ptr& operator=(T* ptr) + { + if (_wx) { + _wx->Destroy(); + } + _wx = ptr; + return *this; + } + + T* operator->() + { DCPOMATIC_ASSERT(_wx); return _wx; } + operator bool() const + { + return _wx != nullptr; + } + + void reset() + { + if (_wx) { + _wx->Destroy(); + _wx = nullptr; + } + } + template void reset(Args&&... args) { if (_wx) { _wx->Destroy(); + _wx = nullptr; } _wx = new T(std::forward(args)...); }