diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-01-11 22:04:31 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-01-11 22:04:31 +0100 |
commit | 0886786bb56e1ebfb53716127fd3ff0366e9a9f3 (patch) | |
tree | 4c65561d1e3b394a834e69a77df1243bd2d2c5f1 /logic/QObjectPtr.h | |
parent | 1151037f968628cd659f06457f9ca7403f77f071 (diff) | |
download | MultiMC-0886786bb56e1ebfb53716127fd3ff0366e9a9f3.tar MultiMC-0886786bb56e1ebfb53716127fd3ff0366e9a9f3.tar.gz MultiMC-0886786bb56e1ebfb53716127fd3ff0366e9a9f3.tar.lz MultiMC-0886786bb56e1ebfb53716127fd3ff0366e9a9f3.tar.xz MultiMC-0886786bb56e1ebfb53716127fd3ff0366e9a9f3.zip |
GH-721 Redo internal NetJob implementation.
NetJob is now using its own task queue and does not start more than 6 actions at the same time
Diffstat (limited to 'logic/QObjectPtr.h')
-rw-r--r-- | logic/QObjectPtr.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/logic/QObjectPtr.h b/logic/QObjectPtr.h new file mode 100644 index 00000000..74c6e82a --- /dev/null +++ b/logic/QObjectPtr.h @@ -0,0 +1,52 @@ +#pragma once + +#include <memory> + +/** + * A pointer class with the usual shared pointer semantics intended for derivates of QObject + * Calls deleteLater() instead of destroying the contained object immediately + */ +template <typename T> +class QObjectPtr +{ +public: + QObjectPtr(){} + QObjectPtr(T * wrap) + { + reset(wrap); + } + QObjectPtr(const QObjectPtr<T>& other) + { + m_ptr = other.m_ptr; + } + +public: + void reset(T * wrap) + { + using namespace std::placeholders; + m_ptr.reset(wrap, std::bind(&QObject::deleteLater, _1)); + } + 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; + } + +private: + std::shared_ptr <T> m_ptr; +}; |