Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/python/pyste/doc/smart_pointers.html @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 5.9 KB
Line 
1<html>
2<head>
3<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
4<title>Smart Pointers</title>
5<link rel="stylesheet" href="theme/style.css" type="text/css">
6<link rel="prev" href="exporting_an_entire_header.html">
7<link rel="next" href="global_variables.html">
8</head>
9<body>
10<table width="100%" height="48" border="0" cellspacing="2">
11  <tr>
12    <td><img src="../../../../boost.png">
13    </td>
14    <td width="85%">
15      <font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Smart Pointers</b></font>
16    </td>
17  </tr>
18</table>
19<br>
20<table border="0">
21  <tr>
22    <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
23    <td width="30"><a href="exporting_an_entire_header.html"><img src="theme/l_arr.gif" border="0"></a></td>
24    <td width="20"><a href="global_variables.html"><img src="theme/r_arr.gif" border="0"></a></td>
25   </tr>
26</table>
27<p>
28Pyste for now has manual support for smart pointers. Suppose:</p>
29<code><pre>
30    <span class=keyword>struct </span><span class=identifier>C
31    </span><span class=special>{
32        </span><span class=keyword>int </span><span class=identifier>value</span><span class=special>;
33    };
34
35    </span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>shared_ptr</span><span class=special>&lt;</span><span class=identifier>C</span><span class=special>&gt; </span><span class=identifier>newC</span><span class=special>(</span><span class=keyword>int </span><span class=identifier>value</span><span class=special>)
36    {
37        </span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>shared_ptr</span><span class=special>&lt;</span><span class=identifier>C</span><span class=special>&gt; </span><span class=identifier>c</span><span class=special>( </span><span class=keyword>new </span><span class=identifier>C</span><span class=special>() );
38        </span><span class=identifier>c</span><span class=special>-&gt;</span><span class=identifier>value </span><span class=special>= </span><span class=identifier>value</span><span class=special>;
39        </span><span class=keyword>return </span><span class=identifier>c</span><span class=special>;
40    }
41
42    </span><span class=keyword>void </span><span class=identifier>printC</span><span class=special>(</span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>shared_ptr</span><span class=special>&lt;</span><span class=identifier>C</span><span class=special>&gt; </span><span class=identifier>c</span><span class=special>)
43    {
44        </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>cout </span><span class=special>&lt;&lt; </span><span class=identifier>c</span><span class=special>-&gt;</span><span class=identifier>value </span><span class=special>&lt;&lt; </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>endl</span><span class=special>;
45    }
46</span></pre></code>
47<p>
48To make <tt>newC</tt> and <tt>printC</tt> work correctly, you have to tell Pyste that a
49convertor for <tt>boost::shared_ptr&lt;C&gt;</tt> is needed.</p>
50<code><pre>
51    <span class=identifier>C </span><span class=special>= </span><span class=identifier>Class</span><span class=special>(</span><span class=literal>'C'</span><span class=special>, </span><span class=literal>'C.h'</span><span class=special>)
52    </span><span class=identifier>use_shared_ptr</span><span class=special>(</span><span class=identifier>C</span><span class=special>)
53    </span><span class=identifier>Function</span><span class=special>(</span><span class=literal>'newC'</span><span class=special>, </span><span class=literal>'C.h'</span><span class=special>)
54    </span><span class=identifier>Function</span><span class=special>(</span><span class=literal>'printC'</span><span class=special>, </span><span class=literal>'C.h'</span><span class=special>)
55</span></pre></code>
56<p>
57For <tt>std::auto_ptr</tt>'s, use the function <tt>use_auto_ptr</tt>.</p>
58<p>
59This system is temporary, and in the future the converters will automatically be
60exported if needed, without the need to tell Pyste about them explicitly.</p>
61<a name="holders"></a><h2>Holders</h2><p>
62If only the converter for the smart pointers is not enough and you need to
63specify the smart pointer as the holder for a class, use the functions
64<tt>hold_with_shared_ptr</tt> and <tt>hold_with_auto_ptr</tt>:</p>
65<code><pre>
66    <span class=identifier>C </span><span class=special>= </span><span class=identifier>Class</span><span class=special>(</span><span class=literal>'C'</span><span class=special>, </span><span class=literal>'C.h'</span><span class=special>)
67    </span><span class=identifier>hold_with_shared_ptr</span><span class=special>(</span><span class=identifier>C</span><span class=special>)
68    </span><span class=identifier>Function</span><span class=special>(</span><span class=literal>'newC'</span><span class=special>, </span><span class=literal>'C.h'</span><span class=special>)
69    </span><span class=identifier>Function</span><span class=special>(</span><span class=literal>'printC'</span><span class=special>, </span><span class=literal>'C.h'</span><span class=special>)
70</span></pre></code>
71<table border="0">
72  <tr>
73    <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
74    <td width="30"><a href="exporting_an_entire_header.html"><img src="theme/l_arr.gif" border="0"></a></td>
75    <td width="20"><a href="global_variables.html"><img src="theme/r_arr.gif" border="0"></a></td>
76   </tr>
77</table>
78<br>
79<hr size="1"><p class="copyright">Copyright &copy; 2003 Bruno da Silva de Oliveira<br>Copyright &copy; 2002-2003 Joel de Guzman<br><br>
80<font size="2">Permission to copy, use, modify, sell and distribute this document
81 is granted provided this copyright notice appears in all copies. This document
82 is provided &quot;as is&quot; without express or implied warranty, and with
83 no claim as to its suitability for any purpose. </font> </p>
84</body>
85</html>
Note: See TracBrowser for help on using the repository browser.