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
|
<html>
<head>
<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
<title>Inserting Code</title>
<link rel="stylesheet" href="theme/style.css" type="text/css">
<link rel="prev" href="adding_new_methods.html">
</head>
<body>
<table width="100%" height="48" border="0" cellspacing="2">
<tr>
<td><img src="../../../../boost.png">
</td>
<td width="85%">
<font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Inserting Code</b></font>
</td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="adding_new_methods.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
</tr>
</table>
<p>
You can insert arbitrary code in the generated cpps, just use the functions
<tt>declaration_code</tt> and <tt>module_code</tt>. This will insert the given string in the
respective sections. Example:</p>
<code><pre>
##<span class=identifier>file </span><span class=identifier>A</span><span class=special>.</span><span class=identifier>pyste
</span><span class=identifier>Class</span><span class=special>(</span><span class=string>"A"</span><span class=special>, </span><span class=string>"A.h"</span><span class=special>)
</span><span class=identifier>declaration_code</span><span class=special>(</span><span class=string>"/* declaration_code() comes here */\n"</span><span class=special>)
</span><span class=identifier>module_code</span><span class=special>(</span><span class=string>"/* module_code() comes here */\n"</span><span class=special>)
</span></pre></code>
<p>
Will generate:</p>
<code><pre>
<span class=comment>// Includes ====================================================================
</span><span class=preprocessor>#include </span><span class=special><</span><span class=identifier>boost</span><span class=special>/</span><span class=identifier>python</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>>
// </span><span class=identifier>Using </span><span class=special>=======================================================================
</span><span class=keyword>using </span><span class=keyword>namespace </span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>python</span><span class=special>;
// </span><span class=identifier>Declarations </span><span class=special>================================================================
/* </span><span class=identifier>declaration_code</span><span class=special>() </span><span class=identifier>comes </span><span class=identifier>here </span><span class=special>*/
// </span><span class=identifier>Module </span><span class=special>======================================================================
</span><span class=identifier>BOOST_PYTHON_MODULE</span><span class=special>(</span><span class=identifier>A</span><span class=special>)
{
</span><span class=identifier>class_</span><span class=special>< </span><span class=identifier>A </span><span class=special>>(</span><span class=string>"A"</span><span class=special>, </span><span class=identifier>init</span><span class=special>< >())
.</span><span class=identifier>def</span><span class=special>(</span><span class=identifier>init</span><span class=special>< </span><span class=keyword>const </span><span class=identifier>A</span><span class=special>& >())
;
/* </span><span class=identifier>module_code</span><span class=special>() </span><span class=identifier>comes </span><span class=identifier>here </span><span class=special>*/
}
</span></pre></code>
<table border="0">
<tr>
<td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="adding_new_methods.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="20"><img src="theme/r_arr_disabled.gif" border="0"></td>
</tr>
</table>
<br>
<hr size="1"><p class="copyright">Copyright © 2003 Bruno da Silva de Oliveira<br>Copyright © 2002-2003 Joel de Guzman<br><br>
<font size="2">Permission to copy, use, modify, sell and distribute this document
is granted provided this copyright notice appears in all copies. This document
is provided "as is" without express or implied warranty, and with
no claim as to its suitability for any purpose. </font> </p>
</body>
</html>
|