aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/ui/DeleteLater.h47
-rw-r--r--src/theme_builder/components/conditions/CompoundConditionEditor.h2
-rw-r--r--src/theme_builder/components/stylers/CompoundStylerEditor.h3
3 files changed, 44 insertions, 8 deletions
diff --git a/include/cru/ui/DeleteLater.h b/include/cru/ui/DeleteLater.h
index 5c098b4a..0f04c73a 100644
--- a/include/cru/ui/DeleteLater.h
+++ b/include/cru/ui/DeleteLater.h
@@ -1,5 +1,4 @@
#pragma once
-
#include "Base.h"
#include <memory>
@@ -16,12 +15,48 @@ class CRU_UI_API DeleteLaterImpl {
};
template <typename T>
-struct DeleteLaterDeleter {
- void operator()(T* p) const { p->DeleteLater(); }
-};
+class DeleteLaterPtr {
+ public:
+ DeleteLaterPtr() = default;
-template <typename T>
-using DeleteLaterPtr = std::unique_ptr<T, DeleteLaterDeleter<T>>;
+ DeleteLaterPtr(const DeleteLaterPtr& other) = delete;
+ DeleteLaterPtr& operator=(const DeleteLaterPtr& other) = delete;
+
+ DeleteLaterPtr(DeleteLaterPtr&& other) noexcept : ptr_(other.ptr_) {
+ other.ptr_ = nullptr;
+ }
+
+ DeleteLaterPtr& operator=(DeleteLaterPtr&& other) noexcept {
+ if (this != &other) {
+ if (ptr_ != nullptr) {
+ ptr_->DeleteLater();
+ }
+
+ ptr_ = other.ptr_;
+ other.ptr_ = nullptr;
+ }
+ return *this;
+ }
+
+ ~DeleteLaterPtr() {
+ if (ptr_ != nullptr) {
+ ptr_->DeleteLater();
+ }
+ }
+
+ explicit DeleteLaterPtr(T* ptr) : ptr_(ptr) {}
+ DeleteLaterPtr(std::unique_ptr<T>&& ptr) : ptr_(ptr.release()) {}
+
+ T& operator*() const { return *ptr_; }
+ T* operator->() const { return ptr_; }
+
+ explicit operator bool() const { return ptr_ != nullptr; }
+
+ T* get() const { return ptr_; }
+
+ private:
+ T* ptr_ = nullptr;
+};
template <typename T, typename... Args>
DeleteLaterPtr<T> MakeDeleteLaterPtr(Args&&... args) {
diff --git a/src/theme_builder/components/conditions/CompoundConditionEditor.h b/src/theme_builder/components/conditions/CompoundConditionEditor.h
index 9732d533..e1398514 100644
--- a/src/theme_builder/components/conditions/CompoundConditionEditor.h
+++ b/src/theme_builder/components/conditions/CompoundConditionEditor.h
@@ -23,7 +23,7 @@ class CompoundConditionEditor : public ConditionEditor {
private:
ui::components::PopupMenuIconButton add_child_button_;
ui::controls::FlexLayout children_container_;
- std::vector<std::unique_ptr<ConditionEditor>> children_;
+ std::vector<ui::DeleteLaterPtr<ConditionEditor>> children_;
};
class AndConditionEditor : public CompoundConditionEditor {
diff --git a/src/theme_builder/components/stylers/CompoundStylerEditor.h b/src/theme_builder/components/stylers/CompoundStylerEditor.h
index a056e45c..57150e83 100644
--- a/src/theme_builder/components/stylers/CompoundStylerEditor.h
+++ b/src/theme_builder/components/stylers/CompoundStylerEditor.h
@@ -1,6 +1,7 @@
#pragma once
#include "StylerEditor.h"
#include "cru/common/ClonablePtr.h"
+#include "cru/ui/DeleteLater.h"
#include "cru/ui/components/PopupButton.h"
#include "cru/ui/controls/FlexLayout.h"
#include "cru/ui/style/Styler.h"
@@ -23,7 +24,7 @@ class CompoundStylerEditor : public StylerEditor {
private:
ui::controls::FlexLayout children_container_;
- std::vector<std::unique_ptr<StylerEditor>> children_;
+ std::vector<ui::DeleteLaterPtr<StylerEditor>> children_;
ui::components::PopupMenuIconButton add_child_button_;
};
} // namespace cru::theme_builder::components::stylers