QExplicitlySharedDataPointer Class
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object. More...
Header: | #include <QExplicitlySharedDataPointer> |
qmake: | QT += core |
Since: | Qt 4.4 |
Note: All functions in this class are reentrant.
Public Types
typedef | Type |
Public Functions
QExplicitlySharedDataPointer() | |
QExplicitlySharedDataPointer(T *data) | |
QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<T> &o) | |
QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<X> &o) | |
QExplicitlySharedDataPointer(QExplicitlySharedDataPointer<T> &&o) | |
~QExplicitlySharedDataPointer() | |
const T * | constData() const |
T * | data() const |
void | detach() |
void | reset() |
T * | take() |
bool | operator bool() const |
bool | operator!=(const QExplicitlySharedDataPointer<T> &other) const |
bool | operator!=(const T *ptr) const |
T & | operator*() const |
T * | operator->() |
T * | operator->() const |
QExplicitlySharedDataPointer<T> & | operator=(const QExplicitlySharedDataPointer<T> &o) |
QExplicitlySharedDataPointer<T> & | operator=(T *o) |
bool | operator==(const QExplicitlySharedDataPointer<T> &other) const |
bool | operator==(const T *ptr) const |
Detailed Description
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object.
QExplicitlySharedDataPointer<T> makes writing your own explicitly shared classes easy. QExplicitlySharedDataPointer implements thread-safe reference counting, ensuring that adding QExplicitlySharedDataPointers to your 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 Employee example in QSharedDataPointer, modified to use explicit sharing as explained in the discussion 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.
See also QSharedData and QSharedDataPointer.
Member Type Documentation
typedef QExplicitlySharedDataPointer::Type
This is the type of the shared data object. The d pointer points to an object of this type.
Member Function Documentation
QExplicitlySharedDataPointer::QExplicitlySharedDataPointer()
Default constructs an instance of QExplicitlySharedDataPointer.
QExplicitlySharedDataPointer::QExplicitlySharedDataPointer(T *data)
Default constructs an instance of QExplicitlySharedDataPointer.
QExplicitlySharedDataPointer::QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<T> &o)
Default constructs an instance of QExplicitlySharedDataPointer.
QExplicitlySharedDataPointer::QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<X> &o)
Default constructs an instance of QExplicitlySharedDataPointer.
QExplicitlySharedDataPointer::QExplicitlySharedDataPointer(QExplicitlySharedDataPointer<T> &&o)
Default constructs an instance of QExplicitlySharedDataPointer.
QExplicitlySharedDataPointer::~QExplicitlySharedDataPointer()
Destroys the instance of QExplicitlySharedDataPointer.
const T *QExplicitlySharedDataPointer::constData() const
T *QExplicitlySharedDataPointer::data() const
void QExplicitlySharedDataPointer::detach()
void QExplicitlySharedDataPointer::reset()
T *QExplicitlySharedDataPointer::take()
bool QExplicitlySharedDataPointer::operator bool() const
bool QExplicitlySharedDataPointer::operator!=(const QExplicitlySharedDataPointer<T> &other) const
bool QExplicitlySharedDataPointer::operator!=(const T *ptr) const
T &QExplicitlySharedDataPointer::operator*() const
T *QExplicitlySharedDataPointer::operator->()
T *QExplicitlySharedDataPointer::operator->() const
QExplicitlySharedDataPointer<T> &QExplicitlySharedDataPointer::operator=(const QExplicitlySharedDataPointer<T> &o)
Copy-assignment operator.