Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > e40b0b2b839eccdb3c85993a7b738115 > files > 33

gtkmm-documentation-3.24.0-1.mga7.noarch.rpm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Appendix A. The RefPtr smartpointer</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Programming with gtkmm 3">
<link rel="up" href="index.html" title="Programming with gtkmm 3">
<link rel="prev" href="chapter-contributing.html" title="Chapter 32. Contributing">
<link rel="next" href="sec-refptr-dereferencing.html" title="Dereferencing">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Appendix A. The RefPtr smartpointer</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="chapter-contributing.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center"> </th>
<td width="20%" align="right"> <a accesskey="n" href="sec-refptr-dereferencing.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="appendix">
<div class="titlepage"><div><div><h1 class="title">
<a name="chapter-refptr"></a>Appendix A. The RefPtr smartpointer</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<ul class="toc">
<li><span class="sect1"><a href="chapter-refptr.html#sec-refptr-copying">Copying</a></span></li>
<li><span class="sect1"><a href="sec-refptr-dereferencing.html">Dereferencing</a></span></li>
<li><span class="sect1"><a href="sec-refptr-casting.html">Casting</a></span></li>
<li><span class="sect1"><a href="sec-refptr-checking-for-null.html">Checking for null</a></span></li>
<li><span class="sect1"><a href="sec-refptr-constness.html">Constness</a></span></li>
</ul>
</div>
<p>
<code class="classname">Glib::RefPtr</code> is a smartpointer. Specifically, it is a
reference-counting smartpointer. You might be familiar with
<code class="classname">std::auto_ptr&lt;&gt;</code>, <code class="classname">std::unique_ptr&lt;&gt;</code>
and <code class="classname">std::shared_ptr&lt;&gt;</code>, which are also smartpointers.
<code class="classname">Glib::RefPtr&lt;&gt;</code> is similar to <code class="classname">std::shared_ptr&lt;&gt;</code>,
which is also reference-counting. <code class="classname">Glib::RefPtr&lt;&gt;</code> was introduced
long before there was a reference-counting smartpointer in the C++ Standard Library.
</p>
<p><a class="ulink" href="http://developer.gnome.org/glibmm/2.58/classGlib_1_1RefPtr.html" target="_top">Reference</a></p>
<p>A smartpointer acts much like a normal pointer. Here are a few examples.</p>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-refptr-copying"></a>Copying</h2></div></div></div>
<p>
You can copy <code class="classname">RefPtr</code>s, just like normal pointers. But
unlike normal pointers, you don't need to worry about deleting the underlying
instance.
</p>
<p>
</p>
<pre class="programlisting">
Glib::RefPtr&lt;Gdk::Pixbuf&gt; refPixbuf = Gdk::Pixbuf::create_from_file(filename);
Glib::RefPtr&lt;Gdk::Pixbuf&gt; refPixbuf2 = refPixbuf;
</pre>
<p>
</p>
<p>
Of course this means that you can store <code class="classname">RefPtr</code>s in
standard containers, such as <code class="classname">std::vector</code> or
<code class="classname">std::list</code>.</p>
<p>
</p>
<pre class="programlisting">
std::list&lt; Glib::RefPtr&lt;Gdk::Pixbuf&gt; &gt; listPixbufs;
Glib::RefPtr&lt;Gdk::Pixbuf&gt; refPixbuf = Gdk::Pixbuf::create_from_file(filename);
listPixbufs.push_back(refPixbuf);
</pre>
<p>
</p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="chapter-contributing.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"> </td>
<td width="40%" align="right"> <a accesskey="n" href="sec-refptr-dereferencing.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter 32. Contributing </td>
<td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> Dereferencing</td>
</tr>
</table>
</div>
</body>
</html>