aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/gui/DeleteLater.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/platform/gui/DeleteLater.h')
-rw-r--r--include/cru/platform/gui/DeleteLater.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/include/cru/platform/gui/DeleteLater.h b/include/cru/platform/gui/DeleteLater.h
new file mode 100644
index 00000000..c0578974
--- /dev/null
+++ b/include/cru/platform/gui/DeleteLater.h
@@ -0,0 +1,41 @@
+#pragma once
+#include "UiApplication.h"
+
+#include <cru/base/Guard.h>
+#include <memory>
+#include <utility>
+
+namespace cru::platform::gui {
+template <typename TSelf>
+class DeleteLaterImpl {
+ CRU_DEFINE_CLASS_LOG_TAG("cru::platform::gui::DeleteLaterImpl")
+
+ public:
+ virtual ~DeleteLaterImpl() {}
+
+ void DeleteLater() {
+ IUiApplication::GetInstance()->DeleteLater(static_cast<TSelf*>(this));
+ }
+};
+
+namespace details {
+template <typename T>
+struct DeleteLaterPtrDeleter {
+ void operator()(T* p) const noexcept { p->DeleteLater(); }
+};
+} // namespace details
+
+template <typename T>
+using DeleteLaterPtr = std::unique_ptr<T, details::DeleteLaterPtrDeleter<T>>;
+
+template <typename T>
+DeleteLaterPtr<T> ToDeleteLaterPtr(std::unique_ptr<T>&& p) {
+ return DeleteLaterPtr<T>(p.release());
+}
+
+template <typename T, typename... Args>
+DeleteLaterPtr<T> MakeDeleteLater(Args&&... args) {
+ return DeleteLaterPtr<T>(new T(std::forward<Args>(args)...));
+}
+
+} // namespace cru::platform::gui