![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtCore More...
#include <qshareddata.h>
Public Types | |
typedef T | Type |
This is the type of the shared data object. | |
typedef T * | pointer |
Public Member Functions | |
T & | operator* () const |
Provides access to the shared data object's members. | |
T * | operator-> () noexcept |
Provides access to the shared data object's members. | |
T * | operator-> () const noexcept |
Provides const access to the shared data object's members. | |
operator T* () | |
operator const T * () const noexcept | |
T * | data () const noexcept |
Returns a pointer to the shared data object. | |
T * | get () const noexcept |
const T * | constData () const noexcept |
Returns a const pointer to the shared data object. | |
T * | take () noexcept |
void | detach () |
If the shared data object's reference count is greater than 1, this function creates a deep copy of the shared data object and sets the {d pointer} of this to the copy. | |
Q_NODISCARD_CTOR | QExplicitlySharedDataPointer () noexcept |
Constructs a QExplicitlySharedDataPointer initialized with \nullptr as {d pointer}. | |
~QExplicitlySharedDataPointer () | |
Decrements the reference count of the shared data object. | |
Q_NODISCARD_CTOR | QExplicitlySharedDataPointer (T *data) noexcept |
Constructs a QExplicitlySharedDataPointer with {d pointer} set to data and increments {data}'s reference count. | |
Q_NODISCARD_CTOR | QExplicitlySharedDataPointer (T *data, QAdoptSharedDataTag) noexcept |
Q_NODISCARD_CTOR | QExplicitlySharedDataPointer (const QExplicitlySharedDataPointer &o) noexcept |
This standard copy constructor sets the {d pointer} of this to the {d pointer} in o and increments the reference count of the shared data object. | |
template<typename X> | |
Q_NODISCARD_CTOR | QExplicitlySharedDataPointer (const QExplicitlySharedDataPointer< X > &o) noexcept |
This copy constructor is different in that it allows o to be a different type of explicitly shared data pointer but one that has a compatible shared data object. | |
void | reset (T *ptr=nullptr) noexcept |
QExplicitlySharedDataPointer & | operator= (const QExplicitlySharedDataPointer &o) noexcept |
Sets the {d pointer} of this to the {d pointer} of o and increments the reference count of the shared data object. | |
QExplicitlySharedDataPointer & | operator= (T *o) noexcept |
Sets the {d pointer} of this to o and increments {o}'s reference count. | |
Q_NODISCARD_CTOR | QExplicitlySharedDataPointer (QExplicitlySharedDataPointer &&o) noexcept |
Move-constructs a QExplicitlySharedDataPointer instance, making it point at the same object that o was pointing to. | |
operator bool () const noexcept | |
Returns true if the {d pointer} of this is not null. | |
bool | operator! () const noexcept |
Returns true if the {d pointer} of this is \nullptr. | |
void | swap (QExplicitlySharedDataPointer &other) noexcept |
\memberswap{explicitly-shared data pointer} | |
void | detach () |
void | detach () |
Protected Member Functions | |
T * | clone () |
Friends | |
bool | comparesEqual (const QExplicitlySharedDataPointer &lhs, const QExplicitlySharedDataPointer &rhs) noexcept |
Qt::strong_ordering | compareThreeWay (const QExplicitlySharedDataPointer &lhs, const QExplicitlySharedDataPointer &rhs) noexcept |
bool | comparesEqual (const QExplicitlySharedDataPointer &lhs, const T *rhs) noexcept |
Qt::strong_ordering | compareThreeWay (const QExplicitlySharedDataPointer &lhs, const T *rhs) noexcept |
bool | comparesEqual (const QExplicitlySharedDataPointer &lhs, std::nullptr_t) noexcept |
Qt::strong_ordering | compareThreeWay (const QExplicitlySharedDataPointer &lhs, std::nullptr_t) noexcept |
\inmodule QtCore
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object.
\compares strong \compareswith strong T* std::nullptr_t \endcompareswith
QExplicitlySharedDataPointer<T> makes writing your own explicitly shared classes easy. QExplicitlySharedDataPointer implements \l {thread-safe} reference counting, ensuring that adding QExplicitlySharedDataPointers to your \l {reentrant} classes won't make them non-reentrant.
Except for one big difference, QExplicitlySharedDataPointer is just like QSharedDataPointer. The big difference is that member functions of QExplicitlySharedDataPointer {do not} do the automatic {copy on write} operation (detach()) that non-const members of QSharedDataPointer do before allowing the shared data object to be modified. There is a detach() function available, but if you really want to detach(), you have to call it yourself. This means that QExplicitlySharedDataPointers behave like regular C++ pointers, except that by doing reference counting and not deleting the shared data object until the reference count is 0, they avoid the dangling pointer problem.
It is instructive to compare QExplicitlySharedDataPointer with QSharedDataPointer by way of an example. Consider the \l {Employee example} in QSharedDataPointer, modified to use explicit sharing as explained in the discussion \l {Implicit vs Explicit Sharing}.
Note that if you use this class but find you are calling detach() a lot, you probably should be using QSharedDataPointer instead.
In the member function documentation, {d pointer} always refers to the internal pointer to the shared data object.
Definition at line 130 of file qshareddata.h.
typedef T* QExplicitlySharedDataPointer< T >::pointer |
Definition at line 134 of file qshareddata.h.
typedef T QExplicitlySharedDataPointer< T >::Type |
This is the type of the shared data object.
The {d pointer} points to an object of this type.
Definition at line 133 of file qshareddata.h.
|
inlinenoexcept |
Constructs a QExplicitlySharedDataPointer initialized with \nullptr as {d pointer}.
Definition at line 149 of file qshareddata.h.
|
inline |
Decrements the reference count of the shared data object.
If the reference count becomes 0, the shared data object is deleted. This is then destroyed.
Definition at line 150 of file qshareddata.h.
|
inlineexplicitnoexcept |
Constructs a QExplicitlySharedDataPointer with {d pointer} set to data and increments {data}'s reference count.
Definition at line 153 of file qshareddata.h.
|
inlinenoexcept |
Definition at line 156 of file qshareddata.h.
|
inlinenoexcept |
This standard copy constructor sets the {d pointer} of this to the {d pointer} in o and increments the reference count of the shared data object.
Definition at line 159 of file qshareddata.h.
|
inlinenoexcept |
This copy constructor is different in that it allows o to be a different type of explicitly shared data pointer but one that has a compatible shared data object.
By default, the {d pointer} of o (of type {X *}) gets implicitly converted to the type
{T *}; the result of this conversion is set as the {d pointer} of {this}, and the reference count of the shared data object is incremented.
Definition at line 164 of file qshareddata.h.
|
inlinenoexcept |
Move-constructs a QExplicitlySharedDataPointer instance, making it point at the same object that o was pointing to.
Definition at line 193 of file qshareddata.h.
|
protected |
Creates and returns a deep copy of the current data. This function is called by detach() when the reference count is greater than 1 in order to create the new copy. This function uses the {operator new} and calls the copy constructor of the type T.
See QSharedDataPointer<T>::clone() for an explanation of how to use it.
Definition at line 252 of file qshareddata.h.
|
inlinenoexcept |
Returns a const pointer to the shared data object.
Definition at line 143 of file qshareddata.h.
|
inlinenoexcept |
Returns a pointer to the shared data object.
Definition at line 141 of file qshareddata.h.
|
inline |
If the shared data object's reference count is greater than 1, this function creates a deep copy of the shared data object and sets the {d pointer} of this to the copy.
Because QExplicitlySharedDataPointer does not do the automatic {copy on write} operations that members of QSharedDataPointer do, detach() is not called automatically anywhere in the member functions of this class. If you find that you are calling detach() everywhere in your code, consider using QSharedDataPointer instead.
Definition at line 146 of file qshareddata.h.
void QExplicitlySharedDataPointer< QHttpHeadersPrivate >::detach | ( | ) |
Definition at line 810 of file qhttpheaders.cpp.
void QExplicitlySharedDataPointer< QHttpHeadersPrivate >::detach | ( | ) |
Definition at line 810 of file qhttpheaders.cpp.
|
inlinenoexcept |
Same as data(). This function is provided for STL compatibility.
Definition at line 142 of file qshareddata.h.
|
inlinenoexcept |
Returns true
if the {d pointer} of this is not null.
Definition at line 196 of file qshareddata.h.
|
inlineexplicitnoexcept |
Definition at line 140 of file qshareddata.h.
|
inlineexplicit |
Definition at line 139 of file qshareddata.h.
|
inlinenoexcept |
Returns true
if the {d pointer} of this is \nullptr.
Definition at line 197 of file qshareddata.h.
|
inline |
Provides access to the shared data object's members.
Definition at line 136 of file qshareddata.h.
|
inlinenoexcept |
Provides const access to the shared data object's members.
Definition at line 138 of file qshareddata.h.
|
inlinenoexcept |
Provides access to the shared data object's members.
Definition at line 137 of file qshareddata.h.
|
inlinenoexcept |
Sets the {d pointer} of this to the {d pointer} of o and increments the reference count of the shared data object.
The reference count of the old shared data object of this is decremented. If the reference count of the old shared data object becomes 0, the old shared data object is deleted.
Definition at line 182 of file qshareddata.h.
|
inlinenoexcept |
Sets the {d pointer} of this to o and increments {o}'s reference count.
The reference count of the old shared data object of this is decremented. If the reference count of the old shared data object becomes 0, the old shared data object is deleted.
Definition at line 187 of file qshareddata.h.
|
inlinenoexcept |
Sets the {d pointer} of this to ptr and increments {ptr}'s reference count if ptr is not \nullptr. The reference count of the old shared data object is decremented, and the object deleted if the reference count reaches 0.
Definition at line 171 of file qshareddata.h.
Referenced by QExplicitlySharedDataPointer< ConnectionData >::operator=(), and QExplicitlySharedDataPointer< ConnectionData >::operator=().
|
inlinenoexcept |
\memberswap{explicitly-shared data pointer}
Definition at line 199 of file qshareddata.h.
|
inlinenoexcept |
Returns a pointer to the shared object, and resets this to be \nullptr. (That is, this function sets the {d pointer} of this to \nullptr.)
Definition at line 144 of file qshareddata.h.
|
friend |
Definition at line 206 of file qshareddata.h.
|
friend |
Definition at line 215 of file qshareddata.h.
|
friend |
Definition at line 222 of file qshareddata.h.
|
friend |
Definition at line 210 of file qshareddata.h.
|
friend |
Definition at line 218 of file qshareddata.h.
|
friend |
Definition at line 225 of file qshareddata.h.