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 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<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/object.hpp></title>
</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 align="center"><a href="../index.html">Boost.Python</a></h1>
<h2 align="center">Header <boost/python/object.hpp></h2>
</td>
</tr>
</table>
<hr>
<h2>Contents</h2>
<dl class="page-index">
<dt><a href="#introduction">Introduction</a></dt>
<dt><a href="#types">Types</a></dt>
<dd>
<dl class="page-index">
<dt><a href="#slice_nil-spec">slice_nil</a></dt>
</dl>
</dd>
<dt><a href="#classes">Classes</a></dt>
<dd>
<dl class="page-index">
<dt><a href="#const_attribute_policies-spec">Class
<code>const_attribute_policies</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#const_attribute_policies-spec-synopsis">Class
<code>const_attribute_policies</code> synopsis</a></dt>
<dt><a href="#const_attribute_policies-spec-statics">Class
<code>const_attribute_policies</code> static functions</a></dt>
</dl>
</dd>
<dt><a href="#attribute_policies-spec">Class
<code>attribute_policies</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#attribute_policies-spec-synopsis">Class
<code>attribute_policies</code> synopsis</a></dt>
<dt><a href="#attribute_policies-spec-statics">Class
<code>attribute_policies</code> static functions</a></dt>
</dl>
</dd>
<dt><a href="#const_item_policies-spec">Class
<code>const_item_policies</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#const_item_policies-spec-synopsis">Class
<code>const_item_policies</code> synopsis</a></dt>
<dt><a href="#const_item_policies-spec-statics">Class
<code>const_item_policies</code> static functions</a></dt>
</dl>
</dd>
<dt><a href="#item_policies-spec">Class
<code>item_policies</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#item_policies-spec-synopsis">Class
<code>item_policies</code> synopsis</a></dt>
<dt><a href="#item_policies-spec-statics">Class
<code>item_policies</code> static functions</a></dt>
</dl>
</dd>
<dt><a href="#const_slice_policies-spec">Class
<code>const_slice_policies</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#const_slice_policies-spec-synopsis">Class
<code>const_slice_policies</code> synopsis</a></dt>
<dt><a href="#const_slice_policies-spec-statics">Class
<code>const_slice_policies</code> static functions</a></dt>
</dl>
</dd>
<dt><a href="#slice_policies-spec">Class
<code>slice_policies</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#slice_policies-spec-synopsis">Class
<code>slice_policies</code> synopsis</a></dt>
<dt><a href="#slice_policies-spec-statics">Class
<code>slice_policies</code> static functions</a></dt>
</dl>
</dd>
<dt><a href="#object_operators-spec">Class
<code>object_operators</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#object_operators-spec-synopsis">Class
<code>object_operators</code> synopsis</a></dt>
<dt><a href="#object_operators-spec-observers">Class
<code>object_operators</code> observer functions</a></dt>
</dl>
</dd>
<dt><a href="#object-spec">Class <code>object</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#object-spec-synopsis">Class <code>object</code>
synopsis</a></dt>
<dt><a href="#object-spec-ctors">Class <code>object</code>
constructors and destructor</a></dt>
<dt><a href="#object-spec-modifiers">Class template
<code>object</code> modifier functions</a></dt>
<dt><a href="#object-spec-observers">Class template
<code>object</code> observer functions</a></dt>
</dl>
</dd>
<dt><a href="#proxy-spec">Class template
<code>proxy</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#proxy-spec-synopsis">Class template
<code>proxy</code> synopsis</a></dt>
<dt><a href="#proxy-spec-modifiers">Class template
<code>proxy</code> modifier functions</a></dt>
<dt><a href="#proxy-spec-observers">Class template
<code>proxy</code> observer functions</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="#functions">Functions</a></dt>
<dd>
<dl class="page-index">
<dt><a href="#del-spec">del</a></dt>
<dt><a href="#comparisons-spec">comparisons</a></dt>
<dt><a href="#binary-spec">binary operations</a></dt>
<dt><a href="#assignment-spec">assignment operations</a></dt>
</dl>
<dl class="page-index">
<dt><a href="#object_operators-spec">operators</a></dt>
</dl>
</dd>
<dt><a href="#examples">Example</a></dt>
</dl>
<hr>
<h2><a name="introduction"></a>Introduction</h2>
<p>Exposes the generic Python object wrapper class <code>object</code>,
and related classes. In order to avoid some potenential problems with
argument-dependent lookup and the generalized operators defined on
<code>object</code>, all these facilities are defined in
<code>namespace boost::python::api</code>, and <code>object</code>
is imported into <code>namespace boost::python</code> with a
<i>using-declaration</i>.</p>
<h2><a name="types"></a>Types</h2>
<p><a name="slice_nil-spec"></a></p>
<pre>
class slice_nil;
static const _ = slice_nil();
</pre>
A type that can be used to get the effect of leaving out an index in a
Python slice expression:
<pre>
>>> x[:-1]
>>> x[::-1]
</pre>
C++ equivalent:
<pre>
x.slice(_,-1)
x[slice(_,_,-1)]
</pre>
<h2><a name="classes"></a>Classes</h2>
<!-- begin -->
<h3><a name="const_attribute_policies-spec"></a>Class
<code>const_attribute_policies</code></h3>
<p>The policies which are used for proxies representing an attribute
access to a <code>const object</code>.</p>
<h4><a name="const_attribute_policies-spec-synopsis"></a>Class
<code>const_attribute_policies</code> synopsis</h4>
<pre>
namespace boost { namespace python { namespace api
{
struct const_attribute_policies
{
typedef char const* key_type;
static object get(object const& target, char const* key);
};
}}}
</pre>
<h4><a name="const_attribute_policies-spec-statics"></a>Class
<code>const_attribute_policies</code> static functions</h4>
<pre>
static object get(object const& target, char const* key);
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> <code>key</code> is an <a href=
"definitions.html#ntbs">ntbs</a>.</dt>
<dt><b>Effects:</b> accesses the attribute of <code>target</code> named
by <code>key</code>.</dt>
<dt><b>Returns:</b> An <code>object</code> managing the result of the
attribute access.</dt>
<dt><b>Throws:</b> <code><a href=
"errors.html#error_already_set-spec">error_already_set</a></code> if a
Python exception is raised.</dt>
</dl>
<h3><a name="attribute_policies-spec"></a>Class
<code>attribute_policies</code></h3>
<p>The policies which are used for proxies representing an attribute
access to a mutable <code>object</code>.</p>
<h4><a name="attribute_policies-spec-synopsis"></a>Class
<code>attribute_policies</code> synopsis</h4>
<pre>
namespace boost { namespace python { namespace api
{
struct attribute_policies : const_attribute_policies
{
static object const& set(object const& target, char const* key, object const& value);
static void del(object const&target, char const* key);
};
}}}
</pre>
<h4><a name="attribute_policies-spec-statics"></a>Class
<code>attribute_policies</code> static functions</h4>
<pre>
static object const& set(object const& target, char const* key, object const& value);
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> <code>key</code> is an <a href=
"definitions.html#ntbs">ntbs</a>.</dt>
<dt><b>Effects:</b> sets the attribute of <code>target</code> named by
<code>key</code> to <code>value</code>.</dt>
<dt><b>Throws:</b> <code><a href=
"errors.html#error_already_set-spec">error_already_set</a></code> if a
Python exception is raised.</dt>
</dl>
<pre>
static void del(object const&target, char const* key);
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> <code>key</code> is an <a href=
"definitions.html#ntbs">ntbs</a>.</dt>
<dt><b>Effects:</b> deletes the attribute of <code>target</code> named
by <code>key</code>.</dt>
<dt><b>Throws:</b> <code><a href=
"errors.html#error_already_set-spec">error_already_set</a></code> if a
Python exception is raised.</dt>
</dl>
<!-- end -->
<!-- begin -->
<h3><a name="const_item_policies-spec"></a>Class
<code>const_item_policies</code></h3>
<p>The policies which are used for proxies representing an item access
(via the Python bracket operators <code>[]</code>) to a
<code>const object</code>.</p>
<h4><a name="const_item_policies-spec-synopsis"></a>Class
<code>const_item_policies</code> synopsis</h4>
<pre>
namespace boost { namespace python { namespace api
{
struct const_item_policies
{
typedef object key_type;
static object get(object const& target, object const& key);
};
}}}
</pre>
<h4><a name="const_item_policies-spec-statics"></a>Class
<code>const_item_policies</code> static functions</h4>
<pre>
static object get(object const& target, object const& key);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> accesses the item of <code>target</code> specified
by <code>key</code>.</dt>
<dt><b>Returns:</b> An <code>object</code> managing the result of the
item access.</dt>
<dt><b>Throws:</b> <code><a href=
"errors.html#error_already_set-spec">error_already_set</a></code> if a
Python exception is raised.</dt>
</dl>
<h3><a name="item_policies-spec"></a>Class
<code>item_policies</code></h3>
<p>The policies which are used for proxies representing an item access
(via the Python bracket operators <code>[]</code>) to a mutable
<code>object</code>.</p>
<h4><a name="item_policies-spec-synopsis"></a>Class
<code>item_policies</code> synopsis</h4>
<pre>
namespace boost { namespace python { namespace api
{
struct item_policies : const_item_policies
{
static object const& set(object const& target, object const& key, object const& value);
static void del(object const& target, object const& key);
};
}}}
</pre>
<h4><a name="item_policies-spec-statics"></a>Class
<code>item_policies</code> static functions</h4>
<pre>
static object const& set(object const& target, object const& key, object const& value);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> sets the item of <code>target</code> specified by
<code>key</code> to <code>value</code>.</dt>
<dt><b>Throws:</b> <code><a href=
"errors.html#error_already_set-spec">error_already_set</a></code> if a
Python exception is raised.</dt>
</dl>
<pre>
static void del(object const& target, object const& key);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> deletes the item of <code>target</code> specified
by <code>key</code>.</dt>
<dt><b>Throws:</b> <code><a href=
"errors.html#error_already_set-spec">error_already_set</a></code> if a
Python exception is raised.</dt>
</dl>
<!-- end -->
<!-- begin -->
<h3><a name="const_slice_policies-spec"></a>Class
<code>const_slice_policies</code></h3>
<p>The policies which are used for proxies representing an slice access
(via the Python slice notation
<code>[</code><i>x</i><code>:</code><i>y</i><code>]</code>) to a
<code>const object</code>.</p>
<h4><a name="const_slice_policies-spec-synopsis"></a>Class
<code>const_slice_policies</code> synopsis</h4>
<pre>
namespace boost { namespace python { namespace api
{
struct const_slice_policies
{
typedef std::pair<handle<>, handle<> > key_type;
static object get(object const& target, key_type const& key);
};
}}}
</pre>
<h4><a name="const_slice_policies-spec-statics"></a>Class
<code>const_slice_policies</code> static functions</h4>
<pre>
static object get(object const& target, key_type const& key);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> accesses the slice of <code>target</code> specified
by <code>key</code>.</dt>
<dt><b>Returns:</b> An <code>object</code> managing the result of the
slice access.</dt>
<dt><b>Throws:</b> <code><a href=
"errors.html#error_already_set-spec">error_already_set</a></code> if a
Python exception is raised.</dt>
</dl>
<h3><a name="slice_policies-spec"></a>Class
<code>slice_policies</code></h3>
<p>The policies which are used for proxies representing an slice access
to a mutable <code>object</code>.</p>
<h4><a name="slice_policies-spec-synopsis"></a>Class
<code>slice_policies</code> synopsis</h4>
<pre>
namespace boost { namespace python { namespace api
{
struct slice_policies : const_slice_policies
{
static object const& set(object const& target, key_type const& key, object const& value);
static void del(object const& target, key_type const& key);
};
}}}
</pre>
<h4><a name="slice_policies-spec-statics"></a>Class
<code>slice_policies</code> static functions</h4>
<pre>
static object const& set(object const& target, key_type const& key, object const& value);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> sets the slice of <code>target</code> specified by
<code>key</code> to <code>value</code>.</dt>
<dt><b>Throws:</b> <code><a href=
"errors.html#error_already_set-spec">error_already_set</a></code> if a
Python exception is raised.</dt>
</dl>
<pre>
static void del(object const& target, key_type const& key);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> deletes the slice of <code>target</code> specified
by <code>key</code>.</dt>
<dt><b>Throws:</b> <code><a href=
"errors.html#error_already_set-spec">error_already_set</a></code> if a
Python exception is raised.</dt>
</dl>
<!-- end -->
<h3><a name="object_operators-spec"></a>Class template
<code>object_operators<U></code></h3>
<p>This is the base class of <code>object</code> and its
<code>proxy</code> template used to supply common interface: member
functions, and operators which must be defined within the class body. Its
template parameter <code>U</code> is expected to be a class derived from
<code>object_operators<U></code>. In practice users should never
use this class directly, but it is documented here because it supplies
important interface to <code>object</code> and its proxies.</p>
<h4><a name="object_operators-spec-synopsis"></a>Class template
<code>object_operators</code> synopsis</h4>
<pre>
namespace boost { namespace python { namespace api
{
template <class U>
class object_operators
{
public:
// function call
//
object operator()() const;
template <class A0>
object operator()(A0 const&) const;
template <class A0, class A1>
object operator()(A0 const&, A1 const&) const;
...
template <class A0, class A1,...class An>
object operator()(A0 const&, A1 const&,...An const&) const;
// truth value testing
//
typedef unspecified bool_type;
operator bool_type() const;
// Attribute access
//
proxy<const_object_attribute> attr(char const*) const;
proxy<object_attribute> attr(char const*);
// item access
//
template <class T>
proxy<const_object_item> operator[](T const& key) const;
template <class T>
proxy<object_item> operator[](T const& key);
// slicing
//
template <class T, class V>
proxy<const_object_slice> slice(T const& start, V const& end) const
template <class T, class V>
proxy<object_slice> slice(T const& start, V const& end);
};
}}}
</pre>
<h4><a name="object_operators-spec-observers"></a>Class template
<code>object_operators</code> observer functions</h4>
<pre>
object operator()() const;
template <class A0>
object operator()(A0 const&) const;
template <class A0, class A1>
object operator()(A0 const&, A1 const&) const;
...
template <class A0, class A1,...class An>
object operator()(A0 const& a1, A1 const& a2,...An const& aN) const;
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
call<object>(object(*static_cast<U*>(this)).ptr(), a1,
a2,...aN)</dt>
</dl>
<pre>
operator bool_type() const;
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> Tests truth value of <code>*this</code>.</dt>
<dt><b>Returns:</b>
call<object>(object(*static_cast<U*>(this)).ptr(), a1,
a2,...aN)</dt>
</dl>
<pre>
proxy<const_object_attribute> attr(char const* name) const;
proxy<object_attribute> attr(char const* name);
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> name is an <a href=
"definitions.html#ntbs">ntbs</a>.</dt>
<dt><b>Effects:</b> accesses the named attribute of
<code>*this</code>.</dt>
<dt><b>Returns:</b> a proxy object which binds
<code>object(*static_cast<U*>(this))</code> as its target, and
<code>name</code> as its key.</dt>
</dl>
<pre>
template <class T>
proxy<const_object_item> operator[](T const& key) const;
template <class T>
proxy<object_item> operator[](T const& key);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> accesses the item of <code>*this</code> indicated
by <code>key</code>.</dt>
<dt><b>Returns:</b> a proxy object which binds
<code>object(*static_cast<U*>(this))</code> as its target, and
<code>object(key)</code> as its key.</dt>
</dl>
<pre>
template <class T, class V>
proxy<const_object_slice> slice(T const& start; start, V const& finish) const
template <class T, class V>
proxy<object_slice> slice(T const& start; start, V const& finish);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> accesses the slice of <code>*this</code> indicated
by <code>std::make_pair(object(start), object(finish))</code>.</dt>
<dt><b>Returns:</b> a proxy object which binds
<code>object(*static_cast<U*>(this))</code> as its target, and
<code>std::make_pair(object(start), object(finish))</code> as its
key.</dt>
</dl>
<!-- -->
<h3><a name="object-spec"></a>Class <code>object</code></h3>
<p>The intention is that <code>object</code> acts as much like a
Python variable as possible. Thus expressions you'd expect to work
in Python should generally work in the same way from C++. Most of
<code>object</code>'s interface is provided by its base class
<code><a
href="#object_operators-spec">object_operators</a><object></code>,
and the <a href="#functions">free functions</a> defined in this
header.
</p>
<h4><a name="object-spec-synopsis"></a>Class <code>object</code>
synopsis</h4>
<pre>
namespace boost { namespace python { namespace api
{
class object : public object_operators<object>
{
public:
object();
object(object const&);
template <class T>
explicit object(T const& x);
~object();
object& operator=(object const&);
PyObject* ptr() const;
};
}}}
</pre>
<h4><a name="object-spec-ctors"></a>Class <code>object</code>
constructors and destructor</h4>
<pre>
object();
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> Constructs an object managing a reference to the
Python <code>None</code> object.</dt>
<dt><b>Throws:</b> nothing.</dt>
</dl>
<pre>
template <class T>
explicit object(T const& x);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> converts <code>x</code> to python and manages a
reference to it.</dt>
<dt><b>Throws:</b> <code>error_already_set</code> and sets a Python
<code>TypeError</code> exception if no such conversion is
possible.</dt>
</dl>
<pre>
~object();
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> decrements the reference count of the
internally-held object.</dt>
</dl>
<h4><a name="object-spec-modifiers"></a>Class <code>object</code>
modifiers</h4>
<pre>
object& operator=(object const& rhs);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> increments the reference count of the object held
by <code>rhs</code> and decrements the reference count of the object
held by <code>*this</code>.</dt>
</dl>
<h4><a name="object-spec-observers"></a>Class <code>object</code>
observers</h4>
<pre>
PyObject* ptr() const;
</pre>
<dl class="function-semantics">
<dt><b>Returns:</b> a pointer to the internally-held Python
object.</dt>
</dl>
<!-- -->
<h3><a name="proxy-spec"></a>Class template <code>proxy</code></h3>
<p>This template is instantiated with various Policies described in this
document in order to implement attribute, item, and slice access for
<code>object</code>. It stores an object of type
<code>Policies::key_type</code>.</p>
<h4><a name="proxy-spec-synopsis"></a>Class template <code>proxy</code>
synopsis</h4>
<pre>
namespace boost { namespace python { namespace api
{
template <class Policies>
class proxy : public object_operators<proxy<Policies> >
{
public:
operator object() const;
proxy const& operator=(proxy const&) const;
template <class T>
inline proxy const& operator=(T const& rhs) const;
void del() const;
template <class R>
proxy operator+=(R const& rhs);
template <class R>
proxy operator-=(R const& rhs);
template <class R>
proxy operator*=(R const& rhs);
template <class R>
proxy operator/=(R const& rhs);
template <class R>
proxy operator%=(R const& rhs);
template <class R>
proxy operator<<=(R const& rhs);
template <class R>
proxy operator>>=(R const& rhs);
template <class R>
proxy operator&=(R const& rhs);
template <class R>
proxy operator|=(R const& rhs);
};
}}}
</pre>
<h4><a name="proxy-spec-observers"></a>Class template <code>proxy</code>
observer functions</h4>
<pre>
operator object() const;
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> applies
<code>Policies::get(</code><i>target</i><code>,</code> <i>key</i>
<code>)</code> with the proxy's target and key objects.</dt>
</dl>
<h4><a name="proxy-spec-modifiers"></a>Class template <code>proxy</code>
modifier functions</h4>
<pre>
proxy const& operator=(proxy const& rhs) const;
template <class T>
inline proxy const& operator=(T const& rhs) const;
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<code>Policies::set(</code><i>target</i><code>,</code> <i>key</i>
<code>, object(rhs))</code> with the proxy's target and key
objects.</dt>
</dl>
<pre>
template <class R>
proxy operator+=(R const& rhs);
template <class R>
proxy operator-=(R const& rhs);
template <class R>
proxy operator*=(R const& rhs);
template <class R>
proxy operator/=(R const& rhs);
template <class R>
proxy operator%=(R const& rhs);
template <class R>
proxy operator<<=(R const& rhs);
template <class R>
proxy operator>>=(R const& rhs);
template <class R>
proxy operator&=(R const& rhs);
template <class R>
proxy operator|=(R const& rhs);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> for a given operator@=,
<code>object(*this) @= rhs;</code></dt>
<dt><b>Returns:</b> <code>*this</code></dt>
</dl>
<pre>
void del() const;
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<code>Policies::del(</code><i>target</i><code>,</code> <i>key</i>
<code>)</code> with the proxy's target and key objects.</dt>
</dl>
<!-- -->
<h2><a name="functions"></a>Functions</h2>
<pre>
<a name="del-spec"></a>template <class T>
void del(proxy<T> const& x);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> x.del()</dt>
</dl>
<pre>
<a name="comparisons-spec"></a>
template<class L,class R> bool operator>(L const&l,R const&r);
template<class L,class R> bool operator>=(L const&l,R const&r);
template<class L,class R> bool operator<(L const&l,R const&r);
template<class L,class R> bool operator<=(L const&l,R const&r);
template<class L,class R> bool operator==(L const&l,R const&r);
template<class L,class R> bool operator!=(L const&l,R const&r);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> returns the result of applying the operator to
<code>object(l)</code> and <code>object(r)</code>, respectively, in
Python.</dt>
</dl>
<pre>
<a name="binary-spec"></a>
template<class L,class R> object operator+(L const&l,R const&r);
template<class L,class R> object operator-(L const&l,R const&r);
template<class L,class R> object operator*(L const&l,R const&r);
template<class L,class R> object operator/(L const&l,R const&r);
template<class L,class R> object operator%(L const&l,R const&r);
template<class L,class R> object operator<<(L const&l,R const&r);
template<class L,class R> object operator>>(L const&l,R const&r);
template<class L,class R> object operator&(L const&l,R const&r);
template<class L,class R> object operator^(L const&l,R const&r);
template<class L,class R> object operator|(L const&l,R const&r);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> returns the result of applying the operator to
<code>object(l)</code> and <code>object(r)</code>, respectively, in
Python.</dt>
</dl>
<pre>
<a name="assignment-spec"></a>
template<class R> object& operator+=(object&l,R const&r);
template<class R> object& operator-=(object&l,R const&r);
template<class R> object& operator*=(object&l,R const&r);
template<class R> object& operator/=(object&l,R const&r);
template<class R> object& operator%=(object&l,R const&r);
template<class R> object& operator<<=(object&l,R const&r)
template<class R> object& operator>>=(object&l,R const&r);
template<class R> object& operator&=(object&l,R const&r);
template<class R> object& operator^=(object&l,R const&r);
template<class R> object& operator|=(object&l,R const&r);
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b> assigns to l the result of applying the
corresponding Python inplace operator to <code>l</code> and
<code>object(r)</code>, respectively.</dt>
<dt><b>Returns:</b> <code>l</code>.</dt>
</dl>
<h2><a name="examples"></a>Example</h2>
Python code:
<pre>
def sum_items(seq):
result = 0
for x in seq:
result += x
return result
</pre>
C++ version:
<pre>
object sum_items(object seq)
{
object result = object(0);
for (int i = 0; i < seq.attr("__len__")(); ++i)
result += seq[i];
return result;
}
</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><i>© Copyright <a href=
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002.</i></p>
</body>
</html>
|