Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/doc/v2/handle.html @ 45

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

updated boost from 1_33_1 to 1_34_1

File size: 9.6 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
3<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
4<!-- Software License, Version 1.0. (See accompanying -->
5<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
6<html>
7  <head>
8    <meta name="generator" content=
9    "HTML Tidy for Windows (vers 1st August 2002), see www.w3.org">
10    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
11    <link rel="stylesheet" type="text/css" href="../boost.css">
12
13    <title>Boost.Python - &lt;boost/python/handle.hpp&gt;</title>
14
15    <style type="text/css">
16 p.c4 {font-style: italic}
17 span.c3 {color: #ff0000}
18 h2.c2 {text-align: center}
19 h1.c1 {text-align: center}
20        </style>
21  </head>
22
23  <body>
24    <table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
25    "header">
26      <tr>
27        <td valign="top" width="300">
28          <h3><a href="../../../../index.htm"><img height="86" width="277"
29          alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
30        </td>
31
32        <td valign="top">
33          <h1 class="c1"><a href="../index.html">Boost.Python</a></h1>
34
35          <h2 class="c2">Header &lt;boost/python/handle.hpp&gt;</h2>
36        </td>
37      </tr>
38    </table>
39    <hr>
40
41    <h2>Contents</h2>
42
43    <dl class="page-index">
44      <dt><a href="#introduction">Introduction</a></dt>
45
46      <dt><a href="#classes">Classes</a></dt>
47
48      <dd>
49        <dl class="page-index">
50          <dt><a href="#handle-spec">Class template
51          <code>handle</code></a></dt>
52
53          <dd>
54            <dl class="page-index">
55              <dt><a href="#handle-spec-synopsis">Class <code>handle</code>
56              synopsis</a></dt>
57
58              <dt><a href="#handle-spec-ctors">Class <code>handle</code>
59              constructors and destructor</a></dt>
60
61              <dt><a href="#handle-spec-modifiers">Class <code>handle</code>
62              modifier functions</a></dt>
63
64              <dt><a href="#handle-spec-observers">Class <code>handle</code>
65              observer functions</a></dt>
66            </dl>
67          </dd>
68        </dl>
69      </dd>
70
71      <dt><a href="#functions">Functions</a></dt>
72
73      <dd>
74        <dl class="page-index">
75          <dt><a href="#borrowed-spec"><code>borrowed</code></a></dt>
76
77          <dt><a href="#allow_null-spec"><code>allow_null</code></a></dt>
78        </dl>
79      </dd>
80    </dl>
81    <hr>
82
83    <h2><a name="introduction"></a>Introduction</h2>
84
85    <p><code>&lt;boost/python/handle.hpp&gt;</code> provides
86    <code>class&nbsp;template&nbsp;handle</code>, a smart pointer for
87    managing reference-counted Python objects.</p>
88
89    <h2><a name="classes"></a>Classes</h2>
90
91    <h3><a name="handle-spec"></a>Class template <code>handle</code></h3>
92
93    <p><code>handle</code> is a smart pointer to a Python object type; it
94    holds a pointer of type <code>T*</code>, where T is its template
95    parameter. <code>T</code> must be either a type derived from
96    <code>PyObject</code> or a <a href="definitions.html#POD">POD</a> type
97    whose initial <code>sizeof(PyObject)</code> bytes are layout-compatible
98    with <code>PyObject</code>. Use <code>handle&lt;&gt;</code> at the
99    boundary between the Python/'C' API and high-level code; prefer <code><a
100    href="object.html#object-spec">object</a></code> for a generalized
101    interface to Python objects.</p>
102
103    <p><a name="upcast"></a>In this document, the term "upcast" refers to an
104    operation which converts a pointer <code>Y*</code> to a base class
105    pointer <code>T*</code> via <code>static_cast&lt;T*&gt;</code> if
106    <code>Y</code> is derived from <code>T</code>, or via C-style cast
107    <code>(T*)</code> if it is not. However, in the latter case the "upcast"
108    is ill-formed if the initial <code>sizeof(PyObject)</code> bytes of
109    <code>Y</code> are not layout-compatible with <code>PyObject</code>.</p>
110
111    <h4><a name="handle-spec-synopsis"></a>Class template handle
112    synopsis</h4>
113<pre>
114namespace boost { namespace python
115{
116  template &lt;class T&gt;
117  class handle
118  {
119      typedef <i>unspecified-member-function-pointer</i> bool_type;
120
121   public: // types
122      typedef T element_type;
123
124   public: // member functions
125      ~handle();
126
127      template &lt;class Y&gt;
128      explicit handle(detail::borrowed&lt;null_ok&lt;Y&gt; &gt;* p);
129
130      template &lt;class Y&gt;
131      explicit handle(null_ok&lt;detail::borrowed&lt;Y&gt; &gt;* p);
132
133      template &lt;class Y&gt;
134      explicit handle(detail::borrowed&lt;Y&gt;* p);
135
136      template &lt;class Y&gt;
137      explicit handle(null_ok&lt;Y&gt;* p);
138
139      template &lt;class Y&gt;
140      explicit handle(Y* p);
141
142      handle();
143
144      handle&amp; operator=(handle const&amp; r);
145
146      template&lt;typename Y&gt;
147      handle&amp; operator=(handle&lt;Y&gt; const &amp; r); // never throws
148
149
150      template &lt;typename Y&gt;
151      handle(handle&lt;Y&gt; const&amp; r);
152
153      handle(handle const&amp; r);
154
155      T* operator-&gt; () const;
156      T&amp; operator* () const;
157      T* get() const;
158      void reset();
159      T* release();
160
161      operator bool_type() const; // never throws
162   private:
163      T* m_p;
164  };
165 
166  template &lt;class T&gt; struct null_ok;
167  namespace detail { template &lt;class T&gt; struct borrowed; }
168}}
169</pre>
170
171    <h4><a name="handle-spec-ctors">Class <code>handle</code> constructors
172    and destructor</a></h4>
173<pre>
174virtual ~handle();
175</pre>
176
177    <dl class="function-semantics">
178      <dt><b>Effects:</b>
179      <code>Py_XDECREF(</code><i>upcast</i><code>&lt;PyObject*&gt;(m_p))</code></dt>
180    </dl>
181<pre>
182template &lt;class Y&gt;
183explicit handle(detail::borrowed&lt;null_ok&lt;Y&gt; &gt;* p);
184</pre>
185
186    <dl class="function-semantics">
187      <dt><b>Effects:</b>
188      <code>Py_XINCREF(</code><i>upcast</i><code>&lt;PyObject*&gt;(p));
189      m_p&nbsp;=&nbsp;</code><i>upcast</i><code>&lt;T*&gt;(p);</code></dt>
190    </dl>
191<pre>
192template &lt;class Y&gt;
193explicit handle(null_ok&lt;detail::borrowed&lt;Y&gt; &gt;* p);
194</pre>
195
196    <dl class="function-semantics">
197      <dt><b>Effects:</b>
198      <code>Py_XINCREF(</code><i>upcast</i><code>&lt;PyObject*&gt;(p));
199      m_p&nbsp;=&nbsp;</code><i>upcast</i><code>&lt;T*&gt;(p);</code></dt>
200    </dl>
201<pre>
202template &lt;class Y&gt;
203explicit handle(detail::borrowed&lt;Y&gt;* p);
204</pre>
205
206    <dl class="function-semantics">
207      <dt><b>Effects:</b>
208      <code>Py_XINCREF(</code><i>upcast</i><code>&lt;PyObject*&gt;(p));
209      m_p&nbsp;=&nbsp;</code><i>upcast</i><code>&lt;T*&gt;(<a href=
210      "errors.html#expect_non_null-spec">expect_non_null</a>(p));</code></dt>
211    </dl>
212<pre>
213template &lt;class Y&gt;
214explicit handle(null_ok&lt;Y&gt;* p);
215</pre>
216
217    <dl class="function-semantics">
218      <dt><b>Effects:</b>
219      <code>m_p&nbsp;=&nbsp;</code><i>upcast</i><code>&lt;T*&gt;(p);</code></dt>
220    </dl>
221<pre>
222template &lt;class Y&gt;
223explicit handle(Y* p);
224</pre>
225
226    <dl class="function-semantics">
227      <dt><b>Effects:</b>
228      <code>m_p&nbsp;=&nbsp;</code><i>upcast</i><code>&lt;T*&gt;(<a href=
229      "errors.html#expect_non_null-spec">expect_non_null</a>(p));</code></dt>
230    </dl>
231<pre>
232handle();
233</pre>
234
235    <dl class="function-semantics">
236      <dt><b>Effects:</b> <code>m_p&nbsp;=&nbsp;0;</code></dt>
237    </dl>
238<pre>
239template &lt;typename Y&gt;
240handle(handle&lt;Y&gt; const&amp; r);
241handle(handle const&amp; r);
242</pre>
243
244    <dl class="function-semantics">
245      <dt><b>Effects:</b>
246      <code>m_p&nbsp;=&nbsp;r.m_p;&nbsp;Py_XINCREF(</code><i>upcast</i><code>&lt;PyObject*&gt;(m_p));</code></dt>
247    </dl>
248
249    <h4><a name="handle-spec-modifiers">Class <code>handle</code>
250    modifiers</a></h4>
251<pre>
252handle&amp; operator=(handle const&amp; r);
253template&lt;typename Y&gt;
254handle&amp; operator=(handle&lt;Y&gt; const &amp; r); // never throws
255</pre>
256
257    <dl class="function-semantics">
258      <dt><b>Effects:</b>
259      <code>Py_XINCREF(</code><i>upcast</i><code>&lt;PyObject*&gt;(r.m_p));&nbsp;Py_XDECREF(</code><i>
260      upcast</i><code>&lt;PyObject*&gt;(m_p));&nbsp;m_p&nbsp;=&nbsp;r.m_p;</code></dt>
261    </dl>
262<pre>
263T* release();
264</pre>
265
266    <dl class="function-semantics">
267      <dt><b>Effects:</b> <code>T* x = m_p;&nbsp;m_p&nbsp;=&nbsp;0;return
268      x;</code></dt>
269    </dl>
270<pre>
271void reset();
272</pre>
273
274    <dl class="function-semantics">
275      <dt><b>Effects:</b>
276      <code>*this&nbsp;=&nbsp;handle&lt;T&gt;();</code></dt>
277    </dl>
278
279    <h4><a name="handle-spec-observers">Class <code>handle</code>
280    observers</a></h4>
281<pre>
282T* operator-&gt; () const;
283T* get() const;
284</pre>
285
286    <dl class="function-semantics">
287      <dt><b>Returns:</b> <code>m_p;</code></dt>
288    </dl>
289<pre>
290T&amp; operator* () const;
291</pre>
292
293    <dl class="function-semantics">
294      <dt><b>Returns:</b> <code>*m_p;</code></dt>
295    </dl>
296<pre>
297operator bool_type() const; // never throws
298</pre>
299
300    <dl class="function-semantics">
301      <dt><b>Returns:</b> 0 if <code>m_p&nbsp;==&nbsp;0</code>, a pointer
302      convertible to <code>true</code> otherwise.</dt>
303    </dl>
304
305    <h2><a name="functions"></a>Functions</h2>
306
307    <h3><a name="borrowed-spec"></a><code>borrowed</code></h3>
308<pre>
309template &lt;class T&gt;
310detail::borrowed&lt;T&gt;* borrowed(T* p)
311{
312    return (detail::borrowed&lt;T&gt;*)p;
313}
314</pre>
315
316    <h3><a name="allow_null-spec"></a><code>allow_null</code></h3>
317<pre>
318template &lt;class T&gt;
319null_ok&lt;T&gt;* allow_null(T* p)
320{
321    return (null_ok&lt;T&gt;*)p;
322}
323</pre>
324
325    <p>Revised
326    <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
327     13 November, 2002
328    <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
329    </p>
330
331    <p class="c4">&copy; Copyright <a href=
332    "../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002
333.</p>
334  </body>
335</html>
336
Note: See TracBrowser for help on using the repository browser.