Qt 4.8
|
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object. More...
#include <qshareddata.h>
Public Types | |
typedef T * | pointer |
typedef T | Type |
This is the type of the shared data object. More... | |
Public Functions | |
const T * | constData () const |
Returns a const pointer to the shared data object. More... | |
T * | data () const |
Returns a pointer to the shared data object. More... | |
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. More... | |
operator bool () const | |
Returns true if the d pointer of this is not null. More... | |
bool | operator! () const |
Returns true if the d pointer of this is null. More... | |
bool | operator!= (const QExplicitlySharedDataPointer< T > &other) const |
Returns true if other and this do not have the same d pointer. More... | |
bool | operator!= (const T *ptr) const |
Returns true if the d pointer of this is not ptr. More... | |
T & | operator* () const |
Provides access to the shared data object's members. More... | |
T * | operator-> () |
Provides access to the shared data object's members. More... | |
T * | operator-> () const |
Provides const access to the shared data object's members. More... | |
QExplicitlySharedDataPointer< T > & | operator= (const QExplicitlySharedDataPointer< T > &o) |
Sets the d pointer of this to the d pointer of other and increments the reference count of the shared data object. More... | |
QExplicitlySharedDataPointer & | operator= (T *o) |
Sets the d pointer of this to sharedData and increments {sharedData}'s reference count. More... | |
bool | operator== (const QExplicitlySharedDataPointer< T > &other) const |
Returns true if other and this have the same d pointer. More... | |
bool | operator== (const T *ptr) const |
Returns true if the d pointer of this is ptr. More... | |
QExplicitlySharedDataPointer () | |
Constructs a QExplicitlySharedDataPointer initialized with a null d pointer. More... | |
QExplicitlySharedDataPointer (T *data) | |
Constructs a QExplicitlySharedDataPointer with d pointer set to sharedData and increments {sharedData}'s reference count. More... | |
QExplicitlySharedDataPointer (const QExplicitlySharedDataPointer< T > &o) | |
This standard copy constructor sets the {d pointer} of this to the {d pointer} in other and increments the reference count of the shared data object. More... | |
template<class X > | |
QExplicitlySharedDataPointer (const QExplicitlySharedDataPointer< X > &o) | |
This copy constructor is different in that it allows other to be a different type of explicitly shared data pointer but one that has a compatible shared data object. More... | |
void | reset () |
Resets this to be null. More... | |
void | swap (QExplicitlySharedDataPointer &other) |
Swap this instance's explicitly shared data pointer with the explicitly shared data pointer in other. More... | |
~QExplicitlySharedDataPointer () | |
Decrements the reference count of the shared data object. More... | |
Protected Functions | |
T * | clone () |
Private Functions | |
void | detach_helper () |
Properties | |
T * | d |
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.
Definition at line 136 of file qshareddata.h.
QExplicitlySharedDataPointer< T >::pointer |
Definition at line 140 of file qshareddata.h.
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 139 of file qshareddata.h.
|
inline |
Constructs a QExplicitlySharedDataPointer initialized with a null d pointer.
Definition at line 165 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 166 of file qshareddata.h.
|
explicit |
Constructs a QExplicitlySharedDataPointer with d pointer set to sharedData and increments {sharedData}'s reference count.
Definition at line 257 of file qshareddata.h.
|
inline |
|
inline |
This copy constructor is different in that it allows other to be a different type of explicitly shared data pointer but one that has a compatible shared data object.
It performs a static cast of the d pointer in other and sets the {d pointer} of this to the converted d pointer. It increments the reference count of the shared data object.
Definition at line 172 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::clone() for an explanation of how to use it.
Definition at line 241 of file qshareddata.h.
|
inline |
Returns a const pointer to the shared data object.
Definition at line 146 of file qshareddata.h.
|
inline |
Returns a pointer to the shared data object.
Definition at line 145 of file qshareddata.h.
Referenced by QPatternist::DistinctIterator::actualReflection(), QPatternist::UntypedAtomicConverter::actualReflection(), QPatternist::IndexOfIterator::actualReflection(), QPatternist::ContextItem::actualReflection(), QPatternist::OrderBy::OrderSpec::actualReflection(), QPatternist::QNameConstructor::actualReflection(), QPatternist::XsdElement::addSubstitutionGroup(), QPatternist::DocumentContentValidator::attribute(), QX11PaintEngine::begin(), QX11WindowSurface::beginPaint(), QGLContextPrivate::bindTextureFromNativePixmap(), QFontMetrics::boundingRect(), QFontMetricsF::boundingRect(), QFontMetrics::charWidth(), QPatternist::CallTargetDescription::checkCallsiteCircularity(), QPatternist::checkVariableCircularity(), QPixmap::clut(), QPixmap::colorCount(), QPatternist::SimpleContentConstructor::compress(), QPixmap::copy(), QPatternist::GenericPredicate::create(), QPatternist::create(), QPatternist::ExpressionFactory::createExpression(), QPatternist::XsdValidatingInstanceReader::createXQuery(), QPixmap::detach(), QFont::detach(), QX11PaintEngine::drawPixmap(), QX11PaintEngine::drawTiledPixmap(), QXmlQueryPrivate::dynamicContext(), QFontMetrics::elidedText(), QFontMetricsF::elidedText(), QPatternist::XsdValidatingInstanceReader::error(), QPatternist::ComparisonPlatform< IndexOfIterator, false >::fetchComparator(), QPatternist::findAxisStep(), QX11GLWindowSurface::flush(), QRawFont::fromFont(), QStaticTextPrivate::get(), QMeeGoGraphicsSystem::getLiveTextureHandle(), QMeeGoLivePixmapData::getSurfaceForBackingPixmap(), hasDuplicatedElementsInternal(), QMeeGoLivePixmapData::invalidateSurfaces(), QPatternist::Expression::invokeOptimizers(), QSslCertificate::issuerInfo(), QPatternist::Item::Item(), QPatternist::AtomicType::itemMatches(), QPatternist::CastingPlatform< UntypedAtomicConverter, true >::locateCaster(), QMeeGoGraphicsSystem::lockLiveTexture(), QFontInfo::operator=(), QFontMetrics::operator=(), QFontMetricsF::operator=(), QFont::operator=(), QPatternist::ItemType::operator|(), QPatternist::AxisStep::patternPriority(), QPixmap::pixmapData(), QPatternist::pushVariable(), QFont::QFont(), QFontMetrics::QFontMetrics(), QFontMetricsF::QFontMetricsF(), qstring_to_xtp(), qt_mac_cg_context(), qt_mac_create_imagemask(), qt_mac_pixmap_get_base(), qt_mac_pixmap_get_bytes_per_line(), QTextLayout::QTextLayout(), QPixmap::qwsBits(), QPixmap::qwsBytesPerLine(), QMeeGoGraphicsSystem::releaseLiveTexture(), QFont::resolve(), QPatternist::resolveVariable(), QPatternist::AccelTreeResourceLoader::retrieveDocument(), QPatternist::ConstructorFunctionsFactory::retrieveExpression(), QPatternist::Expression::rewrite(), QX11GLWindowSurface::scroll(), QSslCertificate::serialNumber(), QMacPixmapData::setAlphaChannel(), QPatternist::XsdSimpleType::setContext(), QPatternist::XsdComplexType::setContext(), QPatternist::XsdAttribute::Scope::setParent(), QPatternist::XsdElement::Scope::setParent(), QPatternist::UserFunctionCallsite::setSource(), QPatternist::XsdElement::setType(), QPatternist::XsdComplexType::setWxsSuperType(), QFontPrivate::smallCapsFontPrivate(), QSslCertificate::subjectInfo(), QFontMetrics::tightBoundingRect(), QFontMetricsF::tightBoundingRect(), toIcdConfig(), QPatternist::toItem(), QPatternist::AbstractFloat< isDouble >::toNegated(), QPatternist::Decimal::toNegated(), QPatternist::AtomicValue::toQt(), QPixmap::toWinHBITMAP(), QPatternist::DocumentFN::typeCheck(), QPatternist::CardinalityVerifier::verifyCardinality(), QPatternist::TypeChecker::verifyType(), QSslCertificate::version(), QFontMetrics::width(), QFontMetricsF::width(), QPatternist::NodeSortExpression::wrapAround(), QPatternist::StaticContext::wrapExpressionWith(), QPatternist::Literal::wrapLiteral(), QPatternist::AnyType::wxsTypeMatches(), QPatternist::BuiltinNodeType< kind >::xdtTypeMatches(), QPatternist::XSLTNodeTest::xdtTypeMatches(), QPatternist::XsdSchemaParser::XsdSchemaParser(), QPatternist::FunctionFactoryCollection::xslt20Factory(), and QPatternist::yyparse().
|
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 148 of file qshareddata.h.
Referenced by QPicture::detach(), QStaticText::detach(), QGlyphRun::detach(), QDateTime::detach(), QFont::detach(), QDBusUnixFileDescriptor::giveFileDescriptor(), QRawFont::loadFromData(), QScriptString::operator=(), QScriptString::QScriptString(), and QRawFont::setPixelSize().
|
private |
|
inline |
|
inline |
|
inline |
Returns true if other and this do not have the same d pointer.
Definition at line 161 of file qshareddata.h.
|
inline |
|
inline |
|
inline |
|
inline |
Provides const access to the shared data object's members.
Definition at line 144 of file qshareddata.h.
|
inline |
Sets the d pointer of this to the d pointer of other 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 178 of file qshareddata.h.
|
inline |
Sets the d pointer of this to sharedData and increments {sharedData}'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 189 of file qshareddata.h.
|
inline |
Returns true if other and this have the same d pointer.
Definition at line 160 of file qshareddata.h.
|
inline |
|
inline |
Resets this to be null.
i.e., this function sets the d pointer of this to 0, but first it decrements the reference count of the shared data object and deletes the shared data object if the reference count became 0.
Definition at line 150 of file qshareddata.h.
Referenced by QPatternist::ApplyTemplate::compress(), QXmlQueryPrivate::expression(), QXmlQueryPrivate::recompileRequired(), and QXmlQueryPrivate::setRequiredType().
|
inline |
|
private |
Definition at line 217 of file qshareddata.h.
Referenced by QExplicitlySharedDataPointer< QSslConfigurationPrivate >::operator!=(), QExplicitlySharedDataPointer< QSslConfigurationPrivate >::operator=(), QExplicitlySharedDataPointer< QSslConfigurationPrivate >::operator==(), QExplicitlySharedDataPointer< QSslConfigurationPrivate >::QExplicitlySharedDataPointer(), and QExplicitlySharedDataPointer< QSslConfigurationPrivate >::swap().