blob: b20d94a1ff5faefad2b13809ac81a6635229b4a5 (
plain)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 1st August 2002), see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../boost.css">
<title>Boost.Python - <boost/python/handle.hpp></title>
<style type="text/css">
p.c4 {font-style: italic}
span.c3 {color: #ff0000}
h2.c2 {text-align: center}
h1.c1 {text-align: center}
</style>
</head>
<body>
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../../../../index.htm"><img height="86" width="277"
alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 class="c1"><a href="../index.html">Boost.Python</a></h1>
<h2 class="c2">Header <boost/python/handle.hpp></h2>
</td>
</tr>
</table>
<hr>
<h2>Contents</h2>
<dl class="page-index">
<dt><a href="#introduction">Introduction</a></dt>
<dt><a href="#classes">Classes</a></dt>
<dd>
<dl class="page-index">
<dt><a href="#handle-spec">Class template
<code>handle</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#handle-spec-synopsis">Class <code>handle</code>
synopsis</a></dt>
<dt><a href="#handle-spec-ctors">Class <code>handle</code>
constructors and destructor</a></dt>
<dt><a href="#handle-spec-modifiers">Class <code>handle</code>
modifier functions</a></dt>
<dt><a href="#handle-spec-observers">Class <code>handle</code>
observer functions</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="#functions">Functions</a></dt>
<dd>
<dl class="page-index">
<dt><a href="#borrowed-spec"><code>borrowed</code></a></dt>
<dt><a href="#allow_null-spec"><code>allow_null</code></a></dt>
</dl>
</dd>
</dl>
<hr>
<h2><a name="introduction"></a>Introduction</h2>
<p><code><boost/python/handle.hpp></code> provides
<code>class template handle</code>, a smart pointer for
managing reference-counted Python objects.</p>
<h2><a name="classes"></a>Classes</h2>
<h3><a name="handle-spec"></a>Class template <code>handle</code></h3>
<p><code>handle</code> is a smart pointer to a Python object type; it
holds a pointer of type <code>T*</code>, where T is its template
parameter. <code>T</code> must be either a type derived from
<code>PyObject</code> or a <a href="definitions.html#POD">POD</a> type
whose initial <code>sizeof(PyObject)</code> bytes are layout-compatible
with <code>PyObject</code>. Use <code>handle<></code> at the
boundary between the Python/'C' API and high-level code; prefer <code><a
href="object.html#object-spec">object</a></code> for a generalized
interface to Python objects.</p>
<p><a name="upcast"></a>In this document, the term "upcast" refers to an
operation which converts a pointer <code>Y*</code> to a base class
pointer <code>T*</code> via <code>static_cast<T*></code> if
<code>Y</code> is derived from <code>T</code>, or via C-style cast
<code>(T*)</code> if it is not. However, in the latter case the "upcast"
is ill-formed if the initial <code>sizeof(PyObject)</code> bytes of
<code>Y</code> are not layout-compatible with <code>PyObject</code>.</p>
<h4><a name="handle-spec-synopsis"></a>Class template handle
synopsis</h4>
<pre>
namespace boost { namespace python
{
template <class T>
class handle
{
typedef <i>unspecified-member-function-pointer</i> bool_type;
public: // types
typedef T element_type;
public: // member functions
~handle();
template <class Y>
explicit handle(detail::borrowed<null_ok<Y> >* p);
template <class Y>
explicit handle(null_ok<detail::borrowed<Y> >* p);
template <class Y>
explicit handle(detail::borrowed<Y>* p);
template <class Y>
explicit handle(null_ok<Y>* p);
template <class Y>
explicit handle(Y* p);
handle();
handle& operator=(handle const& r);
template<typename Y>
handle& operator=(handle<Y> const & r); // never throws
template <typename Y>
handle(handle<Y> const& r);
handle(handle const& r);
T* operator-> () const;
T& operator* () const;
T* get() const;
void reset();
T* release();
operator bool_type() const; // never throws
private:
T* m_p;
};
template <class T> struct null_ok;
namespace detail { template <class T> struct borrowed; }
}}
</pre>
<h4><a name="handle-spec-ctors">Class <code>handle</code> constructors
and destructor</a></h4>
<pre>
virtual ~handle();
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<code>Py_XDECREF(</code><i>upcast</i><code><PyObject*>(m_p))</code></dt>
</dl>
<pre>
template <class Y>
explicit handle(detail::borrowed<null_ok<Y> >* p);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<code>Py_XINCREF(</code><i>upcast</i><code><PyObject*>(p));
m_p = </code><i>upcast</i><code><T*>(p);</code></dt>
</dl>
<pre>
template <class Y>
explicit handle(null_ok<detail::borrowed<Y> >* p);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<code>Py_XINCREF(</code><i>upcast</i><code><PyObject*>(p));
m_p = </code><i>upcast</i><code><T*>(p);</code></dt>
</dl>
<pre>
template <class Y>
explicit handle(detail::borrowed<Y>* p);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<code>Py_XINCREF(</code><i>upcast</i><code><PyObject*>(p));
m_p = </code><i>upcast</i><code><T*>(<a href=
"errors.html#expect_non_null-spec">expect_non_null</a>(p));</code></dt>
</dl>
<pre>
template <class Y>
explicit handle(null_ok<Y>* p);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<code>m_p = </code><i>upcast</i><code><T*>(p);</code></dt>
</dl>
<pre>
template <class Y>
explicit handle(Y* p);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<code>m_p = </code><i>upcast</i><code><T*>(<a href=
"errors.html#expect_non_null-spec">expect_non_null</a>(p));</code></dt>
</dl>
<pre>
handle();
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> <code>m_p = 0;</code></dt>
</dl>
<pre>
template <typename Y>
handle(handle<Y> const& r);
handle(handle const& r);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<code>m_p = r.m_p; Py_XINCREF(</code><i>upcast</i><code><PyObject*>(m_p));</code></dt>
</dl>
<h4><a name="handle-spec-modifiers">Class <code>handle</code>
modifiers</a></h4>
<pre>
handle& operator=(handle const& r);
template<typename Y>
handle& operator=(handle<Y> const & r); // never throws
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<code>Py_XINCREF(</code><i>upcast</i><code><PyObject*>(r.m_p)); Py_XDECREF(</code><i>
upcast</i><code><PyObject*>(m_p)); m_p = r.m_p;</code></dt>
</dl>
<pre>
T* release();
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> <code>T* x = m_p; m_p = 0;return
x;</code></dt>
</dl>
<pre>
void reset();
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<code>*this = handle<T>();</code></dt>
</dl>
<h4><a name="handle-spec-observers">Class <code>handle</code>
observers</a></h4>
<pre>
T* operator-> () const;
T* get() const;
</pre>
<dl class="function-semantics">
<dt><b>Returns:</b> <code>m_p;</code></dt>
</dl>
<pre>
T& operator* () const;
</pre>
<dl class="function-semantics">
<dt><b>Returns:</b> <code>*m_p;</code></dt>
</dl>
<pre>
operator bool_type() const; // never throws
</pre>
<dl class="function-semantics">
<dt><b>Returns:</b> 0 if <code>m_p == 0</code>, a pointer
convertible to <code>true</code> otherwise.</dt>
</dl>
<h2><a name="functions"></a>Functions</h2>
<h3><a name="borrowed-spec"></a><code>borrowed</code></h3>
<pre>
template <class T>
detail::borrowed<T>* borrowed(T* p)
{
return (detail::borrowed<T>*)p;
}
</pre>
<h3><a name="allow_null-spec"></a><code>allow_null</code></h3>
<pre>
template <class T>
null_ok<T>* allow_null(T* p)
{
return (null_ok<T>*)p;
}
</pre>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
13 November, 2002
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
<p class="c4">© Copyright <a href=
"http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> 2002
.</p>
</body>
</html>
|