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 - <boost/python/object.hpp></title> |
---|
14 | </head> |
---|
15 | |
---|
16 | <body> |
---|
17 | <table border="0" cellpadding="7" cellspacing="0" width="100%" summary= |
---|
18 | "header"> |
---|
19 | <tr> |
---|
20 | <td valign="top" width="300"> |
---|
21 | <h3><a href="../../../../index.htm"><img height="86" width="277" |
---|
22 | alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3> |
---|
23 | </td> |
---|
24 | |
---|
25 | <td valign="top"> |
---|
26 | <h1 align="center"><a href="../index.html">Boost.Python</a></h1> |
---|
27 | |
---|
28 | <h2 align="center">Header <boost/python/object.hpp></h2> |
---|
29 | </td> |
---|
30 | </tr> |
---|
31 | </table> |
---|
32 | <hr> |
---|
33 | |
---|
34 | <h2>Contents</h2> |
---|
35 | |
---|
36 | <dl class="page-index"> |
---|
37 | <dt><a href="#introduction">Introduction</a></dt> |
---|
38 | |
---|
39 | <dt><a href="#types">Types</a></dt> |
---|
40 | |
---|
41 | <dd> |
---|
42 | <dl class="page-index"> |
---|
43 | <dt><a href="#slice_nil-spec">slice_nil</a></dt> |
---|
44 | </dl> |
---|
45 | </dd> |
---|
46 | |
---|
47 | <dt><a href="#classes">Classes</a></dt> |
---|
48 | |
---|
49 | <dd> |
---|
50 | <dl class="page-index"> |
---|
51 | <dt><a href="#const_attribute_policies-spec">Class |
---|
52 | <code>const_attribute_policies</code></a></dt> |
---|
53 | |
---|
54 | <dd> |
---|
55 | <dl class="page-index"> |
---|
56 | <dt><a href="#const_attribute_policies-spec-synopsis">Class |
---|
57 | <code>const_attribute_policies</code> synopsis</a></dt> |
---|
58 | |
---|
59 | <dt><a href="#const_attribute_policies-spec-statics">Class |
---|
60 | <code>const_attribute_policies</code> static functions</a></dt> |
---|
61 | </dl> |
---|
62 | </dd> |
---|
63 | |
---|
64 | <dt><a href="#attribute_policies-spec">Class |
---|
65 | <code>attribute_policies</code></a></dt> |
---|
66 | |
---|
67 | <dd> |
---|
68 | <dl class="page-index"> |
---|
69 | <dt><a href="#attribute_policies-spec-synopsis">Class |
---|
70 | <code>attribute_policies</code> synopsis</a></dt> |
---|
71 | |
---|
72 | <dt><a href="#attribute_policies-spec-statics">Class |
---|
73 | <code>attribute_policies</code> static functions</a></dt> |
---|
74 | </dl> |
---|
75 | </dd> |
---|
76 | |
---|
77 | <dt><a href="#const_item_policies-spec">Class |
---|
78 | <code>const_item_policies</code></a></dt> |
---|
79 | |
---|
80 | <dd> |
---|
81 | <dl class="page-index"> |
---|
82 | <dt><a href="#const_item_policies-spec-synopsis">Class |
---|
83 | <code>const_item_policies</code> synopsis</a></dt> |
---|
84 | |
---|
85 | <dt><a href="#const_item_policies-spec-statics">Class |
---|
86 | <code>const_item_policies</code> static functions</a></dt> |
---|
87 | </dl> |
---|
88 | </dd> |
---|
89 | |
---|
90 | <dt><a href="#item_policies-spec">Class |
---|
91 | <code>item_policies</code></a></dt> |
---|
92 | |
---|
93 | <dd> |
---|
94 | <dl class="page-index"> |
---|
95 | <dt><a href="#item_policies-spec-synopsis">Class |
---|
96 | <code>item_policies</code> synopsis</a></dt> |
---|
97 | |
---|
98 | <dt><a href="#item_policies-spec-statics">Class |
---|
99 | <code>item_policies</code> static functions</a></dt> |
---|
100 | </dl> |
---|
101 | </dd> |
---|
102 | |
---|
103 | <dt><a href="#const_slice_policies-spec">Class |
---|
104 | <code>const_slice_policies</code></a></dt> |
---|
105 | |
---|
106 | <dd> |
---|
107 | <dl class="page-index"> |
---|
108 | <dt><a href="#const_slice_policies-spec-synopsis">Class |
---|
109 | <code>const_slice_policies</code> synopsis</a></dt> |
---|
110 | |
---|
111 | <dt><a href="#const_slice_policies-spec-statics">Class |
---|
112 | <code>const_slice_policies</code> static functions</a></dt> |
---|
113 | </dl> |
---|
114 | </dd> |
---|
115 | |
---|
116 | <dt><a href="#slice_policies-spec">Class |
---|
117 | <code>slice_policies</code></a></dt> |
---|
118 | |
---|
119 | <dd> |
---|
120 | <dl class="page-index"> |
---|
121 | <dt><a href="#slice_policies-spec-synopsis">Class |
---|
122 | <code>slice_policies</code> synopsis</a></dt> |
---|
123 | |
---|
124 | <dt><a href="#slice_policies-spec-statics">Class |
---|
125 | <code>slice_policies</code> static functions</a></dt> |
---|
126 | </dl> |
---|
127 | </dd> |
---|
128 | |
---|
129 | <dt><a href="#object_operators-spec">Class |
---|
130 | <code>object_operators</code></a></dt> |
---|
131 | |
---|
132 | <dd> |
---|
133 | <dl class="page-index"> |
---|
134 | <dt><a href="#object_operators-spec-synopsis">Class |
---|
135 | <code>object_operators</code> synopsis</a></dt> |
---|
136 | |
---|
137 | <dt><a href="#object_operators-spec-observers">Class |
---|
138 | <code>object_operators</code> observer functions</a></dt> |
---|
139 | </dl> |
---|
140 | </dd> |
---|
141 | |
---|
142 | <dt><a href="#object-spec">Class <code>object</code></a></dt> |
---|
143 | |
---|
144 | <dd> |
---|
145 | <dl class="page-index"> |
---|
146 | <dt><a href="#object-spec-synopsis">Class <code>object</code> |
---|
147 | synopsis</a></dt> |
---|
148 | |
---|
149 | <dt><a href="#object-spec-ctors">Class <code>object</code> |
---|
150 | constructors and destructor</a></dt> |
---|
151 | |
---|
152 | <dt><a href="#object-spec-modifiers">Class template |
---|
153 | <code>object</code> modifier functions</a></dt> |
---|
154 | |
---|
155 | <dt><a href="#object-spec-observers">Class template |
---|
156 | <code>object</code> observer functions</a></dt> |
---|
157 | </dl> |
---|
158 | </dd> |
---|
159 | |
---|
160 | <dt><a href="#proxy-spec">Class template |
---|
161 | <code>proxy</code></a></dt> |
---|
162 | |
---|
163 | <dd> |
---|
164 | <dl class="page-index"> |
---|
165 | <dt><a href="#proxy-spec-synopsis">Class template |
---|
166 | <code>proxy</code> synopsis</a></dt> |
---|
167 | |
---|
168 | <dt><a href="#proxy-spec-modifiers">Class template |
---|
169 | <code>proxy</code> modifier functions</a></dt> |
---|
170 | |
---|
171 | <dt><a href="#proxy-spec-observers">Class template |
---|
172 | <code>proxy</code> observer functions</a></dt> |
---|
173 | </dl> |
---|
174 | </dd> |
---|
175 | </dl> |
---|
176 | </dd> |
---|
177 | |
---|
178 | <dt><a href="#functions">Functions</a></dt> |
---|
179 | |
---|
180 | <dd> |
---|
181 | <dl class="page-index"> |
---|
182 | <dt><a href="#del-spec">del</a></dt> |
---|
183 | |
---|
184 | <dt><a href="#comparisons-spec">comparisons</a></dt> |
---|
185 | |
---|
186 | <dt><a href="#binary-spec">binary operations</a></dt> |
---|
187 | |
---|
188 | <dt><a href="#assignment-spec">assignment operations</a></dt> |
---|
189 | |
---|
190 | </dl> |
---|
191 | |
---|
192 | <dl class="page-index"> |
---|
193 | <dt><a href="#object_operators-spec">operators</a></dt> |
---|
194 | </dl> |
---|
195 | |
---|
196 | <dl class="page-index"> |
---|
197 | <dt><a href="#len-spec">len()</a></dt> |
---|
198 | </dl> |
---|
199 | </dd> |
---|
200 | |
---|
201 | <dt><a href="#examples">Example</a></dt> |
---|
202 | </dl> |
---|
203 | <hr> |
---|
204 | |
---|
205 | <h2><a name="introduction"></a>Introduction</h2> |
---|
206 | |
---|
207 | <p>Exposes the generic Python object wrapper class <code>object</code>, |
---|
208 | and related classes. In order to avoid some potenential problems with |
---|
209 | argument-dependent lookup and the generalized operators defined on |
---|
210 | <code>object</code>, all these facilities are defined in |
---|
211 | <code>namespace boost::python::api</code>, and <code>object</code> |
---|
212 | is imported into <code>namespace boost::python</code> with a |
---|
213 | <i>using-declaration</i>.</p> |
---|
214 | |
---|
215 | <h2><a name="types"></a>Types</h2> |
---|
216 | |
---|
217 | <p><a name="slice_nil-spec"></a></p> |
---|
218 | <pre> |
---|
219 | class slice_nil; |
---|
220 | static const _ = slice_nil(); |
---|
221 | </pre> |
---|
222 | A type that can be used to get the effect of leaving out an index in a |
---|
223 | Python slice expression: |
---|
224 | <pre> |
---|
225 | >>> x[:-1] |
---|
226 | >>> x[::-1] |
---|
227 | </pre> |
---|
228 | C++ equivalent: |
---|
229 | <pre> |
---|
230 | x.slice(_,-1) |
---|
231 | x[slice(_,_,-1)] |
---|
232 | </pre> |
---|
233 | |
---|
234 | <h2><a name="classes"></a>Classes</h2> |
---|
235 | <!-- begin --> |
---|
236 | |
---|
237 | <h3><a name="const_attribute_policies-spec"></a>Class |
---|
238 | <code>const_attribute_policies</code></h3> |
---|
239 | |
---|
240 | <p>The policies which are used for proxies representing an attribute |
---|
241 | access to a <code>const object</code>.</p> |
---|
242 | |
---|
243 | <h4><a name="const_attribute_policies-spec-synopsis"></a>Class |
---|
244 | <code>const_attribute_policies</code> synopsis</h4> |
---|
245 | <pre> |
---|
246 | namespace boost { namespace python { namespace api |
---|
247 | { |
---|
248 | struct const_attribute_policies |
---|
249 | { |
---|
250 | typedef char const* key_type; |
---|
251 | static object get(object const& target, char const* key); |
---|
252 | }; |
---|
253 | }}} |
---|
254 | </pre> |
---|
255 | |
---|
256 | <h4><a name="const_attribute_policies-spec-statics"></a>Class |
---|
257 | <code>const_attribute_policies</code> static functions</h4> |
---|
258 | <pre> |
---|
259 | static object get(object const& target, char const* key); |
---|
260 | </pre> |
---|
261 | |
---|
262 | <dl class="function-semantics"> |
---|
263 | <dt><b>Requires:</b> <code>key</code> is an <a href= |
---|
264 | "definitions.html#ntbs">ntbs</a>.</dt> |
---|
265 | |
---|
266 | <dt><b>Effects:</b> accesses the attribute of <code>target</code> named |
---|
267 | by <code>key</code>.</dt> |
---|
268 | |
---|
269 | <dt><b>Returns:</b> An <code>object</code> managing the result of the |
---|
270 | attribute access.</dt> |
---|
271 | |
---|
272 | <dt><b>Throws:</b> <code><a href= |
---|
273 | "errors.html#error_already_set-spec">error_already_set</a></code> if a |
---|
274 | Python exception is raised.</dt> |
---|
275 | </dl> |
---|
276 | |
---|
277 | <h3><a name="attribute_policies-spec"></a>Class |
---|
278 | <code>attribute_policies</code></h3> |
---|
279 | |
---|
280 | <p>The policies which are used for proxies representing an attribute |
---|
281 | access to a mutable <code>object</code>.</p> |
---|
282 | |
---|
283 | <h4><a name="attribute_policies-spec-synopsis"></a>Class |
---|
284 | <code>attribute_policies</code> synopsis</h4> |
---|
285 | <pre> |
---|
286 | namespace boost { namespace python { namespace api |
---|
287 | { |
---|
288 | struct attribute_policies : const_attribute_policies |
---|
289 | { |
---|
290 | static object const& set(object const& target, char const* key, object const& value); |
---|
291 | static void del(object const&target, char const* key); |
---|
292 | }; |
---|
293 | }}} |
---|
294 | </pre> |
---|
295 | |
---|
296 | <h4><a name="attribute_policies-spec-statics"></a>Class |
---|
297 | <code>attribute_policies</code> static functions</h4> |
---|
298 | <pre> |
---|
299 | static object const& set(object const& target, char const* key, object const& value); |
---|
300 | </pre> |
---|
301 | |
---|
302 | <dl class="function-semantics"> |
---|
303 | <dt><b>Requires:</b> <code>key</code> is an <a href= |
---|
304 | "definitions.html#ntbs">ntbs</a>.</dt> |
---|
305 | |
---|
306 | <dt><b>Effects:</b> sets the attribute of <code>target</code> named by |
---|
307 | <code>key</code> to <code>value</code>.</dt> |
---|
308 | |
---|
309 | <dt><b>Throws:</b> <code><a href= |
---|
310 | "errors.html#error_already_set-spec">error_already_set</a></code> if a |
---|
311 | Python exception is raised.</dt> |
---|
312 | </dl> |
---|
313 | <pre> |
---|
314 | static void del(object const&target, char const* key); |
---|
315 | </pre> |
---|
316 | |
---|
317 | <dl class="function-semantics"> |
---|
318 | <dt><b>Requires:</b> <code>key</code> is an <a href= |
---|
319 | "definitions.html#ntbs">ntbs</a>.</dt> |
---|
320 | |
---|
321 | <dt><b>Effects:</b> deletes the attribute of <code>target</code> named |
---|
322 | by <code>key</code>.</dt> |
---|
323 | |
---|
324 | <dt><b>Throws:</b> <code><a href= |
---|
325 | "errors.html#error_already_set-spec">error_already_set</a></code> if a |
---|
326 | Python exception is raised.</dt> |
---|
327 | </dl> |
---|
328 | <!-- end --> |
---|
329 | <!-- begin --> |
---|
330 | |
---|
331 | <h3><a name="const_item_policies-spec"></a>Class |
---|
332 | <code>const_item_policies</code></h3> |
---|
333 | |
---|
334 | <p>The policies which are used for proxies representing an item access |
---|
335 | (via the Python bracket operators <code>[]</code>) to a |
---|
336 | <code>const object</code>.</p> |
---|
337 | |
---|
338 | <h4><a name="const_item_policies-spec-synopsis"></a>Class |
---|
339 | <code>const_item_policies</code> synopsis</h4> |
---|
340 | <pre> |
---|
341 | namespace boost { namespace python { namespace api |
---|
342 | { |
---|
343 | struct const_item_policies |
---|
344 | { |
---|
345 | typedef object key_type; |
---|
346 | static object get(object const& target, object const& key); |
---|
347 | }; |
---|
348 | }}} |
---|
349 | </pre> |
---|
350 | |
---|
351 | <h4><a name="const_item_policies-spec-statics"></a>Class |
---|
352 | <code>const_item_policies</code> static functions</h4> |
---|
353 | <pre> |
---|
354 | static object get(object const& target, object const& key); |
---|
355 | </pre> |
---|
356 | |
---|
357 | <dl class="function-semantics"> |
---|
358 | <dt><b>Effects:</b> accesses the item of <code>target</code> specified |
---|
359 | by <code>key</code>.</dt> |
---|
360 | |
---|
361 | <dt><b>Returns:</b> An <code>object</code> managing the result of the |
---|
362 | item access.</dt> |
---|
363 | |
---|
364 | <dt><b>Throws:</b> <code><a href= |
---|
365 | "errors.html#error_already_set-spec">error_already_set</a></code> if a |
---|
366 | Python exception is raised.</dt> |
---|
367 | </dl> |
---|
368 | |
---|
369 | <h3><a name="item_policies-spec"></a>Class |
---|
370 | <code>item_policies</code></h3> |
---|
371 | |
---|
372 | <p>The policies which are used for proxies representing an item access |
---|
373 | (via the Python bracket operators <code>[]</code>) to a mutable |
---|
374 | <code>object</code>.</p> |
---|
375 | |
---|
376 | <h4><a name="item_policies-spec-synopsis"></a>Class |
---|
377 | <code>item_policies</code> synopsis</h4> |
---|
378 | <pre> |
---|
379 | namespace boost { namespace python { namespace api |
---|
380 | { |
---|
381 | struct item_policies : const_item_policies |
---|
382 | { |
---|
383 | static object const& set(object const& target, object const& key, object const& value); |
---|
384 | static void del(object const& target, object const& key); |
---|
385 | }; |
---|
386 | }}} |
---|
387 | </pre> |
---|
388 | |
---|
389 | <h4><a name="item_policies-spec-statics"></a>Class |
---|
390 | <code>item_policies</code> static functions</h4> |
---|
391 | <pre> |
---|
392 | static object const& set(object const& target, object const& key, object const& value); |
---|
393 | </pre> |
---|
394 | |
---|
395 | <dl class="function-semantics"> |
---|
396 | <dt><b>Effects:</b> sets the item of <code>target</code> specified by |
---|
397 | <code>key</code> to <code>value</code>.</dt> |
---|
398 | |
---|
399 | <dt><b>Throws:</b> <code><a href= |
---|
400 | "errors.html#error_already_set-spec">error_already_set</a></code> if a |
---|
401 | Python exception is raised.</dt> |
---|
402 | </dl> |
---|
403 | <pre> |
---|
404 | static void del(object const& target, object const& key); |
---|
405 | </pre> |
---|
406 | |
---|
407 | <dl class="function-semantics"> |
---|
408 | <dt><b>Effects:</b> deletes the item of <code>target</code> specified |
---|
409 | by <code>key</code>.</dt> |
---|
410 | |
---|
411 | <dt><b>Throws:</b> <code><a href= |
---|
412 | "errors.html#error_already_set-spec">error_already_set</a></code> if a |
---|
413 | Python exception is raised.</dt> |
---|
414 | </dl> |
---|
415 | <!-- end --> |
---|
416 | <!-- begin --> |
---|
417 | |
---|
418 | <h3><a name="const_slice_policies-spec"></a>Class |
---|
419 | <code>const_slice_policies</code></h3> |
---|
420 | |
---|
421 | <p>The policies which are used for proxies representing an slice access |
---|
422 | (via the Python slice notation |
---|
423 | <code>[</code><i>x</i><code>:</code><i>y</i><code>]</code>) to a |
---|
424 | <code>const object</code>.</p> |
---|
425 | |
---|
426 | <h4><a name="const_slice_policies-spec-synopsis"></a>Class |
---|
427 | <code>const_slice_policies</code> synopsis</h4> |
---|
428 | <pre> |
---|
429 | namespace boost { namespace python { namespace api |
---|
430 | { |
---|
431 | struct const_slice_policies |
---|
432 | { |
---|
433 | typedef std::pair<handle<>, handle<> > key_type; |
---|
434 | static object get(object const& target, key_type const& key); |
---|
435 | }; |
---|
436 | }}} |
---|
437 | </pre> |
---|
438 | |
---|
439 | <h4><a name="const_slice_policies-spec-statics"></a>Class |
---|
440 | <code>const_slice_policies</code> static functions</h4> |
---|
441 | <pre> |
---|
442 | static object get(object const& target, key_type const& key); |
---|
443 | </pre> |
---|
444 | |
---|
445 | <dl class="function-semantics"> |
---|
446 | <dt><b>Effects:</b> accesses the slice of <code>target</code> specified |
---|
447 | by <code>key</code>.</dt> |
---|
448 | |
---|
449 | <dt><b>Returns:</b> An <code>object</code> managing the result of the |
---|
450 | slice access.</dt> |
---|
451 | |
---|
452 | <dt><b>Throws:</b> <code><a href= |
---|
453 | "errors.html#error_already_set-spec">error_already_set</a></code> if a |
---|
454 | Python exception is raised.</dt> |
---|
455 | </dl> |
---|
456 | |
---|
457 | <h3><a name="slice_policies-spec"></a>Class |
---|
458 | <code>slice_policies</code></h3> |
---|
459 | |
---|
460 | <p>The policies which are used for proxies representing an slice access |
---|
461 | to a mutable <code>object</code>.</p> |
---|
462 | |
---|
463 | <h4><a name="slice_policies-spec-synopsis"></a>Class |
---|
464 | <code>slice_policies</code> synopsis</h4> |
---|
465 | <pre> |
---|
466 | namespace boost { namespace python { namespace api |
---|
467 | { |
---|
468 | struct slice_policies : const_slice_policies |
---|
469 | { |
---|
470 | static object const& set(object const& target, key_type const& key, object const& value); |
---|
471 | static void del(object const& target, key_type const& key); |
---|
472 | }; |
---|
473 | }}} |
---|
474 | </pre> |
---|
475 | |
---|
476 | <h4><a name="slice_policies-spec-statics"></a>Class |
---|
477 | <code>slice_policies</code> static functions</h4> |
---|
478 | <pre> |
---|
479 | static object const& set(object const& target, key_type const& key, object const& value); |
---|
480 | </pre> |
---|
481 | |
---|
482 | <dl class="function-semantics"> |
---|
483 | <dt><b>Effects:</b> sets the slice of <code>target</code> specified by |
---|
484 | <code>key</code> to <code>value</code>.</dt> |
---|
485 | |
---|
486 | <dt><b>Throws:</b> <code><a href= |
---|
487 | "errors.html#error_already_set-spec">error_already_set</a></code> if a |
---|
488 | Python exception is raised.</dt> |
---|
489 | </dl> |
---|
490 | <pre> |
---|
491 | static void del(object const& target, key_type const& key); |
---|
492 | </pre> |
---|
493 | |
---|
494 | <dl class="function-semantics"> |
---|
495 | <dt><b>Effects:</b> deletes the slice of <code>target</code> specified |
---|
496 | by <code>key</code>.</dt> |
---|
497 | |
---|
498 | <dt><b>Throws:</b> <code><a href= |
---|
499 | "errors.html#error_already_set-spec">error_already_set</a></code> if a |
---|
500 | Python exception is raised.</dt> |
---|
501 | </dl> |
---|
502 | <!-- end --> |
---|
503 | |
---|
504 | <h3><a name="object_operators-spec"></a>Class template |
---|
505 | <code>object_operators<U></code></h3> |
---|
506 | |
---|
507 | <p>This is the base class of <code>object</code> and its |
---|
508 | <code>proxy</code> template used to supply common interface: member |
---|
509 | functions, and operators which must be defined within the class body. Its |
---|
510 | template parameter <code>U</code> is expected to be a class derived from |
---|
511 | <code>object_operators<U></code>. In practice users should never |
---|
512 | use this class directly, but it is documented here because it supplies |
---|
513 | important interface to <code>object</code> and its proxies.</p> |
---|
514 | |
---|
515 | <h4><a name="object_operators-spec-synopsis"></a>Class template |
---|
516 | <code>object_operators</code> synopsis</h4> |
---|
517 | <pre> |
---|
518 | namespace boost { namespace python { namespace api |
---|
519 | { |
---|
520 | template <class U> |
---|
521 | class object_operators |
---|
522 | { |
---|
523 | public: |
---|
524 | // function call |
---|
525 | // |
---|
526 | object operator()() const; |
---|
527 | |
---|
528 | template <class A0> |
---|
529 | object operator()(A0 const&) const; |
---|
530 | template <class A0, class A1> |
---|
531 | object operator()(A0 const&, A1 const&) const; |
---|
532 | ... |
---|
533 | template <class A0, class A1,...class An> |
---|
534 | object operator()(A0 const&, A1 const&,...An const&) const; |
---|
535 | |
---|
536 | // truth value testing |
---|
537 | // |
---|
538 | typedef unspecified bool_type; |
---|
539 | operator bool_type() const; |
---|
540 | |
---|
541 | // Attribute access |
---|
542 | // |
---|
543 | proxy<const_object_attribute> attr(char const*) const; |
---|
544 | proxy<object_attribute> attr(char const*); |
---|
545 | |
---|
546 | // item access |
---|
547 | // |
---|
548 | template <class T> |
---|
549 | proxy<const_object_item> operator[](T const& key) const; |
---|
550 | |
---|
551 | template <class T> |
---|
552 | proxy<object_item> operator[](T const& key); |
---|
553 | |
---|
554 | // slicing |
---|
555 | // |
---|
556 | template <class T, class V> |
---|
557 | proxy<const_object_slice> slice(T const& start, V const& end) const |
---|
558 | |
---|
559 | template <class T, class V> |
---|
560 | proxy<object_slice> slice(T const& start, V const& end); |
---|
561 | }; |
---|
562 | }}} |
---|
563 | </pre> |
---|
564 | |
---|
565 | <h4><a name="object_operators-spec-observers"></a>Class template |
---|
566 | <code>object_operators</code> observer functions</h4> |
---|
567 | <pre> |
---|
568 | object operator()() const; |
---|
569 | template <class A0> |
---|
570 | object operator()(A0 const&) const; |
---|
571 | template <class A0, class A1> |
---|
572 | object operator()(A0 const&, A1 const&) const; |
---|
573 | ... |
---|
574 | template <class A0, class A1,...class An> |
---|
575 | object operator()(A0 const& a1, A1 const& a2,...An const& aN) const; |
---|
576 | </pre> |
---|
577 | |
---|
578 | <dl class="function-semantics"> |
---|
579 | <dt><b>Effects:</b> |
---|
580 | call<object>(object(*static_cast<U*>(this)).ptr(), a1, |
---|
581 | a2,...aN)</dt> |
---|
582 | </dl> |
---|
583 | <pre> |
---|
584 | operator bool_type() const; |
---|
585 | </pre> |
---|
586 | |
---|
587 | <dl class="function-semantics"> |
---|
588 | <dt><b>Effects:</b> Tests truth value of <code>*this</code>.</dt> |
---|
589 | |
---|
590 | <dt><b>Returns:</b> |
---|
591 | call<object>(object(*static_cast<U*>(this)).ptr(), a1, |
---|
592 | a2,...aN)</dt> |
---|
593 | </dl> |
---|
594 | <pre> |
---|
595 | proxy<const_object_attribute> attr(char const* name) const; |
---|
596 | proxy<object_attribute> attr(char const* name); |
---|
597 | </pre> |
---|
598 | |
---|
599 | <dl class="function-semantics"> |
---|
600 | <dt><b>Requires:</b> name is an <a href= |
---|
601 | "definitions.html#ntbs">ntbs</a>.</dt> |
---|
602 | |
---|
603 | <dt><b>Effects:</b> accesses the named attribute of |
---|
604 | <code>*this</code>.</dt> |
---|
605 | |
---|
606 | <dt><b>Returns:</b> a proxy object which binds |
---|
607 | <code>object(*static_cast<U*>(this))</code> as its target, and |
---|
608 | <code>name</code> as its key.</dt> |
---|
609 | </dl> |
---|
610 | <pre> |
---|
611 | template <class T> |
---|
612 | proxy<const_object_item> operator[](T const& key) const; |
---|
613 | template <class T> |
---|
614 | proxy<object_item> operator[](T const& key); |
---|
615 | </pre> |
---|
616 | |
---|
617 | <dl class="function-semantics"> |
---|
618 | <dt><b>Effects:</b> accesses the item of <code>*this</code> indicated |
---|
619 | by <code>key</code>.</dt> |
---|
620 | |
---|
621 | <dt><b>Returns:</b> a proxy object which binds |
---|
622 | <code>object(*static_cast<U*>(this))</code> as its target, and |
---|
623 | <code>object(key)</code> as its key.</dt> |
---|
624 | </dl> |
---|
625 | <pre> |
---|
626 | template <class T, class V> |
---|
627 | proxy<const_object_slice> slice(T const& start; start, V const& finish) const |
---|
628 | template <class T, class V> |
---|
629 | proxy<object_slice> slice(T const& start; start, V const& finish); |
---|
630 | </pre> |
---|
631 | |
---|
632 | <dl class="function-semantics"> |
---|
633 | <dt><b>Effects:</b> accesses the slice of <code>*this</code> indicated |
---|
634 | by <code>std::make_pair(object(start), object(finish))</code>.</dt> |
---|
635 | |
---|
636 | <dt><b>Returns:</b> a proxy object which binds |
---|
637 | <code>object(*static_cast<U*>(this))</code> as its target, and |
---|
638 | <code>std::make_pair(object(start), object(finish))</code> as its |
---|
639 | key.</dt> |
---|
640 | </dl> |
---|
641 | <!-- --> |
---|
642 | |
---|
643 | <h3><a name="object-spec"></a>Class <code>object</code></h3> |
---|
644 | |
---|
645 | <p>The intention is that <code>object</code> acts as much like a |
---|
646 | Python variable as possible. Thus expressions you'd expect to work |
---|
647 | in Python should generally work in the same way from C++. Most of |
---|
648 | <code>object</code>'s interface is provided by its base class |
---|
649 | <code><a |
---|
650 | href="#object_operators-spec">object_operators</a><object></code>, |
---|
651 | and the <a href="#functions">free functions</a> defined in this |
---|
652 | header. |
---|
653 | </p> |
---|
654 | |
---|
655 | <h4><a name="object-spec-synopsis"></a>Class <code>object</code> |
---|
656 | synopsis</h4> |
---|
657 | <pre> |
---|
658 | namespace boost { namespace python { namespace api |
---|
659 | { |
---|
660 | class object : public object_operators<object> |
---|
661 | { |
---|
662 | public: |
---|
663 | object(); |
---|
664 | |
---|
665 | object(object const&); |
---|
666 | |
---|
667 | template <class T> |
---|
668 | explicit object(T const& x); |
---|
669 | |
---|
670 | ~object(); |
---|
671 | |
---|
672 | object& operator=(object const&); |
---|
673 | |
---|
674 | PyObject* ptr() const; |
---|
675 | }; |
---|
676 | }}} |
---|
677 | </pre> |
---|
678 | |
---|
679 | <h4><a name="object-spec-ctors"></a>Class <code>object</code> |
---|
680 | constructors and destructor</h4> |
---|
681 | <pre> |
---|
682 | object(); |
---|
683 | </pre> |
---|
684 | |
---|
685 | <dl class="function-semantics"> |
---|
686 | <dt><b>Effects:</b> Constructs an object managing a reference to the |
---|
687 | Python <code>None</code> object.</dt> |
---|
688 | |
---|
689 | <dt><b>Throws:</b> nothing.</dt> |
---|
690 | </dl> |
---|
691 | <pre> |
---|
692 | template <class T> |
---|
693 | explicit object(T const& x); |
---|
694 | </pre> |
---|
695 | |
---|
696 | <dl class="function-semantics"> |
---|
697 | <dt><b>Effects:</b> converts <code>x</code> to python and manages a |
---|
698 | reference to it.</dt> |
---|
699 | |
---|
700 | <dt><b>Throws:</b> <code>error_already_set</code> and sets a Python |
---|
701 | <code>TypeError</code> exception if no such conversion is |
---|
702 | possible.</dt> |
---|
703 | </dl> |
---|
704 | <pre> |
---|
705 | ~object(); |
---|
706 | </pre> |
---|
707 | |
---|
708 | <dl class="function-semantics"> |
---|
709 | <dt><b>Effects:</b> decrements the reference count of the |
---|
710 | internally-held object.</dt> |
---|
711 | </dl> |
---|
712 | |
---|
713 | <h4><a name="object-spec-modifiers"></a>Class <code>object</code> |
---|
714 | modifiers</h4> |
---|
715 | <pre> |
---|
716 | object& operator=(object const& rhs); |
---|
717 | </pre> |
---|
718 | |
---|
719 | <dl class="function-semantics"> |
---|
720 | <dt><b>Effects:</b> increments the reference count of the object held |
---|
721 | by <code>rhs</code> and decrements the reference count of the object |
---|
722 | held by <code>*this</code>.</dt> |
---|
723 | </dl> |
---|
724 | |
---|
725 | <h4><a name="object-spec-observers"></a>Class <code>object</code> |
---|
726 | observers</h4> |
---|
727 | <pre> |
---|
728 | PyObject* ptr() const; |
---|
729 | </pre> |
---|
730 | |
---|
731 | <dl class="function-semantics"> |
---|
732 | <dt><b>Returns:</b> a pointer to the internally-held Python |
---|
733 | object.</dt> |
---|
734 | </dl> |
---|
735 | <!-- --> |
---|
736 | |
---|
737 | <h3><a name="proxy-spec"></a>Class template <code>proxy</code></h3> |
---|
738 | |
---|
739 | <p>This template is instantiated with various Policies described in this |
---|
740 | document in order to implement attribute, item, and slice access for |
---|
741 | <code>object</code>. It stores an object of type |
---|
742 | <code>Policies::key_type</code>.</p> |
---|
743 | |
---|
744 | <h4><a name="proxy-spec-synopsis"></a>Class template <code>proxy</code> |
---|
745 | synopsis</h4> |
---|
746 | <pre> |
---|
747 | namespace boost { namespace python { namespace api |
---|
748 | { |
---|
749 | template <class Policies> |
---|
750 | class proxy : public object_operators<proxy<Policies> > |
---|
751 | { |
---|
752 | public: |
---|
753 | operator object() const; |
---|
754 | |
---|
755 | proxy const& operator=(proxy const&) const; |
---|
756 | template <class T> |
---|
757 | inline proxy const& operator=(T const& rhs) const; |
---|
758 | |
---|
759 | void del() const; |
---|
760 | |
---|
761 | template <class R> |
---|
762 | proxy operator+=(R const& rhs); |
---|
763 | template <class R> |
---|
764 | proxy operator-=(R const& rhs); |
---|
765 | template <class R> |
---|
766 | proxy operator*=(R const& rhs); |
---|
767 | template <class R> |
---|
768 | proxy operator/=(R const& rhs); |
---|
769 | template <class R> |
---|
770 | proxy operator%=(R const& rhs); |
---|
771 | template <class R> |
---|
772 | proxy operator<<=(R const& rhs); |
---|
773 | template <class R> |
---|
774 | proxy operator>>=(R const& rhs); |
---|
775 | template <class R> |
---|
776 | proxy operator&=(R const& rhs); |
---|
777 | template <class R> |
---|
778 | proxy operator|=(R const& rhs); |
---|
779 | }; |
---|
780 | }}} |
---|
781 | </pre> |
---|
782 | |
---|
783 | <h4><a name="proxy-spec-observers"></a>Class template <code>proxy</code> |
---|
784 | observer functions</h4> |
---|
785 | <pre> |
---|
786 | operator object() const; |
---|
787 | </pre> |
---|
788 | |
---|
789 | <dl class="function-semantics"> |
---|
790 | <dt><b>Effects:</b> applies |
---|
791 | <code>Policies::get(</code><i>target</i><code>,</code> <i>key</i> |
---|
792 | <code>)</code> with the proxy's target and key objects.</dt> |
---|
793 | </dl> |
---|
794 | |
---|
795 | <h4><a name="proxy-spec-modifiers"></a>Class template <code>proxy</code> |
---|
796 | modifier functions</h4> |
---|
797 | <pre> |
---|
798 | proxy const& operator=(proxy const& rhs) const; |
---|
799 | template <class T> |
---|
800 | inline proxy const& operator=(T const& rhs) const; |
---|
801 | </pre> |
---|
802 | |
---|
803 | <dl class="function-semantics"> |
---|
804 | <dt><b>Effects:</b> |
---|
805 | <code>Policies::set(</code><i>target</i><code>,</code> <i>key</i> |
---|
806 | <code>, object(rhs))</code> with the proxy's target and key |
---|
807 | objects.</dt> |
---|
808 | </dl> |
---|
809 | <pre> |
---|
810 | template <class R> |
---|
811 | proxy operator+=(R const& rhs); |
---|
812 | template <class R> |
---|
813 | proxy operator-=(R const& rhs); |
---|
814 | template <class R> |
---|
815 | proxy operator*=(R const& rhs); |
---|
816 | template <class R> |
---|
817 | proxy operator/=(R const& rhs); |
---|
818 | template <class R> |
---|
819 | proxy operator%=(R const& rhs); |
---|
820 | template <class R> |
---|
821 | proxy operator<<=(R const& rhs); |
---|
822 | template <class R> |
---|
823 | proxy operator>>=(R const& rhs); |
---|
824 | template <class R> |
---|
825 | proxy operator&=(R const& rhs); |
---|
826 | template <class R> |
---|
827 | proxy operator|=(R const& rhs); |
---|
828 | </pre> |
---|
829 | |
---|
830 | <dl class="function-semantics"> |
---|
831 | <dt><b>Effects:</b> for a given operator@=, |
---|
832 | <code>object(*this) @= rhs;</code></dt> |
---|
833 | <dt><b>Returns:</b> <code>*this</code></dt> |
---|
834 | </dl> |
---|
835 | <pre> |
---|
836 | void del() const; |
---|
837 | </pre> |
---|
838 | |
---|
839 | <dl class="function-semantics"> |
---|
840 | <dt><b>Effects:</b> |
---|
841 | <code>Policies::del(</code><i>target</i><code>,</code> <i>key</i> |
---|
842 | <code>)</code> with the proxy's target and key objects.</dt> |
---|
843 | </dl> |
---|
844 | <!-- --> |
---|
845 | |
---|
846 | <h2><a name="functions"></a>Functions</h2> |
---|
847 | <pre> |
---|
848 | <a name="del-spec"></a>template <class T> |
---|
849 | void del(proxy<T> const& x); |
---|
850 | </pre> |
---|
851 | |
---|
852 | <dl class="function-semantics"> |
---|
853 | <dt><b>Effects:</b> x.del()</dt> |
---|
854 | </dl> |
---|
855 | <pre> |
---|
856 | <a name="comparisons-spec"></a> |
---|
857 | template<class L,class R> object operator>(L const&l,R const&r); |
---|
858 | template<class L,class R> object operator>=(L const&l,R const&r); |
---|
859 | template<class L,class R> object operator<(L const&l,R const&r); |
---|
860 | template<class L,class R> object operator<=(L const&l,R const&r); |
---|
861 | template<class L,class R> object operator==(L const&l,R const&r); |
---|
862 | template<class L,class R> object operator!=(L const&l,R const&r); |
---|
863 | </pre> |
---|
864 | |
---|
865 | <dl class="function-semantics"> |
---|
866 | <dt><b>Effects:</b> returns the result of applying the operator to |
---|
867 | <code>object(l)</code> and <code>object(r)</code>, respectively, in |
---|
868 | Python.</dt> |
---|
869 | </dl> |
---|
870 | <pre> |
---|
871 | <a name="binary-spec"></a> |
---|
872 | template<class L,class R> object operator+(L const&l,R const&r); |
---|
873 | template<class L,class R> object operator-(L const&l,R const&r); |
---|
874 | template<class L,class R> object operator*(L const&l,R const&r); |
---|
875 | template<class L,class R> object operator/(L const&l,R const&r); |
---|
876 | template<class L,class R> object operator%(L const&l,R const&r); |
---|
877 | template<class L,class R> object operator<<(L const&l,R const&r); |
---|
878 | template<class L,class R> object operator>>(L const&l,R const&r); |
---|
879 | template<class L,class R> object operator&(L const&l,R const&r); |
---|
880 | template<class L,class R> object operator^(L const&l,R const&r); |
---|
881 | template<class L,class R> object operator|(L const&l,R const&r); |
---|
882 | </pre> |
---|
883 | |
---|
884 | <dl class="function-semantics"> |
---|
885 | <dt><b>Effects:</b> returns the result of applying the operator to |
---|
886 | <code>object(l)</code> and <code>object(r)</code>, respectively, in |
---|
887 | Python.</dt> |
---|
888 | </dl> |
---|
889 | <pre> |
---|
890 | <a name="assignment-spec"></a> |
---|
891 | template<class R> object& operator+=(object&l,R const&r); |
---|
892 | template<class R> object& operator-=(object&l,R const&r); |
---|
893 | template<class R> object& operator*=(object&l,R const&r); |
---|
894 | template<class R> object& operator/=(object&l,R const&r); |
---|
895 | template<class R> object& operator%=(object&l,R const&r); |
---|
896 | template<class R> object& operator<<=(object&l,R const&r) |
---|
897 | template<class R> object& operator>>=(object&l,R const&r); |
---|
898 | template<class R> object& operator&=(object&l,R const&r); |
---|
899 | template<class R> object& operator^=(object&l,R const&r); |
---|
900 | template<class R> object& operator|=(object&l,R const&r); |
---|
901 | </pre> |
---|
902 | |
---|
903 | <dl class="function-semantics"> |
---|
904 | <dt><b>Effects:</b> assigns to l the result of applying the |
---|
905 | corresponding Python inplace operator to <code>l</code> and |
---|
906 | <code>object(r)</code>, respectively.</dt> |
---|
907 | |
---|
908 | <dt><b>Returns:</b> <code>l</code>.</dt> |
---|
909 | </dl> |
---|
910 | |
---|
911 | <pre> |
---|
912 | inline long len(object const& obj); |
---|
913 | </pre> |
---|
914 | |
---|
915 | <dl class="function-semantics"> |
---|
916 | <dt><b>Effects:</b> PyObject_Length(obj.ptr()) </dt> |
---|
917 | <dt><b>Returns:</b> len() of object.</dt> |
---|
918 | </dl> |
---|
919 | |
---|
920 | <h2><a name="examples"></a>Example</h2> |
---|
921 | Python code: |
---|
922 | <pre> |
---|
923 | def sum_items(seq): |
---|
924 | result = 0 |
---|
925 | for x in seq: |
---|
926 | result += x |
---|
927 | return result |
---|
928 | </pre> |
---|
929 | C++ version: |
---|
930 | <pre> |
---|
931 | object sum_items(object seq) |
---|
932 | { |
---|
933 | object result = object(0); |
---|
934 | for (int i = 0; i < len(seq); ++i) |
---|
935 | result += seq[i]; |
---|
936 | return result; |
---|
937 | } |
---|
938 | </pre> |
---|
939 | <p>Revised |
---|
940 | <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan --> |
---|
941 | 13 January, 2006 |
---|
942 | <!--webbot bot="Timestamp" endspan i-checksum="39359" --> |
---|
943 | </p> |
---|
944 | |
---|
945 | <p><i>© Copyright <a href= |
---|
946 | "../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2006.</i></p> |
---|
947 | </body> |
---|
948 | </html> |
---|