From: Carl Hetherington Date: Sat, 14 Jan 2023 21:50:09 +0000 (+0100) Subject: Add reset() to wx_ptr and allow it to be null. X-Git-Tag: v2.16.41~53 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=e6725d6b0fc1a00fbcf35c1dda2c670f349f6a36 Add reset() to wx_ptr and allow it to be null. --- diff --git a/src/wx/wx_ptr.h b/src/wx/wx_ptr.h index de18846cc..7eff673a4 100644 --- a/src/wx/wx_ptr.h +++ b/src/wx/wx_ptr.h @@ -23,6 +23,7 @@ #define DCPOMATIC_WX_PTR_H +#include "lib/dcpomatic_assert.h" #include @@ -30,6 +31,8 @@ template class wx_ptr { public: + wx_ptr() {} + explicit wx_ptr(T* wx) : _wx(wx) {} @@ -60,11 +63,21 @@ public: } T* operator->() { + DCPOMATIC_ASSERT(_wx); return _wx; } + template + void reset(Args... args) + { + if (_wx) { + _wx->Destroy(); + } + _wx = new T(std::forward(args)...); + } + private: - T* _wx; + T* _wx = nullptr; };