From e6725d6b0fc1a00fbcf35c1dda2c670f349f6a36 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 14 Jan 2023 22:50:09 +0100 Subject: [PATCH] Add reset() to wx_ptr and allow it to be null. --- src/wx/wx_ptr.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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; }; -- 2.30.2