|
Krita Source Code Documentation
|
#include <kis_shared_ptr.h>
Inheritance diagram for KisSharedPtr< T >:Public Types | |
| using | element_type = T |
| using | weak_type = KisWeakSharedPtr<T> |
Public Member Functions | |
| void | attach (T *p) |
| void | clear () |
| const T * | constData () const |
| T * | data () |
| const T * | data () const |
| bool | isNull () const |
| KisSharedPtr () | |
| KisSharedPtr (const KisSharedPtr< T > &o) | |
| KisSharedPtr (const KisWeakSharedPtr< T > &o) | |
| KisSharedPtr (T *p) | |
| operator const T * () const | |
| template<class T2 > | |
| operator KisSharedPtr< T2 > () const | |
| bool | operator!= (const KisSharedPtr &o) const |
| bool | operator!= (const T *p) const |
| T & | operator* () |
| const T & | operator* () const |
| T * | operator-> () |
| const T * | operator-> () const |
| KisSharedPtr & | operator= (const KisSharedPtr &o) |
| KisSharedPtr< T > & | operator= (T *p) |
| bool | operator== (const KisSharedPtr &o) const |
| bool | operator== (const T *p) const |
| ~KisSharedPtr () | |
Static Public Member Functions | |
| static bool | deref (const KisSharedPtr< T > *sp, T *t) |
| static void | ref (const KisSharedPtr< T > *sp, T *t) |
Private Member Functions | |
| void | deref () const |
| void | ref () const |
Private Attributes | |
| T * | d |
Friends | |
| class | KisWeakSharedPtr< T > |
KisSharedPtr is a shared pointer similar to KSharedPtr and boost::shared_ptr. The difference with KSharedPtr is that our constructor is not explicit.
A shared pointer is a wrapper around a real pointer. The shared pointer keeps a reference count, and when the reference count drops to 0 the contained pointer is deleted. You can use the shared pointer just as you would use a real pointer.
See also item 28 and 29 of More Effective C++ and https://bugs.kde.org/show_bug.cgi?id=52261 as well as https://www.boost.org/libs/smart_ptr/shared_ptr.htm.
Advantage of KisSharedPtr over boost pointer or QSharedPointer?
The difference with boost share pointer is that in boost::shared_ptr, the counter is kept inside the smart pointer, meaning that you should never never remove the pointer from its smart pointer object, because if you do that, and somewhere in the code, the pointer is put back in a smart pointer, then you have two counters, and when one reach zero, then the object gets deleted while some other code thinks the pointer is still valid.
Disadvantage of KisSharedPtr compared to boost pointer?
KisSharedPtr requires the class to inherits KisShared.
Difference with QSharedPointer
QSharedPointer and KisSharedPtr are very similar, but QSharedPointer has an explicit constructor which makes it more painful to use in some constructions. And QSharedPointer doesn't offer a weak pointer.
Definition at line 56 of file kis_shared_ptr.h.
| using KisSharedPtr< T >::element_type = T |
Definition at line 60 of file kis_shared_ptr.h.
| using KisSharedPtr< T >::weak_type = KisWeakSharedPtr<T> |
Definition at line 61 of file kis_shared_ptr.h.
|
inline |
|
inline |
Creates a new pointer.
| p | the pointer |
Definition at line 73 of file kis_shared_ptr.h.
References KisSharedPtr< T >::ref().
|
inline |
Thread safety: Is the object we have just referenced still valid?
Definition at line 484 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d, and KisSharedPtr< T >::ref().
|
inline |
Copies a pointer.
| o | the pointer to copy |
Definition at line 90 of file kis_shared_ptr.h.
References KisSharedPtr< T >::ref().
|
inline |
Dereferences the object that this pointer points to. If it was the last reference, the object will be deleted.
Definition at line 99 of file kis_shared_ptr.h.
References KisSharedPtr< T >::deref().
| Q_INLINE_TEMPLATE void KisSharedPtr< T >::attach | ( | T * | p | ) |
Definition at line 503 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d, KisSharedPtr< T >::deref(), p, and KisSharedPtr< T >::ref().
| Q_INLINE_TEMPLATE void KisSharedPtr< T >::clear | ( | ) |
Definition at line 514 of file kis_shared_ptr.h.
References KisSharedPtr< T >::attach().
|
inline |
Definition at line 153 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d.
|
inline |
Definition at line 139 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d.
|
inline |
Definition at line 146 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d.
|
inlineprivate |
Definition at line 214 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d, KisSharedPtr< T >::deref(), and v.
|
inlinestatic |
Definition at line 194 of file kis_shared_ptr.h.
References KisMemoryLeakTracker::dereference(), and KisMemoryLeakTracker::instance().
|
inline |
Definition at line 178 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d.
|
inline |
Definition at line 125 of file kis_shared_ptr.h.
|
inline |
Definition at line 129 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d.
|
inline |
Definition at line 116 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d.
|
inline |
Definition at line 110 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d, and p.
|
inline |
Definition at line 161 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d.
|
inline |
Definition at line 157 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d.
|
inline |
Definition at line 170 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d.
|
inline |
Definition at line 166 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d.
|
inline |
Definition at line 103 of file kis_shared_ptr.h.
References KisSharedPtr< T >::attach().
|
inline |
Definition at line 120 of file kis_shared_ptr.h.
References KisSharedPtr< T >::attach(), and p.
|
inline |
Definition at line 113 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d.
|
inline |
Definition at line 107 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d, and p.
|
inlineprivate |
Definition at line 209 of file kis_shared_ptr.h.
References KisSharedPtr< T >::d, and KisSharedPtr< T >::ref().
|
inlinestatic |
Definition at line 182 of file kis_shared_ptr.h.
References KisMemoryLeakTracker::instance(), and KisMemoryLeakTracker::reference().
|
friend |
Definition at line 514 of file kis_shared_ptr.h.
|
mutableprivate |
Definition at line 227 of file kis_shared_ptr.h.