diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-01-14 22:50:09 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-01-14 22:50:09 +0100 |
| commit | e6725d6b0fc1a00fbcf35c1dda2c670f349f6a36 (patch) | |
| tree | b673c6b40a364fffbc78960f6ecadfa62f8da07d /src/wx | |
| parent | 018a48ef7eab75b0c7f703bee0ecd28e306698dd (diff) | |
Add reset() to wx_ptr and allow it to be null.
Diffstat (limited to 'src/wx')
| -rw-r--r-- | src/wx/wx_ptr.h | 15 |
1 files changed, 14 insertions, 1 deletions
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 <utility> @@ -30,6 +31,8 @@ template <class T> 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 <typename... Args> + void reset(Args... args) + { + if (_wx) { + _wx->Destroy(); + } + _wx = new T(std::forward<Args>(args)...); + } + private: - T* _wx; + T* _wx = nullptr; }; |
