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 - CallPolicies Concept</title> |
---|
14 | </head> |
---|
15 | |
---|
16 | <body link="#0000ff" vlink="#800080"> |
---|
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">CallPolicies Concept</h2> |
---|
29 | </td> |
---|
30 | </tr> |
---|
31 | </table> |
---|
32 | <hr> |
---|
33 | |
---|
34 | <dl class="page-index"> |
---|
35 | <dt><a href="#introduction">Introduction</a></dt> |
---|
36 | |
---|
37 | <dt><a href="#composition">CallPolicies Composition</a></dt> |
---|
38 | |
---|
39 | <dt><a href="#concept-requirements">Concept Requirements</a></dt> |
---|
40 | |
---|
41 | <dd> |
---|
42 | <dl class="page-index"> |
---|
43 | <dt><a href="#CallPolicies-concept">CallPolicies Concept</a></dt> |
---|
44 | </dl> |
---|
45 | </dd> |
---|
46 | </dl> |
---|
47 | |
---|
48 | <h2><a name="introduction"></a>Introduction</h2> |
---|
49 | |
---|
50 | <p>Models of the CallPolicies concept are used to specialize the behavior |
---|
51 | of Python callable objects generated by Boost.Python to wrapped C++ |
---|
52 | objects like function and member function pointers, providing three |
---|
53 | behaviors:</p> |
---|
54 | |
---|
55 | <ol> |
---|
56 | <li><code>precall</code> - Python argument tuple management before the |
---|
57 | wrapped object is invoked</li> |
---|
58 | |
---|
59 | <li><code>result_converter</code> - C++ return value handling</li> |
---|
60 | |
---|
61 | <li><code>postcall</code> - Python argument tuple and result management |
---|
62 | after the wrapped object is invoked</li> |
---|
63 | </ol> |
---|
64 | |
---|
65 | <h2><a name="composition"></a>CallPolicies Composition</h2> |
---|
66 | In order to allow the use of multiple models of CallPolicies in the same |
---|
67 | callable object, Boost.Python's CallPolicies class templates provide a |
---|
68 | chaining interface which allows them to be recursively composed. This |
---|
69 | interface takes the form of an optional template parameter, |
---|
70 | <code>Base</code> which defaults to <a href= |
---|
71 | "default_call_policies.html#default_call_policies-spec"><code>default_call_policies</code></a>. |
---|
72 | By convention, the <code>precall</code> function of the <code>Base</code> |
---|
73 | is invoked <i>after</i> the <code>precall</code> function supplied by the |
---|
74 | outer template, and the <code>postcall</code> function of the |
---|
75 | <code>Base</code> is invoked <i>before</i> the <code>postcall</code> |
---|
76 | function of the outer template. If a <code>result_converter</code> is |
---|
77 | supplied by the outer template, it <i>replaces</i> any |
---|
78 | <code>result_converter</code> supplied by the <code>Base</code>. For an |
---|
79 | example, see <a href= |
---|
80 | "return_internal_reference.html#return_internal_reference-spec"><code>return_internal_reference</code></a>. |
---|
81 | |
---|
82 | |
---|
83 | <h2><a name="concept-requirements"></a>Concept Requirements</h2> |
---|
84 | |
---|
85 | <h3><a name="CallPolicies-concept"></a>CallPolicies Concept</h3> |
---|
86 | |
---|
87 | <p>In the table below, <code><b>x</b></code> denotes an object whose type |
---|
88 | <code><b>P</b></code> is a model of CallPolicies, <code><b>a</b></code> |
---|
89 | denotes a <code>PyObject*</code> pointing to a Python argument tuple |
---|
90 | object, and <code><b>r</b></code> denotes a <code>PyObject*</code> |
---|
91 | referring to a "preliminary" result object.</p> |
---|
92 | |
---|
93 | <table summary="CallPolicies expressions" border="1" cellpadding="5"> |
---|
94 | <tr> |
---|
95 | <td><b>Expression</b></td> |
---|
96 | |
---|
97 | <td><b>Type</b></td> |
---|
98 | |
---|
99 | <td><b>Result/Semantics</b></td> |
---|
100 | </tr> |
---|
101 | |
---|
102 | <tr> |
---|
103 | <td valign="top"><code>x.precall(a)</code></td> |
---|
104 | |
---|
105 | <td>convertible to <code>bool</code></td> |
---|
106 | |
---|
107 | <td>returns <code>false</code> and <code><a href= |
---|
108 | "http://www.python.org/doc/2.2/api/exceptionHandling.html#l2h-71">PyErr_Occurred</a>() != 0</code> |
---|
109 | upon failure, <code>true</code> otherwise.</td> |
---|
110 | </tr> |
---|
111 | |
---|
112 | <tr> |
---|
113 | <td valign="top"><code>P::result_converter</code></td> |
---|
114 | |
---|
115 | <td>A model of <a href= |
---|
116 | "ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator</a>.</td> |
---|
117 | |
---|
118 | <td>An MPL unary <a href= |
---|
119 | "../../../mpl/doc/refmanual/metafunction-class.html">Metafunction |
---|
120 | Class</a> used produce the "preliminary" result object.</td> |
---|
121 | </tr> |
---|
122 | |
---|
123 | <tr> |
---|
124 | <td valign="top"><code>x.postcall(a, r)</code></td> |
---|
125 | |
---|
126 | <td>convertible to <code>PyObject*</code></td> |
---|
127 | |
---|
128 | <td>0 <code>0</code> and <code><a href= |
---|
129 | "http://www.python.org/doc/2.2/api/exceptionHandling.html#l2h-71">PyErr_Occurred</a>() != 0</code> |
---|
130 | upon failure. Must "conserve references" even in the event of an |
---|
131 | exception. In other words, if <code>r</code> is not returned, its |
---|
132 | reference count must be decremented; if another existing object is |
---|
133 | returned, its reference count must be incremented.</td> |
---|
134 | </tr> |
---|
135 | </table> |
---|
136 | Models of CallPolicies are required to be <a href= |
---|
137 | "../../../utility/CopyConstructible.html">CopyConstructible</a>. |
---|
138 | <hr> |
---|
139 | |
---|
140 | <p>Revised |
---|
141 | <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan --> |
---|
142 | 13 November, 2002 |
---|
143 | <!--webbot bot="Timestamp" endspan i-checksum="39359" --> |
---|
144 | </p> |
---|
145 | |
---|
146 | <p><i>© Copyright <a href= |
---|
147 | "../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002.</i></p> |
---|
148 | |
---|
149 | <p>Permission to copy, use, modify, sell and distribute this software is |
---|
150 | granted provided this copyright notice appears in all copies. This |
---|
151 | software is provided "as is" without express or implied warranty, and |
---|
152 | with no claim as to its suitability for any purpose.</p> |
---|
153 | </body> |
---|
154 | </html> |
---|
155 | |
---|