CopperSpice API
1.9.2
|
Stores a pointer to a potentially shared object. More...
Public Typedefs | |
using | element_type = typename std::shared_ptr< T >::element_type |
using | ElementType = element_type |
using | pointer = element_type * |
using | Pointer = pointer |
using | weak_type = QWeakPointer< T > |
using | WeakType = weak_type |
Public Methods | |
constexpr | QSharedPointer () noexcept |
QSharedPointer (const QSharedPointer< T > &other) = default | |
template<typename U > | |
QSharedPointer (const QSharedPointer< U > &p) noexcept | |
template<typename U > | |
QSharedPointer (const QWeakPointer< U > &p) | |
template<typename U > | |
QSharedPointer (const std::shared_ptr< U > &p) noexcept | |
QSharedPointer (QSharedPointer< T > &&other) = default | |
template<typename U > | |
QSharedPointer (QSharedPointer< U > &&p) noexcept | |
template<typename U , typename Deleter > | |
QSharedPointer (QUniquePointer< U, Deleter > &&p) | |
constexpr | QSharedPointer (std::nullptr_t) noexcept |
template<typename Deleter > | |
QSharedPointer (std::nullptr_t, Deleter d) | |
template<typename Deleter , typename Alloc > | |
QSharedPointer (std::nullptr_t, Deleter d, Alloc a) | |
template<typename U > | |
QSharedPointer (std::shared_ptr< U > &&p) noexcept | |
template<typename U > | |
QSharedPointer (U *p) | |
template<typename U , typename Deleter > | |
QSharedPointer (U *p, Deleter d) | |
template<typename U , typename Deleter , typename Alloc > | |
QSharedPointer (U *p, Deleter d, Alloc a) | |
~QSharedPointer () | |
void | clear () |
template<typename U > | |
QSharedPointer< U > | constCast () const |
QSharedPointer< T > | create (Args &&...args) |
T * | data () const |
template<typename U > | |
QSharedPointer< U > | dynamicCast () const |
bool | isNull () const |
template<typename U > | |
QSharedPointer< U > | objectCast () const |
operator bool () const | |
bool | operator! () const |
T & | operator* () const |
T * | operator-> () const |
QSharedPointer & | operator= (const QSharedPointer< T > &other) = default |
template<typename U > | |
QSharedPointer & | operator= (const QSharedPointer< U > &p) noexcept |
template<typename U > | |
QSharedPointer & | operator= (const QWeakPointer< U > &p) |
QSharedPointer & | operator= (QSharedPointer< T > &&other) = default |
template<typename U > | |
QSharedPointer & | operator= (QSharedPointer< U > &&p) noexcept |
void | reset () |
void | reset (U *value) |
void | reset (U *value, Deleter d) |
void | reset (U *value, Deleter d, Alloc a) |
template<typename U > | |
QSharedPointer< U > | staticCast () const |
void | swap (QSharedPointer &other) |
QWeakPointer< T > | toWeakRef () const |
Related Functions | |
These are not member functions | |
bool | operator!= (const QSharedPointer< T1 > &ptr1, const QSharedPointer< T2 > &ptr2) |
bool | operator!= (const QSharedPointer< T1 > &ptr1, const T2 *ptr2) |
bool | operator!= (const T1 *ptr1, const QSharedPointer< T2 > &ptr2) |
bool | operator< (const QSharedPointer< T1 > &ptr1, const QSharedPointer< T2 > ptr2) |
bool | operator<= (const QSharedPointer< T1 > &ptr1, const QSharedPointer< T2 > ptr2) |
bool | operator== (const QSharedPointer< T1 > &ptr1, const QSharedPointer< T2 > &ptr2) |
bool | operator== (const QSharedPointer< T1 > &ptr1, const T2 *ptr2) |
bool | operator== (const T1 *ptr1, const QSharedPointer< T2 > &ptr2) |
bool | operator> (const QSharedPointer< T1 > &ptr1, const QSharedPointer< T2 > ptr2) |
bool | operator>= (const QSharedPointer< T1 > &ptr1, const QSharedPointer< T2 > ptr2) |
QSharedPointer< T > | QMakeShared (Args &&...args) |
QSharedPointer< U > | qSharedPointerConstCast (const QSharedPointer< T > &other) |
QSharedPointer< U > | qSharedPointerDynamicCast (const QSharedPointer< T > &other) |
QSharedPointer< U > | qSharedPointerObjectCast (const QSharedPointer< T > &other) |
QSharedPointer< U > | qSharedPointerStaticCast (const QSharedPointer< T > &other) |
The QSharedPointer class stores a pointer to a potentially shared object. This class maintains a shared reference count which indicates how many shared pointers are pointing to the current object. Any pointer class which takes responsibility for the lifetime of the object it points to is considered a smart pointer.
A QSharedPointer object can be constructed from a raw pointer, another QSharedPointer object, or by a QWeakPointer object. When this class is destroyed the object it points to will be deleted if no other shared pointers are pointing to the given object.
QSharedPointer and QWeakPointer are thread safe which means the internal pointer is updated atomically. Different threads can access the QSharedPointer or QWeakPointer pointing to the same object at the same time without a locking mechanism. While this shared pointer class is thread safe it can not provide a guarantee about the object it points to.
QSharedPointer< T >::element_type |
Typedef for std::shared_ptr<T>::element_type.
QSharedPointer< T >::ElementType |
Typedef for element_type.
QSharedPointer< T >::pointer |
Typedef for element_type *.
QSharedPointer< T >::Pointer |
Typedef for pointer.
QSharedPointer< T >::weak_type |
Typedef for QWeakPointer<T>.
|
constexprnoexcept |
Creates a new QSharedPointer which contains a nullptr.
|
constexprnoexcept |
Creates a new QSharedPointer which contains a nullptr.
|
explicit |
Creates a new QSharedPointer which points to p. Ownership of the object is transferred to the new QSharedPointer.
QSharedPointer< T >::QSharedPointer | ( | U * | p, |
Deleter | d | ||
) |
Creates a new QSharedPointer which points to the given raw pointer p. Ownership of the object is transferred to the new QSharedPointer. The value for d is a deleter object and will be used when QSharedPointer is being destroyed.
QSharedPointer< T >::QSharedPointer | ( | std::nullptr_t | , |
Deleter | d | ||
) |
Creates a new QSharedPointer which contains a nullptr. The value for d is a deleter object and will be used when QSharedPointer is being destroyed.
QSharedPointer< T >::QSharedPointer | ( | U * | p, |
Deleter | d, | ||
Alloc | a | ||
) |
Creates a new QSharedPointer which points to p. Ownership of the object is transferred to the new QSharedPointer. The value for d is a deleter object and will be used when QSharedPointer is being destroyed. The value for a is an allocator object and will be used when QSharedPointer needs to allocate memory.
QSharedPointer< T >::QSharedPointer | ( | std::nullptr_t | , |
Deleter | d, | ||
Alloc | a | ||
) |
Creates a new QSharedPointer which contains a nullptr. The value for d is a deleter object and will be used when QSharedPointer is being destroyed. The value for a is an allocator object and will be used when QSharedPointer needs to allocate memory.
QSharedPointer< T >::QSharedPointer | ( | QUniquePointer< U, Deleter > && | p | ) |
Creates a new QSharedPointer using the given unique pointer p. The unique pointer will be set to a nullptr.
|
noexcept |
Creates a new QSharedPointer using the given C++ Standard Library shared pointer p.
|
noexcept |
Creates a new QSharedPointer by moving from the given C++ Standard Library shared pointer p.
QSharedPointer< T >::~QSharedPointer | ( | ) |
Destroys this QSharedPointer.
If the current QSharedPointer is not a nullptr, then the internal reference count is decremented. If the reference count is zero then the object it is pointing to will be destroyed.
|
default |
Copy constructs a new QSharedPointer from other. The current shared pointer shares ownership with other.
|
default |
Move constructs a new QSharedPointer from other.
|
noexcept |
Copy constructs a new QSharedPointer from p. This shared pointer shares ownership with other. The template parameter U must inherit from T.
|
noexcept |
Creates a QSharedPointer which shares ownership with p. The template parameter U must inherit from T.
|
explicit |
Creates a QSharedPointer by converting the weak pointer p to a shared pointer. The template parameter U must inherit from T.
void QSharedPointer< T >::clear | ( | ) |
Set the current QSharedPointer to a nullptr.
If the current QSharedPointer is not a nullptr, then the internal reference count is decremented. If the reference count is zero then the object it is pointing to will be destroyed.
QSharedPointer< U > QSharedPointer< T >::constCast | ( | ) | const |
Returns a QSharedPointer to the current object. The shared pointer is cast from type T to type U using a const_cast.
QSharedPointer< T > QSharedPointer< T >::create | ( | Args &&... | args | ) |
Creates a new QSharedPointer pointing to a new object of type T. This method can be more efficient than calling new to create the object and using the constructor which accepts a raw pointer.
T * QSharedPointer< T >::data | ( | ) | const |
Returns the value of the pointer referenced by this object.
QSharedPointer< U > QSharedPointer< T >::dynamicCast | ( | ) | const |
Returns a QSharedPointer to the current object. The returned shared pointer is cast from type T to type U using a dynamic_cast. If the cast fails this method will return a nullptr.
The U must have the same cv-qualifiers (const and volatile) that T has. If you need to cast away either of these qualifiers then use constCast().
bool QSharedPointer< T >::isNull | ( | ) | const |
Returns true if the current QSharedPointer contains a nullptr.
QSharedPointer< U > QSharedPointer< T >::objectCast | ( | ) | const |
Equivalent to calling dynamicCast<U>().
QSharedPointer< T >::operator bool | ( | ) | const |
Returns true if the current QSharedPointer is not a nullptr. This method is called when a shared pointer is used in an "if statement" or another context where a boolean value is expected. Since this method is explicit it is not possible to assign a QSharedPointer to a boolean.
bool QSharedPointer< T >::operator! | ( | ) | const |
Returns true if this object is a nullptr. This method is called when a shared pointer is used in an "if statement" or another context where a boolean value is expected.
T & QSharedPointer< T >::operator* | ( | ) | const |
Returns a reference to the object the current QSharedPointer is pointing to.
T * QSharedPointer< T >::operator-> | ( | ) | const |
Returns a pointer to the object the current QSharedPointer is pointing to.
|
default |
Copy assigns from other and returns a reference to this object.
If the current QSharedPointer is not a nullptr, then the internal reference count is decremented. If the reference count is zero then the object it is pointing to will be destroyed.
|
noexcept |
Copy assigns from p and returns a reference to this object. The template parameter U must inherit from T.
If the current QSharedPointer is not a nullptr, then the internal reference count is decremented. If the reference count is zero then the object it is pointing to will be destroyed.
QSharedPointer & QSharedPointer< T >::operator= | ( | const QWeakPointer< U > & | p | ) |
Converts the weak pointer p to a shared pointer and then assigns it to the current QSharedPointer. The template parameter U must inherit from T.
If the current QSharedPointer is not a nullptr, then the internal reference count is decremented. If the reference count is zero then the object it is pointing to will be destroyed.
|
default |
Move assigns from other and returns a reference to this object.
If the current QSharedPointer is not a nullptr, then the internal reference count is decremented. If the reference count is zero then the object it is pointing to will be destroyed.
|
noexcept |
Copy assigns from p and returns a reference to this object. The template parameter U must inherit from T.
If the current QSharedPointer is not a nullptr, then the internal reference count is decremented. If the reference count is zero then the object it is pointing to will be destroyed.
void QSharedPointer< T >::reset | ( | ) |
Equivalent to calling clear().
void QSharedPointer< T >::reset | ( | U * | value | ) |
Resets the current QSharedPointer object to point to value. The template parameter U must inherit from T.
void QSharedPointer< T >::reset | ( | U * | value, |
Deleter | d | ||
) |
Resets the current QSharedPointer object to point to value and updates the Deleter to d. The template parameter U must inherit from T.
void QSharedPointer< T >::reset | ( | U * | value, |
Deleter | d, | ||
Alloc | a | ||
) |
Resets the current QSharedPointer object to point to value and updates the Deleter to d. The value for a is an allocator object and will be used when QSharedPointer needs to allocate memory. The template parameter U must inherit from T.
QSharedPointer< U > QSharedPointer< T >::staticCast | ( | ) | const |
Returns a QSharedPointer to the current object. The returned shared pointer is cast from type T to type U using a static_cast.
void QSharedPointer< T >::swap | ( | QSharedPointer< T > & | other | ) |
Swaps the current QSharedPointer with other. This method is very fast and never fails.
QWeakPointer< T > QSharedPointer< T >::toWeakRef | ( | ) | const |
Returns a QWeakPointer which shares the internal reference count with the current QSharedPointer.
|
related |
Returns true if ptr1 and ptr2 do not point to the same object.
|
related |
Returns true if ptr1 and ptr2 do not point to the same object.
|
related |
Returns true if ptr1 and ptr2 do not point to the same object.
|
related |
Returns true if the value of ptr1 is less than ptr2.
|
related |
Returns true if the value of ptr1 is less than or equal to ptr2.
|
related |
Returns true if ptr1 and ptr2 point to the same object.
|
related |
Returns true if ptr1 and ptr2 point to the same object.
|
related |
Returns true if ptr1 and ptr2 point to the same object.
|
related |
Returns true if the value of ptr1 is greater than ptr2.
|
related |
Returns true if the value of ptr1 is greater than or equal to ptr2.
|
related |
This function constructs a new object of type T and returns a shared pointer to the newly created object in a single operation.
|
related |
Equivalent to calling other.constCast<U>().
|
related |
Equivalent to calling other.dynamicCast<U>().
|
related |
Equivalent to calling other.dynamicCast<U>() or other.objectCast<U>().
|
related |
Equivalent to calling other.staticCast<U>().