[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [krita/rempt/impex-refactoring] libs/global: Add toStrongRef to KisWeakPtr
From: Frederik Gladhorn <gladhorn () kde ! org>
Date: 2016-11-07 23:45:46
Message-ID: E1c3tbm-0000Dl-Iy () code ! kde ! org
[Download RAW message or body]
Git commit fddc7d90787827d73f6dee9c3b757c090e289d8f by Frederik Gladhorn.
Committed on 07/11/2016 at 22:28.
Pushed by gladhorn into branch 'rempt/impex-refactoring'.
Add toStrongRef to KisWeakPtr
Weak pointers don't hold a strong reference, they may
become nullptr at any time. To use them safely, they always have bo be
converted to a strong reference. Further commits can then slowly move
over to users of weak pointers to first convert them to strong pointers
and introduce a check for nullptr at the same time.
M +13 -0 libs/global/kis_shared_ptr.h
http://commits.kde.org/krita/fddc7d90787827d73f6dee9c3b757c090e289d8f
diff --git a/libs/global/kis_shared_ptr.h b/libs/global/kis_shared_ptr.h
index 4b35c48..5453bfa 100644
--- a/libs/global/kis_shared_ptr.h
+++ b/libs/global/kis_shared_ptr.h
@@ -408,6 +408,19 @@ public:
return d && weakReference && isOdd((int)*weakReference);
}
+
+ /**
+ * @brief toStrongRef returns a KisSharedPtr which may be dereferenced.
+ *
+ * Weak pointers should only be used to track ownership but never be used as pointers.
+ * This has historically not been the case, but in new API this function should be used
+ * instead of directly using a weak pointer as pointer.
+ * @return a KisSharedPtr, which may be null
+ */
+ inline KisSharedPtr<T> toStrongRef() const {
+ return KisSharedPtr<T>(*this);
+ }
+
private:
static const qint32 WEAK_REF = 2;
static inline bool isOdd(const qint32 &x) {
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic