From 20b9f2b42a3b58b6081af271774fbcc34025dccb Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 25 Jul 2021 19:11:59 +0200 Subject: NOISSUE Flatten gui and logic libraries into MultiMC --- api/logic/QObjectPtr.h | 83 -------------------------------------------------- 1 file changed, 83 deletions(-) delete mode 100644 api/logic/QObjectPtr.h (limited to 'api/logic/QObjectPtr.h') diff --git a/api/logic/QObjectPtr.h b/api/logic/QObjectPtr.h deleted file mode 100644 index 0ff51136..00000000 --- a/api/logic/QObjectPtr.h +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace details -{ -struct DeleteQObjectLater -{ - void operator()(QObject *obj) const - { - obj->deleteLater(); - } -}; -} -/** - * A unique pointer class with unique pointer semantics intended for derivates of QObject - * Calls deleteLater() instead of destroying the contained object immediately - */ -template using unique_qobject_ptr = std::unique_ptr; - -/** - * A shared pointer class with shared pointer semantics intended for derivates of QObject - * Calls deleteLater() instead of destroying the contained object immediately - */ -template -class shared_qobject_ptr -{ -public: - shared_qobject_ptr(){} - shared_qobject_ptr(T * wrap) - { - reset(wrap); - } - shared_qobject_ptr(const shared_qobject_ptr& other) - { - m_ptr = other.m_ptr; - } - template - shared_qobject_ptr(const shared_qobject_ptr &other) - { - m_ptr = other.unwrap(); - } - -public: - void reset(T * wrap) - { - using namespace std::placeholders; - m_ptr.reset(wrap, std::bind(&QObject::deleteLater, _1)); - } - void reset(const shared_qobject_ptr &other) - { - m_ptr = other.m_ptr; - } - void reset() - { - m_ptr.reset(); - } - T * get() const - { - return m_ptr.get(); - } - T * operator->() const - { - return m_ptr.get(); - } - T & operator*() const - { - return *m_ptr.get(); - } - operator bool() const - { - return m_ptr.get() != nullptr; - } - const std::shared_ptr unwrap() const - { - return m_ptr; - } - -private: - std::shared_ptr m_ptr; -}; -- cgit