1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qshareddata.cpp -->
<title>Qt 4.8: QExplicitlySharedDataPointer Class Reference</title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="content">
<a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
</div>
<div class="breadcrumb toolblock">
<ul>
<li class="first"><a href="index.html">Home</a></li>
<!-- Breadcrumbs go here -->
<li><a href="modules.html">Modules</a></li>
<li><a href="qtcore.html">QtCore</a></li>
<li>QExplicitlySharedDataPointer</li>
</ul>
</div>
</div>
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-types">Public Types</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#protected-functions">Protected Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<h1 class="title">QExplicitlySharedDataPointer Class Reference</h1>
<!-- $$$QExplicitlySharedDataPointer-brief -->
<p>The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object. <a href="#details">More...</a></p>
<!-- @@@QExplicitlySharedDataPointer -->
<pre class="cpp"> <span class="preprocessor">#include <QExplicitlySharedDataPointer></span></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>
<a name="public-types"></a>
<h2>Public Types</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#Type-typedef">Type</a></b></td></tr>
</table>
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#QExplicitlySharedDataPointer">QExplicitlySharedDataPointer</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#QExplicitlySharedDataPointer-2">QExplicitlySharedDataPointer</a></b> ( T * <i>sharedData</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#QExplicitlySharedDataPointer-3">QExplicitlySharedDataPointer</a></b> ( const QExplicitlySharedDataPointer<T> & <i>other</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#QExplicitlySharedDataPointer-4">QExplicitlySharedDataPointer</a></b> ( const QExplicitlySharedDataPointer<X> & <i>other</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#dtor.QExplicitlySharedDataPointer">~QExplicitlySharedDataPointer</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const T * </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#constData">constData</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> T * </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#data">data</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#detach">detach</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#reset">reset</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#swap">swap</a></b> ( QExplicitlySharedDataPointer & <i>other</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#operator-bool">operator bool</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#operator-not">operator!</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#operator-not-eq">operator!=</a></b> ( const QExplicitlySharedDataPointer<T> & <i>other</i> ) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#operator-not-eq-2">operator!=</a></b> ( const T * <i>ptr</i> ) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> T & </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#operator-2a">operator*</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> T * </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#operator--gt">operator-></a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> T * </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#operator--gt-2">operator-></a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QExplicitlySharedDataPointer<T> & </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#operator-eq">operator=</a></b> ( const QExplicitlySharedDataPointer<T> & <i>other</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QExplicitlySharedDataPointer & </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#operator-eq-2">operator=</a></b> ( T * <i>sharedData</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#operator-eq-eq">operator==</a></b> ( const QExplicitlySharedDataPointer<T> & <i>other</i> ) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#operator-eq-eq-2">operator==</a></b> ( const T * <i>ptr</i> ) const</td></tr>
</table>
<a name="protected-functions"></a>
<h2>Protected Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> T * </td><td class="memItemRight bottomAlign"><b><a href="qexplicitlyshareddatapointer.html#clone">clone</a></b> ()</td></tr>
</table>
<a name="details"></a>
<!-- $$$QExplicitlySharedDataPointer-description -->
<div class="descr">
<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>
</div>
<p><b>See also </b><a href="qshareddata.html">QSharedData</a> and <a href="qshareddatapointer.html">QSharedDataPointer</a>.</p>
<!-- @@@QExplicitlySharedDataPointer -->
<div class="types">
<h2>Member Type Documentation</h2>
<!-- $$$Type -->
<h3 class="fn"><a name="Type-typedef"></a>typedef QExplicitlySharedDataPointer::<span class="name">Type</span></h3>
<p>This is the type of the shared data object. The <i>d pointer</i> points to an object of this type.</p>
<!-- @@@Type -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QExplicitlySharedDataPointer[overload1]$$$QExplicitlySharedDataPointer -->
<h3 class="fn"><a name="QExplicitlySharedDataPointer"></a>QExplicitlySharedDataPointer::<span class="name">QExplicitlySharedDataPointer</span> ()</h3>
<p>Constructs a <a href="qexplicitlyshareddatapointer.html">QExplicitlySharedDataPointer</a> initialized with a null <i>d pointer</i>.</p>
<!-- @@@QExplicitlySharedDataPointer -->
<!-- $$$QExplicitlySharedDataPointer$$$QExplicitlySharedDataPointerT* -->
<h3 class="fn"><a name="QExplicitlySharedDataPointer-2"></a>QExplicitlySharedDataPointer::<span class="name">QExplicitlySharedDataPointer</span> ( <span class="type">T</span> * <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>
<!-- @@@QExplicitlySharedDataPointer -->
<!-- $$$QExplicitlySharedDataPointer$$$QExplicitlySharedDataPointerconstQExplicitlySharedDataPointer<T>& -->
<h3 class="fn"><a name="QExplicitlySharedDataPointer-3"></a>QExplicitlySharedDataPointer::<span class="name">QExplicitlySharedDataPointer</span> ( const <span class="type">QExplicitlySharedDataPointer</span><<span class="type">T</span>> & <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>
<!-- @@@QExplicitlySharedDataPointer -->
<!-- $$$QExplicitlySharedDataPointer$$$QExplicitlySharedDataPointerconstQExplicitlySharedDataPointer<X>& -->
<h3 class="fn"><a name="QExplicitlySharedDataPointer-4"></a>QExplicitlySharedDataPointer::<span class="name">QExplicitlySharedDataPointer</span> ( const <span class="type">QExplicitlySharedDataPointer</span><<span class="type">X</span>> & <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>
<!-- @@@QExplicitlySharedDataPointer -->
<!-- $$$~QExplicitlySharedDataPointer[overload1]$$$~QExplicitlySharedDataPointer -->
<h3 class="fn"><a name="dtor.QExplicitlySharedDataPointer"></a>QExplicitlySharedDataPointer::<span class="name">~QExplicitlySharedDataPointer</span> ()</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>
<!-- @@@~QExplicitlySharedDataPointer -->
<!-- $$$clone[overload1]$$$clone -->
<h3 class="fn"><a name="clone"></a><span class="type">T</span> * QExplicitlySharedDataPointer::<span class="name">clone</span> ()<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>
<!-- @@@clone -->
<!-- $$$constData[overload1]$$$constData -->
<h3 class="fn"><a name="constData"></a>const <span class="type">T</span> * QExplicitlySharedDataPointer::<span class="name">constData</span> () const</h3>
<p>Returns a const pointer to the shared data object.</p>
<p><b>See also </b><a href="qexplicitlyshareddatapointer.html#data">data</a>().</p>
<!-- @@@constData -->
<!-- $$$data[overload1]$$$data -->
<h3 class="fn"><a name="data"></a><span class="type">T</span> * QExplicitlySharedDataPointer::<span class="name">data</span> () const</h3>
<p>Returns a pointer to the shared data object.</p>
<!-- @@@data -->
<!-- $$$detach[overload1]$$$detach -->
<h3 class="fn"><a name="detach"></a><span class="type">void</span> QExplicitlySharedDataPointer::<span class="name">detach</span> ()</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>
<!-- @@@detach -->
<!-- $$$reset[overload1]$$$reset -->
<h3 class="fn"><a name="reset"></a><span class="type">void</span> QExplicitlySharedDataPointer::<span class="name">reset</span> ()</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>
<!-- @@@reset -->
<!-- $$$swap[overload1]$$$swapQExplicitlySharedDataPointer& -->
<h3 class="fn"><a name="swap"></a><span class="type">void</span> QExplicitlySharedDataPointer::<span class="name">swap</span> ( <span class="type">QExplicitlySharedDataPointer</span> & <i>other</i> )</h3>
<p>Swap this instance's explicitly shared data pointer with the explicitly shared data pointer in <i>other</i>.</p>
<!-- @@@swap -->
<!-- $$$operator bool[overload1]$$$operator bool -->
<h3 class="fn"><a name="operator-bool"></a>QExplicitlySharedDataPointer::<span class="name">operator bool</span> () const</h3>
<p>Returns true if the <i>d pointer</i> of <i>this</i> is <i>not</i> null.</p>
<!-- @@@operator bool -->
<!-- $$$operator![overload1]$$$operator! -->
<h3 class="fn"><a name="operator-not"></a><span class="type">bool</span> QExplicitlySharedDataPointer::<span class="name">operator!</span> () const</h3>
<p>Returns true if the <i>d pointer</i> of <i>this</i> is null.</p>
<!-- @@@operator! -->
<!-- $$$operator!=[overload1]$$$operator!=constQExplicitlySharedDataPointer<T>& -->
<h3 class="fn"><a name="operator-not-eq"></a><span class="type">bool</span> QExplicitlySharedDataPointer::<span class="name">operator!=</span> ( const <span class="type">QExplicitlySharedDataPointer</span><<span class="type">T</span>> & <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>
<!-- @@@operator!= -->
<!-- $$$operator!=$$$operator!=constT* -->
<h3 class="fn"><a name="operator-not-eq-2"></a><span class="type">bool</span> QExplicitlySharedDataPointer::<span class="name">operator!=</span> ( const <span class="type">T</span> * <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>
<!-- @@@operator!= -->
<!-- $$$operator*[overload1]$$$operator* -->
<h3 class="fn"><a name="operator-2a"></a><span class="type">T</span> & QExplicitlySharedDataPointer::<span class="name">operator*</span> () const</h3>
<p>Provides access to the shared data object's members.</p>
<!-- @@@operator* -->
<!-- $$$operator->[overload1]$$$operator-> -->
<h3 class="fn"><a name="operator--gt"></a><span class="type">T</span> * QExplicitlySharedDataPointer::<span class="name">operator-></span> ()</h3>
<p>Provides access to the shared data object's members.</p>
<!-- @@@operator-> -->
<!-- $$$operator->$$$operator-> -->
<h3 class="fn"><a name="operator--gt-2"></a><span class="type">T</span> * QExplicitlySharedDataPointer::<span class="name">operator-></span> () const</h3>
<p>Provides const access to the shared data object's members.</p>
<!-- @@@operator-> -->
<!-- $$$operator=[overload1]$$$operator=constQExplicitlySharedDataPointer<T>& -->
<h3 class="fn"><a name="operator-eq"></a><span class="type">QExplicitlySharedDataPointer</span><<span class="type">T</span>> & QExplicitlySharedDataPointer::<span class="name">operator=</span> ( const <span class="type">QExplicitlySharedDataPointer</span><<span class="type">T</span>> & <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>
<!-- @@@operator= -->
<!-- $$$operator=$$$operator=T* -->
<h3 class="fn"><a name="operator-eq-2"></a><span class="type">QExplicitlySharedDataPointer</span> & QExplicitlySharedDataPointer::<span class="name">operator=</span> ( <span class="type">T</span> * <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>
<!-- @@@operator= -->
<!-- $$$operator==[overload1]$$$operator==constQExplicitlySharedDataPointer<T>& -->
<h3 class="fn"><a name="operator-eq-eq"></a><span class="type">bool</span> QExplicitlySharedDataPointer::<span class="name">operator==</span> ( const <span class="type">QExplicitlySharedDataPointer</span><<span class="type">T</span>> & <i>other</i> ) const</h3>
<p>Returns true if <i>other</i> and <i>this</i> have the same <i>d pointer</i>.</p>
<!-- @@@operator== -->
<!-- $$$operator==$$$operator==constT* -->
<h3 class="fn"><a name="operator-eq-eq-2"></a><span class="type">bool</span> QExplicitlySharedDataPointer::<span class="name">operator==</span> ( const <span class="type">T</span> * <i>ptr</i> ) const</h3>
<p>Returns true if the <i>d pointer</i> of <i>this</i> is <i>ptr</i>.</p>
<!-- @@@operator== -->
</div>
<div class="ft">
<span></span>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2012 Nokia Corporation and/or its
subsidiaries. Documentation contributions included herein are the copyrights of
their respective owners.</p>
<br />
<p>
The documentation provided herein is licensed under the terms of the
<a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
License version 1.3</a> as published by the Free Software Foundation.</p>
<p>
Documentation sources may be obtained from <a href="http://www.qt-project.org">
www.qt-project.org</a>.</p>
<br />
<p>
Nokia, Qt and their respective logos are trademarks of Nokia Corporation
in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. <a title="Privacy Policy"
href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>
|