#define DCPOMATIC_WX_PTR_H
+#include "lib/dcpomatic_assert.h"
#include <utility>
class wx_ptr
{
public:
+ wx_ptr() {}
+
explicit wx_ptr(T* wx)
: _wx(wx)
{}
}
}
- 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 <typename... Args>
+ void reset(Args&&... args)
+ {
+ if (_wx) {
+ _wx->Destroy();
+ _wx = nullptr;
+ }
+ _wx = new T(std::forward<Args>(args)...);
+ }
+
private:
- T* _wx;
+ T* _wx = nullptr;
};