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
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Class template weak_ptr</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../../boost_interprocess_reference.html#header.boost.interprocess.smart_ptr.weak_ptr_hpp" title="Header <boost/interprocess/smart_ptr/weak_ptr.hpp>">
<link rel="prev" href="make_managed_unique_ptr.html" title="Function template make_managed_unique_ptr">
<link rel="next" href="managed_weak_ptr.html" title="Struct template managed_weak_ptr">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="make_managed_unique_ptr.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_interprocess_reference.html#header.boost.interprocess.smart_ptr.weak_ptr_hpp"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="managed_weak_ptr.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>
</div>
<div class="refentry" title="Class template weak_ptr">
<a name="boost.interprocess.weak_ptr"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Class template weak_ptr</span></h2>
<p>boost::interprocess::weak_ptr</p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="emphasis"><em>// In header: <<a class="link" href="../../boost_interprocess_reference.html#header.boost.interprocess.smart_ptr.weak_ptr_hpp" title="Header <boost/interprocess/smart_ptr/weak_ptr.hpp>">boost/interprocess/smart_ptr/weak_ptr.hpp</a>>
</em></span><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T, <span class="bold"><strong>typename</strong></span> A, <span class="bold"><strong>typename</strong></span> D>
<span class="bold"><strong>class</strong></span> <a class="link" href="weak_ptr.html" title="Class template weak_ptr">weak_ptr</a> {
<span class="bold"><strong>public</strong></span>:
<span class="emphasis"><em>// types</em></span>
<span class="bold"><strong>typedef</strong></span> T <a name="boost.interprocess.weak_ptr.element_type"></a>element_type;
<span class="bold"><strong>typedef</strong></span> T <a name="boost.interprocess.weak_ptr.value_type"></a>value_type;
<span class="emphasis"><em>// <a class="link" href="weak_ptr.html#boost.interprocess.weak_ptrconstruct-copy-destruct">construct/copy/destruct</a></em></span>
<a class="link" href="weak_ptr.html#id819097-bb">weak_ptr</a>();
<span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Y> <a class="link" href="weak_ptr.html#id819103-bb">weak_ptr</a>(<a class="link" href="weak_ptr.html" title="Class template weak_ptr">weak_ptr</a>< Y, A, D > <span class="bold"><strong>const</strong></span> &);
<span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Y> <a class="link" href="weak_ptr.html#id819131-bb">weak_ptr</a>(<a class="link" href="shared_ptr.html" title="Class template shared_ptr">shared_ptr</a>< Y, A, D > <span class="bold"><strong>const</strong></span> &);
<span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Y> weak_ptr& <a class="link" href="weak_ptr.html#id819159-bb"><span class="bold"><strong>operator</strong></span>=</a>(<a class="link" href="weak_ptr.html" title="Class template weak_ptr">weak_ptr</a>< Y, A, D > <span class="bold"><strong>const</strong></span> &);
<span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Y> weak_ptr& <a class="link" href="weak_ptr.html#id819186-bb"><span class="bold"><strong>operator</strong></span>=</a>(<a class="link" href="shared_ptr.html" title="Class template shared_ptr">shared_ptr</a>< Y, A, D > <span class="bold"><strong>const</strong></span> &);
<span class="emphasis"><em>// <a class="link" href="weak_ptr.html#id819007-bb">public member functions</a></em></span>
<span class="type"><a class="link" href="shared_ptr.html" title="Class template shared_ptr">shared_ptr</a>< T, A, D ></span> <a class="link" href="weak_ptr.html#id819011-bb">lock</a>() <span class="bold"><strong>const</strong></span>;
<span class="type"><span class="bold"><strong>long</strong></span></span> <a class="link" href="weak_ptr.html#id819028-bb">use_count</a>() <span class="bold"><strong>const</strong></span>;
<span class="type"><span class="bold"><strong>bool</strong></span></span> <a class="link" href="weak_ptr.html#id819048-bb">expired</a>() <span class="bold"><strong>const</strong></span>;
<span class="type"><span class="bold"><strong>void</strong></span></span> <a class="link" href="weak_ptr.html#id819065-bb">reset</a>() ;
<span class="type"><span class="bold"><strong>void</strong></span></span> <a class="link" href="weak_ptr.html#id819077-bb">swap</a>(this_type &) ;
};</pre></div>
<div class="refsect1" title="Description">
<a name="id1049697"></a><h2>Description</h2>
<p>The weak_ptr class template stores a "weak reference" to an object that's already managed by a shared_ptr. To access the object, a weak_ptr can be converted to a shared_ptr using the shared_ptr constructor or the member function lock. When the last shared_ptr to the object goes away and the object is deleted, the attempt to obtain a shared_ptr from the weak_ptr instances that refer to the deleted object will fail: the constructor will throw an exception of type bad_weak_ptr, and weak_ptr::lock will return an empty shared_ptr.</p>
<p>Every weak_ptr meets the CopyConstructible and Assignable requirements of the C++ Standard Library, and so can be used in standard library containers. Comparison operators are supplied so that weak_ptr works with the standard library's associative containers.</p>
<p>weak_ptr operations never throw exceptions.</p>
<p>The class template is parameterized on T, the type of the object pointed to. </p>
<div class="refsect2" title="weak_ptr public construct/copy/destruct">
<a name="id1049715"></a><h3>
<a name="boost.interprocess.weak_ptrconstruct-copy-destruct"></a><code class="computeroutput">weak_ptr</code>
public
construct/copy/destruct</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><a name="id819097-bb"></a>weak_ptr();</pre>
<p>Effects: Constructs an empty weak_ptr. Postconditions: use_count() == 0. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Y> <a name="id819103-bb"></a>weak_ptr(<a class="link" href="weak_ptr.html" title="Class template weak_ptr">weak_ptr</a>< Y, A, D > <span class="bold"><strong>const</strong></span> & r);</pre>
<p>Effects: If r is empty, constructs an empty weak_ptr; otherwise, constructs a weak_ptr that shares ownership with r as if by storing a copy of the pointer stored in r.</p>
<p>Postconditions: use_count() == r.use_count().</p>
<p>Throws: nothing. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Y> <a name="id819131-bb"></a>weak_ptr(<a class="link" href="shared_ptr.html" title="Class template shared_ptr">shared_ptr</a>< Y, A, D > <span class="bold"><strong>const</strong></span> & r);</pre>
<p>Effects: If r is empty, constructs an empty weak_ptr; otherwise, constructs a weak_ptr that shares ownership with r as if by storing a copy of the pointer stored in r.</p>
<p>Postconditions: use_count() == r.use_count().</p>
<p>Throws: nothing. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Y> weak_ptr& <a name="id819159-bb"></a><span class="bold"><strong>operator</strong></span>=(<a class="link" href="weak_ptr.html" title="Class template weak_ptr">weak_ptr</a>< Y, A, D > <span class="bold"><strong>const</strong></span> & r);</pre>
<p>Effects: Equivalent to weak_ptr(r).swap(*this).</p>
<p>Throws: nothing.</p>
<p>Notes: The implementation is free to meet the effects (and the implied guarantees) via different means, without creating a temporary. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Y> weak_ptr& <a name="id819186-bb"></a><span class="bold"><strong>operator</strong></span>=(<a class="link" href="shared_ptr.html" title="Class template shared_ptr">shared_ptr</a>< Y, A, D > <span class="bold"><strong>const</strong></span> & r);</pre>
<p>Effects: Equivalent to weak_ptr(r).swap(*this).</p>
<p>Throws: nothing.</p>
<p>Notes: The implementation is free to meet the effects (and the implied guarantees) via different means, without creating a temporary. </p>
</li>
</ol></div>
</div>
<div class="refsect2" title="weak_ptr public member functions">
<a name="id1049959"></a><h3>
<a name="id819007-bb"></a><code class="computeroutput">weak_ptr</code> public member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="type"><a class="link" href="shared_ptr.html" title="Class template shared_ptr">shared_ptr</a>< T, A, D ></span> <a name="id819011-bb"></a>lock() <span class="bold"><strong>const</strong></span>;</pre>
<p>Returns: expired()? shared_ptr<T>(): shared_ptr<T>(*this).</p>
<p>Throws: nothing. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="type"><span class="bold"><strong>long</strong></span></span> <a name="id819028-bb"></a>use_count() <span class="bold"><strong>const</strong></span>;</pre>
<p>Returns: 0 if *this is empty; otherwise, the number of shared_ptr objects that share ownership with *this.</p>
<p>Throws: nothing.</p>
<p>Notes: use_count() is not necessarily efficient. Use only for debugging and testing purposes, not for production code. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id819048-bb"></a>expired() <span class="bold"><strong>const</strong></span>;</pre>
<p>Returns: Returns: use_count() == 0.</p>
<p>Throws: nothing.</p>
<p>Notes: expired() may be faster than use_count(). </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id819065-bb"></a>reset() ;</pre>
<p>Effects: Equivalent to: weak_ptr().swap(*this). </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id819077-bb"></a>swap(this_type & other) ;</pre>
<p>Effects: Exchanges the contents of the two smart pointers.</p>
<p>Throws: nothing. </p>
</li>
</ol></div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2005 - 2008 Ion Gaztanaga<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="make_managed_unique_ptr.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_interprocess_reference.html#header.boost.interprocess.smart_ptr.weak_ptr_hpp"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="managed_weak_ptr.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>
</div>
</body>
</html>
|