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 Linux/x86 (vers 1st September 2004), see www.w3.org"> |
---|
10 | <meta http-equiv="Content-Type" content= |
---|
11 | "text/html; charset=us-ascii"> |
---|
12 | <link rel="stylesheet" type="text/css" href="../boost.css"> |
---|
13 | |
---|
14 | <title>Boost.Python - |
---|
15 | <boost/python/docstring_options.hpp></title> |
---|
16 | </head> |
---|
17 | |
---|
18 | <body> |
---|
19 | <table border="0" cellpadding="7" cellspacing="0" width="100%" |
---|
20 | summary="header"> |
---|
21 | <tr> |
---|
22 | <td valign="top" width="300"> |
---|
23 | <h3><a href="../../../../index.htm"><img height="86" width= |
---|
24 | "277" alt="C++ Boost" src="../../../../boost.png" border= |
---|
25 | "0"></a></h3> |
---|
26 | </td> |
---|
27 | |
---|
28 | <td valign="top"> |
---|
29 | <h1 align="center"><a href= |
---|
30 | "../index.html">Boost.Python</a></h1> |
---|
31 | |
---|
32 | <h2 align="center">Header |
---|
33 | <boost/python/docstring_options.hpp></h2> |
---|
34 | </td> |
---|
35 | </tr> |
---|
36 | </table> |
---|
37 | <hr> |
---|
38 | |
---|
39 | <h2>Contents</h2> |
---|
40 | |
---|
41 | <dl class="page-index"> |
---|
42 | <dt><a href="#introduction">Introduction</a></dt> |
---|
43 | |
---|
44 | <dt><a href="#classes">Classes</a></dt> |
---|
45 | |
---|
46 | <dd> |
---|
47 | <dl class="page-index"> |
---|
48 | <dt><a href="#docstring_options-spec">Class |
---|
49 | <code>docstring_options</code></a></dt> |
---|
50 | |
---|
51 | <dd> |
---|
52 | <dl class="page-index"> |
---|
53 | <dt><a href="#docstring_options-spec-synopsis">Class |
---|
54 | <code>docstring_options</code> synopsis</a></dt> |
---|
55 | |
---|
56 | <dt><a href="#docstring_options-spec-ctors">Class |
---|
57 | <code>docstring_options</code> constructors</a></dt> |
---|
58 | |
---|
59 | <dt><a href="#docstring_options-spec-dtors">Class |
---|
60 | <code>docstring_options</code> destructors</a></dt> |
---|
61 | |
---|
62 | <dt><a href="#docstring_options-spec-modifiers">Class |
---|
63 | <code>docstring_options</code> modifiers</a></dt> |
---|
64 | </dl> |
---|
65 | </dd> |
---|
66 | </dl> |
---|
67 | </dd> |
---|
68 | |
---|
69 | <dt><a href="#examples">Examples</a></dt> |
---|
70 | </dl> |
---|
71 | <hr> |
---|
72 | |
---|
73 | <h2><a name="introduction" id= |
---|
74 | "introduction"></a>Introduction</h2> |
---|
75 | |
---|
76 | <p>Boost.Python supports user-defined docstrings with automatic |
---|
77 | appending of C++ signatures. These features are enabled by |
---|
78 | default. The <code>class docstring_options</code> is available to |
---|
79 | selectively suppress the user-defined docstrings, signatures, or |
---|
80 | both.</p> |
---|
81 | |
---|
82 | <h2><a name="classes" id="classes"></a>Classes</h2> |
---|
83 | |
---|
84 | <h3><a name="docstring_options-spec" id= |
---|
85 | "docstring_options-spec"></a>Class |
---|
86 | <code>docstring_options</code></h3> |
---|
87 | |
---|
88 | <p>Controls the appearance of docstrings of wrapped functions and |
---|
89 | member functions for the life-time of the instance. The instances |
---|
90 | are noncopyable to eliminate the possibility of surprising side |
---|
91 | effects.</p> |
---|
92 | |
---|
93 | <h4><a name="docstring_options-spec-synopsis" id= |
---|
94 | "docstring_options-spec-synopsis"></a>Class |
---|
95 | <code>docstring_options</code> synopsis</h4> |
---|
96 | <pre> |
---|
97 | namespace boost { namespace python { |
---|
98 | |
---|
99 | class docstring_options : boost::noncopyable |
---|
100 | { |
---|
101 | public: |
---|
102 | docstring_options(bool show_all=true); |
---|
103 | |
---|
104 | docstring_options(bool show_user_defined, bool show_signatures); |
---|
105 | |
---|
106 | ~docstring_options(); |
---|
107 | |
---|
108 | void |
---|
109 | disable_user_defined(); |
---|
110 | |
---|
111 | void |
---|
112 | enable_user_defined(); |
---|
113 | |
---|
114 | void |
---|
115 | disable_signatures(); |
---|
116 | |
---|
117 | void |
---|
118 | enable_signatures(); |
---|
119 | |
---|
120 | void |
---|
121 | disable_all(); |
---|
122 | |
---|
123 | void |
---|
124 | enable_all(); |
---|
125 | }; |
---|
126 | |
---|
127 | }} |
---|
128 | </pre> |
---|
129 | |
---|
130 | <h4><a name="docstring_options-spec-ctors" id= |
---|
131 | "docstring_options-spec-ctors"></a>Class |
---|
132 | <code>docstring_options</code> constructors</h4> |
---|
133 | <pre> |
---|
134 | docstring_options(bool show_all=true); |
---|
135 | </pre> |
---|
136 | |
---|
137 | <dl class="function-semantics"> |
---|
138 | <dt><b>Effects:</b> Constructs a <code>docstring_options</code> |
---|
139 | object which controls the appearance of function and |
---|
140 | member-function docstrings defined in the code that follows. If |
---|
141 | <code>show_all</code> is <code>true</code>, both the |
---|
142 | user-defined docstrings and the automatically generated C++ |
---|
143 | signatures are shown. If <code>show_all</code> is |
---|
144 | <code>false</code> the <code>__doc__</code> attributes are |
---|
145 | <code>None</code>.</dt> |
---|
146 | </dl> |
---|
147 | <pre> |
---|
148 | docstring_options(bool show_user_defined, bool show_signatures); |
---|
149 | </pre> |
---|
150 | |
---|
151 | <dl class="function-semantics"> |
---|
152 | <dt><b>Effects:</b> Constructs a <code>docstring_options</code> |
---|
153 | object which controls the appearance of function and |
---|
154 | member-function docstrings defined in the code that follows. |
---|
155 | Iff <code>show_user_defined</code> is <code>true</code>, the |
---|
156 | user-defined docstrings are shown. Iff |
---|
157 | <code>show_signatures</code> is <code>true</code>, C++ |
---|
158 | signatures are automatically added. If both |
---|
159 | <code>show_user_defined</code> and <code>show_signatures</code> |
---|
160 | are <code>false</code>, the <code>__doc__</code> attributes are |
---|
161 | <code>None</code>.</dt> |
---|
162 | </dl> |
---|
163 | |
---|
164 | <h4><a name="docstring_options-spec-dtors" id= |
---|
165 | "docstring_options-spec-dtors"></a>Class |
---|
166 | <code>docstring_options</code> destructors</h4> |
---|
167 | <pre> |
---|
168 | ~docstring_options(); |
---|
169 | </pre> |
---|
170 | |
---|
171 | <dl class="function-semantics"> |
---|
172 | <dt><b>Effects:</b> Restores the previous state of the |
---|
173 | docstring options. In particular, if |
---|
174 | <code>docstring_options</code> instances are in nested C++ |
---|
175 | scopes the settings effective in the enclosing scope are |
---|
176 | restored. If the last <code>docstring_options</code> instance |
---|
177 | goes out of scope the default "all on" settings are |
---|
178 | restored.</dt> |
---|
179 | </dl> |
---|
180 | |
---|
181 | <h4><a name="docstring_options-spec-modifiers" id= |
---|
182 | "docstring_options-spec-modifiers"></a>Class |
---|
183 | <code>docstring_options</code> modifier functions</h4> |
---|
184 | <pre> |
---|
185 | void disable_user_defined(); |
---|
186 | void enable_user_defined(); |
---|
187 | void disable_signatures(); |
---|
188 | void enable_signatures(); |
---|
189 | void disable_all(); |
---|
190 | void enable_all(); |
---|
191 | </pre> |
---|
192 | |
---|
193 | <dl class="function-semantics"> |
---|
194 | <dt>These member functions dynamically change the appearance of |
---|
195 | docstrings in the code that follows. The |
---|
196 | <code>*_user_defined()</code> and <code>*_signatures()</code> |
---|
197 | member functions are provided for fine-grained control. The |
---|
198 | <code>*_all()</code> member functions are convenient shortcuts |
---|
199 | to manipulate both settings simultaneously.</dt> |
---|
200 | </dl> |
---|
201 | |
---|
202 | <h2><a name="examples" id="examples"></a>Examples</h2> |
---|
203 | |
---|
204 | <h4>Docstring options defined at compile time</h4> |
---|
205 | <pre> |
---|
206 | #include <boost/python/module.hpp> |
---|
207 | #include <boost/python/def.hpp> |
---|
208 | #include <boost/python/docstring_options.hpp> |
---|
209 | |
---|
210 | void foo() {} |
---|
211 | |
---|
212 | BOOST_PYTHON_MODULE(demo) |
---|
213 | { |
---|
214 | using namespace boost::python; |
---|
215 | docstring_options doc_options(DEMO_DOCSTRING_SHOW_ALL); |
---|
216 | def("foo", foo, "foo doc"); |
---|
217 | } |
---|
218 | </pre>If compiled with <code>-DDEMO_DOCSTRING_SHOW_ALL=true</code>: |
---|
219 | <pre> |
---|
220 | >>> import demo |
---|
221 | >>> print demo.foo.__doc__ |
---|
222 | foo doc |
---|
223 | C++ signature: |
---|
224 | foo(void) -> void |
---|
225 | </pre>If compiled with |
---|
226 | <code>-DDEMO_DOCSTRING_SHOW_ALL=false</code>: |
---|
227 | <pre> |
---|
228 | >>> import demo |
---|
229 | >>> print demo.foo.__doc__ |
---|
230 | None |
---|
231 | </pre> |
---|
232 | |
---|
233 | <h4>Selective suppressions</h4> |
---|
234 | <pre> |
---|
235 | #include <boost/python/module.hpp> |
---|
236 | #include <boost/python/def.hpp> |
---|
237 | #include <boost/python/args.hpp> |
---|
238 | #include <boost/python/docstring_options.hpp> |
---|
239 | |
---|
240 | int foo1(int i) { return i; } |
---|
241 | int foo2(long l) { return static_cast<int>(l); } |
---|
242 | int foo3(float f) { return static_cast<int>(f); } |
---|
243 | int foo4(double d) { return static_cast<int>(d); } |
---|
244 | |
---|
245 | BOOST_PYTHON_MODULE(demo) |
---|
246 | { |
---|
247 | using namespace boost::python; |
---|
248 | docstring_options doc_options; |
---|
249 | def("foo1", foo1, arg("i"), "foo1 doc"); |
---|
250 | doc_options.disable_user_defined(); |
---|
251 | def("foo2", foo2, arg("l"), "foo2 doc"); |
---|
252 | doc_options.disable_signatures(); |
---|
253 | def("foo3", foo3, arg("f"), "foo3 doc"); |
---|
254 | doc_options.enable_user_defined(); |
---|
255 | def("foo4", foo4, arg("d"), "foo4 doc"); |
---|
256 | } |
---|
257 | </pre>Python code: |
---|
258 | <pre> |
---|
259 | >>> import demo |
---|
260 | >>> print demo.foo1.__doc__ |
---|
261 | foo1 doc |
---|
262 | C++ signature: |
---|
263 | foo1(int i) -> int |
---|
264 | >>> print demo.foo2.__doc__ |
---|
265 | C++ signature: |
---|
266 | foo2(long l) -> int |
---|
267 | >>> print demo.foo3.__doc__ |
---|
268 | None |
---|
269 | >>> print demo.foo4.__doc__ |
---|
270 | foo4 doc |
---|
271 | </pre> |
---|
272 | |
---|
273 | <h4>Wrapping from multiple C++ scopes</h4> |
---|
274 | <pre> |
---|
275 | #include <boost/python/module.hpp> |
---|
276 | #include <boost/python/def.hpp> |
---|
277 | #include <boost/python/args.hpp> |
---|
278 | #include <boost/python/docstring_options.hpp> |
---|
279 | |
---|
280 | int foo1(int i) { return i; } |
---|
281 | int foo2(long l) { return static_cast<int>(l); } |
---|
282 | |
---|
283 | int bar1(int i) { return i; } |
---|
284 | int bar2(long l) { return static_cast<int>(l); } |
---|
285 | |
---|
286 | namespace { |
---|
287 | |
---|
288 | void wrap_foos() |
---|
289 | { |
---|
290 | using namespace boost::python; |
---|
291 | // no docstring_options here |
---|
292 | // -> settings from outer C++ scope are in effect |
---|
293 | def("foo1", foo1, arg("i"), "foo1 doc"); |
---|
294 | def("foo2", foo2, arg("l"), "foo2 doc"); |
---|
295 | } |
---|
296 | |
---|
297 | void wrap_bars() |
---|
298 | { |
---|
299 | using namespace boost::python; |
---|
300 | bool show_user_defined = true; |
---|
301 | bool show_signatures = false; |
---|
302 | docstring_options doc_options(show_user_defined, show_signatures); |
---|
303 | def("bar1", bar1, arg("i"), "bar1 doc"); |
---|
304 | def("bar2", bar2, arg("l"), "bar2 doc"); |
---|
305 | } |
---|
306 | } |
---|
307 | |
---|
308 | BOOST_PYTHON_MODULE(demo) |
---|
309 | { |
---|
310 | boost::python::docstring_options doc_options(false); |
---|
311 | wrap_foos(); |
---|
312 | wrap_bars(); |
---|
313 | } |
---|
314 | </pre>Python code: |
---|
315 | <pre> |
---|
316 | >>> import demo |
---|
317 | >>> print demo.foo1.__doc__ |
---|
318 | None |
---|
319 | >>> print demo.foo2.__doc__ |
---|
320 | None |
---|
321 | >>> print demo.bar1.__doc__ |
---|
322 | bar1 doc |
---|
323 | >>> print demo.bar2.__doc__ |
---|
324 | bar2 doc |
---|
325 | </pre> |
---|
326 | |
---|
327 | <h4>See also: <code>boost/libs/python/test/docstring.cpp</code> |
---|
328 | and <code>docstring.py</code></h4> |
---|
329 | |
---|
330 | <p>Revised |
---|
331 | <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan --> |
---|
332 | 16 January, 2006 |
---|
333 | <!--webbot bot="Timestamp" endspan i-checksum="39359" --></p> |
---|
334 | |
---|
335 | <p><i>© Copyright <a href= |
---|
336 | "../../../../people/ralf_w_grosse_kunstleve.htm">Ralf W. |
---|
337 | Grosse-Kunstleve</a> 2006.</i></p> |
---|
338 | </body> |
---|
339 | </html> |
---|