<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- qshareddata.cpp --> <head> <title>Qt 4.6: QExplicitlySharedDataPointer Class Reference</title> <link href="classic.css" rel="stylesheet" type="text/css" /> </head> <body> <a name="//apple_ref/cpp/cl//QExplicitlySharedDataPointer"></a> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td> <td width="1"> </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="functions.html"><font color="#004faf">All Functions</font></a> · <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><h1 class="title">QExplicitlySharedDataPointer Class Reference<br /><span class="small-subtitle">[<a href="qtcore.html">QtCore</a> module]</span> </h1> <p>The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object. <a href="#details">More...</a></p> <pre> #include <QExplicitlySharedDataPointer></pre><p><b>Note:</b> All functions in this class are <a href="threads-reentrancy.html#reentrant">reentrant</a>.</p> <p>This class was introduced in Qt 4.4.</p> <ul> <li><a href="qexplicitlyshareddatapointer-members.html">List of all members, including inherited members</a></li> </ul> <hr /> <a name="public-types"></a> <h2>Public Types</h2> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top">typedef </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#Type-typedef">Type</a></b></td></tr> </table> <hr /> <a name="public-functions"></a> <h2>Public Functions</h2> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#QExplicitlySharedDataPointer">QExplicitlySharedDataPointer</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#QExplicitlySharedDataPointer-2">QExplicitlySharedDataPointer</a></b> ( T * <i>sharedData</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#QExplicitlySharedDataPointer-3">QExplicitlySharedDataPointer</a></b> ( const QExplicitlySharedDataPointer<T> & <i>other</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#QExplicitlySharedDataPointer-4">QExplicitlySharedDataPointer</a></b> ( const QExplicitlySharedDataPointer<X> & <i>other</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#dtor.QExplicitlySharedDataPointer">~QExplicitlySharedDataPointer</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">const T * </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#constData">constData</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">T * </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#data">data</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#detach">detach</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#reset">reset</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#swap">swap</a></b> ( QExplicitlySharedDataPointer & <i>other</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#operator-bool">operator bool</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#operator-not">operator!</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#operator-not-eq">operator!=</a></b> ( const QExplicitlySharedDataPointer<T> & <i>other</i> ) const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#operator-not-eq-2">operator!=</a></b> ( const T * <i>ptr</i> ) const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">T & </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#operator-2a">operator*</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">T * </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#operator--gt">operator-></a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">T * </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#operator--gt-2">operator-></a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">QExplicitlySharedDataPointer<T> & </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#operator-eq">operator=</a></b> ( const QExplicitlySharedDataPointer<T> & <i>other</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">QExplicitlySharedDataPointer & </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#operator-eq-2">operator=</a></b> ( T * <i>sharedData</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#operator-eq-eq">operator==</a></b> ( const QExplicitlySharedDataPointer<T> & <i>other</i> ) const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#operator-eq-eq-2">operator==</a></b> ( const T * <i>ptr</i> ) const</td></tr> </table> <hr /> <a name="protected-functions"></a> <h2>Protected Functions</h2> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top">T * </td><td class="memItemRight" valign="bottom"><b><a href="qexplicitlyshareddatapointer.html#clone">clone</a></b> ()</td></tr> </table> <a name="details"></a> <hr /> <h2>Detailed Description</h2> <p>The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object.</p> <p>QExplicitlySharedDataPointer<T> makes writing your own explicitly shared classes easy. QExplicitlySharedDataPointer implements <a href="threads-reentrancy.html#thread-safe">thread-safe</a> reference counting, ensuring that adding QExplicitlySharedDataPointers to your <a href="threads-reentrancy.html#reentrant">reentrant</a> classes won't make them non-reentrant.</p> <p>Except for one big difference, QExplicitlySharedDataPointer is just like <a href="qshareddatapointer.html">QSharedDataPointer</a>. The big difference is that member functions of QExplicitlySharedDataPointer <i>do not</i> do the automatic <i>copy on write</i> operation (<a href="qexplicitlyshareddatapointer.html#detach">detach</a>()) that non-const members of <a href="qshareddatapointer.html">QSharedDataPointer</a> do before allowing the shared data object to be modified. There is a <a href="qexplicitlyshareddatapointer.html#detach">detach</a>() function available, but if you really want to <a href="qexplicitlyshareddatapointer.html#detach">detach</a>(), 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.</p> <p>It is instructive to compare QExplicitlySharedDataPointer with <a href="qshareddatapointer.html">QSharedDataPointer</a> by way of an example. Consider the <a href="qshareddatapointer.html#employee-example">Employee example</a> in <a href="qshareddatapointer.html">QSharedDataPointer</a>, modified to use explicit sharing as explained in the discussion <a href="qshareddatapointer.html#implicit-vs-explicit-sharing">Implicit vs Explicit Sharing</a>.</p> <p>Note that if you use this class but find you are calling <a href="qexplicitlyshareddatapointer.html#detach">detach</a>() a lot, you probably should be using <a href="qshareddatapointer.html">QSharedDataPointer</a> instead.</p> <p>In the member function documentation, <i>d pointer</i> always refers to the internal pointer to the shared data object.</p> <p>See also <a href="qshareddata.html">QSharedData</a> and <a href="qshareddatapointer.html">QSharedDataPointer</a>.</p> <hr /> <h2>Member Type Documentation</h2> <a name="//apple_ref/cpp/tdef/QExplicitlySharedDataPointer/Type"></a> <h3 class="fn"><a name="Type-typedef"></a>typedef QExplicitlySharedDataPointer::Type</h3> <p>This is the type of the shared data object. The <i>d pointer</i> points to an object of this type.</p> <hr /> <h2>Member Function Documentation</h2> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/QExplicitlySharedDataPointer"></a> <h3 class="fn"><a name="QExplicitlySharedDataPointer"></a>QExplicitlySharedDataPointer::QExplicitlySharedDataPointer ()</h3> <p>Constructs a <a href="qexplicitlyshareddatapointer.html">QExplicitlySharedDataPointer</a> initialized with a null <i>d pointer</i>.</p> <h3 class="fn"><a name="QExplicitlySharedDataPointer-2"></a>QExplicitlySharedDataPointer::QExplicitlySharedDataPointer ( T * <i>sharedData</i> )</h3> <p>Constructs a <a href="qexplicitlyshareddatapointer.html">QExplicitlySharedDataPointer</a> with <i>d pointer</i> set to <i>sharedData</i> and increments <i>sharedData</i>'s reference count.</p> <h3 class="fn"><a name="QExplicitlySharedDataPointer-3"></a>QExplicitlySharedDataPointer::QExplicitlySharedDataPointer ( const QExplicitlySharedDataPointer<T> & <i>other</i> )</h3> <p>This standard copy constructor sets the <i>d pointer</i> of <i>this</i> to the <i>d pointer</i> in <i>other</i> and increments the reference count of the shared data object.</p> <h3 class="fn"><a name="QExplicitlySharedDataPointer-4"></a>QExplicitlySharedDataPointer::QExplicitlySharedDataPointer ( const QExplicitlySharedDataPointer<X> & <i>other</i> )</h3> <p>This copy constructor is different in that it allows <i>other</i> 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 <i>d pointer</i> in <i>other</i> and sets the <i>d pointer</i> of <i>this</i> to the converted <i>d pointer</i>. It increments the reference count of the shared data object.</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/~QExplicitlySharedDataPointer"></a> <h3 class="fn"><a name="dtor.QExplicitlySharedDataPointer"></a>QExplicitlySharedDataPointer::~QExplicitlySharedDataPointer ()</h3> <p>Decrements the reference count of the shared data object. If the reference count becomes 0, the shared data object is deleted. <i>This</i> is then destroyed.</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/clone"></a> <h3 class="fn"><a name="clone"></a>T * QExplicitlySharedDataPointer::clone () <tt> [protected]</tt></h3> <p>Creates and returns a deep copy of the current data. This function is called by <a href="qexplicitlyshareddatapointer.html#detach">detach</a>() when the reference count is greater than 1 in order to create the new copy. This function uses the <i>operator new</i> and calls the copy constructor of the type T.</p> <p>See <a href="qshareddatapointer.html#clone">QSharedDataPointer::clone</a>() for an explanation of how to use it.</p> <p>This function was introduced in Qt 4.5.</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/constData"></a> <h3 class="fn"><a name="constData"></a>const T * QExplicitlySharedDataPointer::constData () const</h3> <p>Returns a const pointer to the shared data object.</p> <p>See also <a href="qexplicitlyshareddatapointer.html#data">data</a>().</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/data"></a> <h3 class="fn"><a name="data"></a>T * QExplicitlySharedDataPointer::data () const</h3> <p>Returns a pointer to the shared data object.</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/detach"></a> <h3 class="fn"><a name="detach"></a>void QExplicitlySharedDataPointer::detach ()</h3> <p>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 <i>d pointer</i> of <i>this</i> to the copy.</p> <p>Because <a href="qexplicitlyshareddatapointer.html">QExplicitlySharedDataPointer</a> does not do the automatic <i>copy on write</i> operations that members of <a href="qshareddatapointer.html">QSharedDataPointer</a> do, detach() is <i>not</i> called automatically anywhere in the member functions of this class. If you find that you are calling detach() everywhere in your code, consider using <a href="qshareddatapointer.html">QSharedDataPointer</a> instead.</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/reset"></a> <h3 class="fn"><a name="reset"></a>void QExplicitlySharedDataPointer::reset ()</h3> <p>Resets <i>this</i> to be null. i.e., this function sets the <i>d pointer</i> of <i>this</i> 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.</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/swap"></a> <h3 class="fn"><a name="swap"></a>void QExplicitlySharedDataPointer::swap ( QExplicitlySharedDataPointer & <i>other</i> )</h3> <p>Swap this instance's explicitly shared data pointer with the explicitly shared data pointer in <i>other</i>.</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/operator bool"></a> <h3 class="fn"><a name="operator-bool"></a>QExplicitlySharedDataPointer::operator bool () const</h3> <p>Returns true if the <i>d pointer</i> of <i>this</i> is <i>not</i> null.</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/operator!"></a> <h3 class="fn"><a name="operator-not"></a>bool QExplicitlySharedDataPointer::operator! () const</h3> <p>Returns true if the <i>d pointer</i> of <i>this</i> is null.</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/operator!="></a> <h3 class="fn"><a name="operator-not-eq"></a>bool QExplicitlySharedDataPointer::operator!= ( const QExplicitlySharedDataPointer<T> & <i>other</i> ) const</h3> <p>Returns true if <i>other</i> and <i>this</i> do <i>not</i> have the same <i>d pointer</i>.</p> <h3 class="fn"><a name="operator-not-eq-2"></a>bool QExplicitlySharedDataPointer::operator!= ( const T * <i>ptr</i> ) const</h3> <p>Returns true if the <i>d pointer</i> of <i>this</i> is <i>not</i> <i>ptr</i>.</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/operator*"></a> <h3 class="fn"><a name="operator-2a"></a>T & QExplicitlySharedDataPointer::operator* () const</h3> <p>Provides access to the shared data object's members.</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/operator->"></a> <h3 class="fn"><a name="operator--gt"></a>T * QExplicitlySharedDataPointer::operator-> ()</h3> <p>Provides access to the shared data object's members.</p> <h3 class="fn"><a name="operator--gt-2"></a>T * QExplicitlySharedDataPointer::operator-> () const</h3> <p>Provides const access to the shared data object's members.</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/operator="></a> <h3 class="fn"><a name="operator-eq"></a>QExplicitlySharedDataPointer<T> & QExplicitlySharedDataPointer::operator= ( const QExplicitlySharedDataPointer<T> & <i>other</i> )</h3> <p>Sets the <i>d pointer</i> of <i>this</i> to the <i>d pointer</i> of <i>other</i> and increments the reference count of the shared data object. The reference count of the old shared data object of <i>this</i> is decremented. If the reference count of the old shared data object becomes 0, the old shared data object is deleted.</p> <h3 class="fn"><a name="operator-eq-2"></a>QExplicitlySharedDataPointer & QExplicitlySharedDataPointer::operator= ( T * <i>sharedData</i> )</h3> <p>Sets the <i>d pointer</i> of <i>this</i> to <i>sharedData</i> and increments <i>sharedData</i>'s reference count. The reference count of the old shared data object of <i>this</i> is decremented. If the reference count of the old shared data object becomes 0, the old shared data object is deleted.</p> <a name="//apple_ref/cpp/instm/QExplicitlySharedDataPointer/operator=="></a> <h3 class="fn"><a name="operator-eq-eq"></a>bool QExplicitlySharedDataPointer::operator== ( const QExplicitlySharedDataPointer<T> & <i>other</i> ) const</h3> <p>Returns true if <i>other</i> and <i>this</i> have the same <i>d pointer</i>.</p> <h3 class="fn"><a name="operator-eq-eq-2"></a>bool QExplicitlySharedDataPointer::operator== ( const T * <i>ptr</i> ) const</h3> <p>Returns true if the <i>d pointer</i> of <i>this</i> is <i>ptr</i>.</p> <p /><address><hr /><div align="center"> <table width="100%" cellspacing="0" border="0"><tr class="address"> <td width="40%" align="left">Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies)</td> <td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td> <td width="40%" align="right"><div align="right">Qt 4.6.3</div></td> </tr></table></div></address></body> </html>