Files
smart_ptr/intrusive_ref_counter.html

93 lines
5.3 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>basic_intrusive_ref_counter</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body text="#000000" bgColor="#ffffff">
<h1><A href="../../index.htm"><IMG height="86" alt="boost.png (6897 bytes)" src="../../boost.png" width="277" align="middle"
border="0"></A>basic_intrusive_ref_counter class template</h1>
<p>
<A href="#Introduction">Introduction</A><br>
<A href="#Synopsis">Synopsis</A><br>
<A href="#Members">Members</A><br>
</p>
<h2><a name="Introduction">Introduction</a></h2>
<p>The <STRONG>basic_intrusive_ref_counter</STRONG> class template implements a reference counter for a defived
user&apos;s class that is intended to be used with <STRONG><a href="intrusive_ptr.html">intrusive_ptr</a></STRONG>.
The base class has associated <STRONG>intrusive_ptr_add_ref</STRONG> and <STRONG>intrusive_ptr_release</STRONG> functions
which modify the reference counter as needed and destroy the user's object when the counter drops to zero.</p>
<p>The class template is parameterized on <STRONG>CounterPolicyT</STRONG>, which is a policy that defines the nature of the reference counter.
Boost.SmartPtr provides two such policies: <STRONG>thread_unsafe_counter</STRONG> and <STRONG>thread_safe_counter</STRONG>. The former
instructs the <STRONG>basic_intrusive_ref_counter</STRONG> base class to use a counter only suitable for a single-threaded use.
Pointers to a single object that uses this kind of reference counter must not be used in different threads. The latter policy
makes the reference counter thread-safe, unless the target platform doesn't support threading. Since in modern systems support for
threading is common, a shorthand <STRONG>intrusive_ref_counter</STRONG> is provided, which is an alias for
<STRONG>basic_intrusive_ref_counter&lt;thread_safe_counter&gt;</STRONG>.</p>
<h2><a name="Synopsis">Synopsis</a></h2>
<pre>namespace boost {
template&lt;class CounterPolicyT&gt; class basic_intrusive_ref_counter {
public:
<A href="#constructors" >basic_intrusive_ref_counter</A>();
<A href="#constructors" >basic_intrusive_ref_counter</A>(basic_intrusive_ref_counter const &amp; r);
virtual <A href="#destructor" >~basic_intrusive_ref_counter</A>();
basic_intrusive_ref_counter &amp; <A href="#assignment" >operator=</A>(basic_intrusive_ref_counter const &amp; r) noexcept;
unsigned int <a href="#use_count" >use_count</a>() const noexcept;
};
struct thread_unsafe_counter;
struct thread_safe_counter;
typedef basic_intrusive_ref_counter&lt;thread_safe_counter&gt; intrusive_ref_counter;
}</pre>
<h2><a name="Members">Members</a></h2>
<h3><a name="constructors">constructors</a></h3>
<pre>basic_intrusive_ref_counter();</pre>
<blockquote>
<p><b>Postconditions:</b> <code>use_count() == 0</code>.</p>
<p><b>Throws:</b> nothing.</p>
<P><B>Notes:</B> The pointer to the constructed object is expected to be passed to <STRONG>intrusive_ptr</STRONG>
constructor, assignment operator or <STRONG>reset()</STRONG> method, which would increment the reference counter.</P>
</blockquote>
<pre>basic_intrusive_ref_counter(basic_intrusive_ref_counter const &amp;);</pre>
<blockquote>
<p><b>Postconditions:</b> <code>use_count() == 0</code>.</p>
<p><b>Throws:</b> nothing.</p>
<P><B>Notes:</B> The pointer to the constructed object is expected to be passed to <STRONG>intrusive_ptr</STRONG>
constructor, assignment operator or <STRONG>reset()</STRONG> method, which would increment the reference counter.</P>
</blockquote>
<h3><a name="destructor">destructor</a></h3>
<pre>virtual ~basic_intrusive_ref_counter();</pre>
<BLOCKQUOTE>
<P><B>Effects:</B> Destroys the counter object.</P>
</BLOCKQUOTE>
<H3><a name="assignment">assignment</a></H3>
<pre>basic_intrusive_ref_counter &amp; operator=(basic_intrusive_ref_counter const &amp; r) noexcept;</pre>
<BLOCKQUOTE>
<P><B>Effects:</B> Does nothing, reference counter is not modified.</P>
<P><B>Returns:</B> <code>*this</code>.</P>
</BLOCKQUOTE>
<H3><a name="use_count">use_count</a></H3>
<pre>unsigned int use_count() const noexcept;</pre>
<BLOCKQUOTE>
<p><b>Returns:</b> The current value of the reference counter.</p>
<p><b>Throws:</b> nothing.</p>
<P><B>Notes:</B> The returned value may not be actual in multi-threaded applications.</P>
</BLOCKQUOTE>
<hr>
<p>
$Date: 2013-08-31 23:37:43 +0400 (Sat, 31 Aug 2013) $</p>
<p>
<small>Copyright © 2013 Andrey Semashev. Distributed under the Boost Software License, Version
1.0. See accompanying file <A href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</A> or
copy at <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>.</small></p>
</body>
</html>