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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Class Poco::SharedPtr</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="author" content="Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="publisher" content="Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="copyright" content="Copyright (c) 2009, Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="language" content="en"/>
<meta name="date" content="2009-11-24"/>
<meta name="generator" content="PocoDoc"/>
<link rel="stylesheet" href="css/styles.css" type="text/css"/>
</head>
<body bgcolor="#ffffff" leftmargin="0" topmargin="0">
<div class="header">
<h1 class="namespace"><a href="Poco.html" class="namespace">Poco</a></h1>
<h1 class="template">template < class C, class RC = ReferenceCounter, class RP = ReleasePolicy < C > ></h1>
<h1 class="symbol">class SharedPtr</h1>
</div>
<div class="body">
<p>
<b>Library:</b> Foundation<br />
<b>Package:</b> Core<br />
<b>Header:</b> Poco/SharedPtr.h</p>
<h2>Description</h2>
<div class="description">
<p><a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> is a "smart" pointer for classes implementing reference counting based garbage collection. <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> is thus similar to <a href="Poco.AutoPtr.html" title="class Poco::AutoPtr">AutoPtr</a>. Unlike the <a href="Poco.AutoPtr.html" title="class Poco::AutoPtr">AutoPtr</a> template, which can only be used with classes that support reference counting, <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> can be used with any class. For this to work, a <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> manages a reference count for the object it manages. </p>
<p><a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> works in the following way: If an <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> is assigned an ordinary pointer to an object (via the constructor or the assignment operator), it takes ownership of the object and the object's reference count is initialized to one. If the <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> is assigned another <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a>, the object's reference count is incremented by one. The destructor of <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> decrements the object's reference count by one and deletes the object if the reference count reaches zero. <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> supports dereferencing with both the -> and the * operator. An attempt to dereference a null <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> results in a <a href="Poco.NullPointerException.html" title="class Poco::NullPointerException">NullPointerException</a> being thrown. <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> also implements all relational operators and a cast operator in case dynamic casting of the encapsulated data types is required. </p>
</div>
<h2>Member Summary</h2>
<p><b>Member Functions: </b><a href="Poco.SharedPtr.html#9970" title="Poco::SharedPtr::assign()">assign</a>, <a href="Poco.SharedPtr.html#9988" title="Poco::SharedPtr::cast()">cast</a>, <a href="Poco.SharedPtr.html#9994" title="Poco::SharedPtr::get()">get</a>, <a href="Poco.SharedPtr.html#9999" title="Poco::SharedPtr::isNull()">isNull</a>, <a href="Poco.SharedPtr.html#9998" title="Poco::SharedPtr::operator !()">operator !</a>, <a href="Poco.SharedPtr.html#10006" title="Poco::SharedPtr::operator !=()">operator !=</a>, <a href="Poco.SharedPtr.html#9992" title="Poco::SharedPtr::operator *()">operator *</a>, <a href="Poco.SharedPtr.html#10012" title="Poco::SharedPtr::operator <()">operator <</a>, <a href="Poco.SharedPtr.html#10018" title="Poco::SharedPtr::operator <=()">operator <=</a>, <a href="Poco.SharedPtr.html#9978" title="Poco::SharedPtr::operator =()">operator =</a>, <a href="Poco.SharedPtr.html#10000" title="Poco::SharedPtr::operator ==()">operator ==</a>, <a href="Poco.SharedPtr.html#10024" title="Poco::SharedPtr::operator >()">operator ></a>, <a href="Poco.SharedPtr.html#10030" title="Poco::SharedPtr::operator >=()">operator >=</a>, <a href="Poco.SharedPtr.html#9996" title="Poco::SharedPtr::operator C *()">operator C *</a>, <a href="Poco.SharedPtr.html#9997" title="Poco::SharedPtr::operator const C *()">operator const C *</a>, <a href="Poco.SharedPtr.html#9990" title="Poco::SharedPtr::operator->()">operator-></a>, <a href="Poco.SharedPtr.html#10036" title="Poco::SharedPtr::referenceCount()">referenceCount</a>, <a href="Poco.SharedPtr.html#9986" title="Poco::SharedPtr::swap()">swap</a>, <a href="Poco.SharedPtr.html#9989" title="Poco::SharedPtr::unsafeCast()">unsafeCast</a></p>
<h2>Constructors</h2>
<h3><a name="9960">SharedPtr</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl"><a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a>();</p>
<div class="description">
<p></p>
</div>
<h3><a name="9961">SharedPtr</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl"><a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a>(<br /> C * ptr<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="9967">SharedPtr</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl"><a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a>(<br /> const <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & ptr<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="9963">SharedPtr</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">template < class Other, class OtherRP > <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a>(<br /> const <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> < Other,<br /> RC,<br /> OtherRP > & ptr<br />);</p>
<div class="description">
<p></p>
</div>
<h2>Destructor</h2>
<h3><a name="9969">~SharedPtr</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">~<a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a>();</p>
<div class="description">
<p></p>
</div>
<h2>Member Functions</h2>
<h3><a name="9970">assign</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl"><a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & assign(<br /> C * ptr<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="9972">assign</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl"><a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & assign(<br /> const <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & ptr<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="9974">assign</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">template < class Other, class OtherRP > <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & assign(<br /> const <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> < Other,<br /> RC,<br /> OtherRP > & ptr<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="9988">cast</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">template < class Other > <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> < Other, RC, RP > cast() const;</p>
<div class="description">
<p>Casts the <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> via a dynamic cast to the given type. Returns an <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> containing NULL if the cast fails. Example: (assume class Sub: public Super) </p>
<pre>SharedPtr<Super> super(new Sub());
SharedPtr<Sub> sub = super.cast<Sub>();
poco_assert (sub.get());
</pre>
</div>
<h3><a name="9994">get</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">C * get();</p>
<div class="description">
<p></p>
</div>
<h3><a name="9995">get</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">const C * get() const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="9999">isNull</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool isNull() const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="9998">operator !</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator ! () const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10006">operator !=</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator != (<br /> const <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10008">operator !=</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator != (<br /> const C * ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10010">operator !=</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator != (<br /> C * ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="9992">operator *</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">C & operator * ();</p>
<div class="description">
<p></p>
</div>
<h3><a name="9993">operator *</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">const C & operator * () const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10012">operator <</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator < (<br /> const <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10014">operator <</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator < (<br /> const C * ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10016">operator <</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator < (<br /> C * ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10018">operator <=</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator <= (<br /> const <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10020">operator <=</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator <= (<br /> const C * ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10022">operator <=</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator <= (<br /> C * ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="9978">operator =</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl"><a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & operator = (<br /> C * ptr<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="9980">operator =</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl"><a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & operator = (<br /> const <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & ptr<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="9982">operator =</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">template < class Other, class OtherRP > <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & operator = (<br /> const <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> < Other,<br /> RC,<br /> OtherRP > & ptr<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="10000">operator ==</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator == (<br /> const <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10002">operator ==</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator == (<br /> const C * ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10004">operator ==</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator == (<br /> C * ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10024">operator ></a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator > (<br /> const <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10026">operator ></a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator > (<br /> const C * ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10028">operator ></a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator > (<br /> C * ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10030">operator >=</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator >= (<br /> const <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10032">operator >=</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator >= (<br /> const C * ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10034">operator >=</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">bool operator >= (<br /> C * ptr<br />) const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="9996">operator C *</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">operator C * ();</p>
<div class="description">
<p></p>
</div>
<h3><a name="9997">operator const C *</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">operator const C * () const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="9990">operator-></a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">C * operator-> ();</p>
<div class="description">
<p></p>
</div>
<h3><a name="9991">operator-></a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">const C * operator-> () const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="10036">referenceCount</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">int referenceCount() const;</p>
<div class="description">
<p></p>
</div>
<h3><a name="9986">swap</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">void swap(<br /> <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> & ptr<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="9989">unsafeCast</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">template < class Other > <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> < Other, RC, RP > unsafeCast() const;</p>
<div class="description">
<p>Casts the <a href="Poco.SharedPtr.html" title="class Poco::SharedPtr">SharedPtr</a> via a static cast to the given type. Example: (assume class Sub: public Super) </p>
<pre>SharedPtr<Super> super(new Sub());
SharedPtr<Sub> sub = super.unsafeCast<Sub>();
poco_assert (sub.get());
</pre>
</div>
<p class="footer">POCO C++ Libraries 1.3.6-all<br />
Copyright © 2009, <a href="http://pocoproject.org/" target="_blank">Applied Informatics Software Engineering GmbH and Contributors</a></p>
</div>
</body>
</html>
|