On 19 Apr 2007 00:37:36 -0700, <b class="gmail_sendername">Stou Sandalski</b> <<a href="mailto:stou.sandalski@gmail.com">stou.sandalski@gmail.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br><br>I have a python library created by wrapping the C++ library using<br>Boost.Python, the problem is that the wrappers are not very<br>pythonic.... so I want to add some methods that do not exist in the C+<br>+ implementation, that would create a better Python interface.
<br><br>For example to initialize the data in an object in the library one<br>must iterate through every point, setting a value for each<br>individually.  That's the way it works in C++ but in python it would<br>be nice to instead just have one call that can receive a numpy array
<br>or a tuple. I want to add a call like: setData(array) to the python<br>object, a call that does not exist in the C++ implementation and then<br>in the C++ wrappers actually use setData to iterate through the array<br>
and set the values using the normal C++ method, say setValue(index,<br>value).<br><br>Something along the lines of this (initData is not in the constructor<br>on purpose) C++ object:<br><br>class Foo<br>{<br>public:<br>     void initData(int size)
<br>     {<br>        data = new float[size];<br>     }; // Create the data array<br>     void setValue(int index, float value) // Set given value<br>     {<br>         data[index] = value;<br>     }<br>private:<br>     float *data;
<br>};<br><br><br>In python however I want to do this:<br><br>obj = foo()<br>ar = array([1,2,3,4,5], dtype=float)<br><br>foo.setData(ar)<br><br>Or even better:<br><br>ar = array([1,2,3,4,5], dtype=float)<br>obj = foo(ar)<br>
<br>And have it somehow call initData() and setValue() iteration inside<br>the C++ code of the wrapper.  I've only used SWIG and don't really<br>know much about Boost, I am not even sure how to label what I am<br>
trying to do.<br><br>Can this be done with Boost, without changing the C++ library?</blockquote><div><br>Take a look on next link:<br><a href="http://boost.org/libs/python/doc/tutorial/doc/html/python/techniques.html#python.extending_wrapped_objects_in_python">
http://boost.org/libs/python/doc/tutorial/doc/html/python/techniques.html#python.extending_wrapped_objects_in_python</a> <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Regards,<br><br>Stou<br><br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a><br></blockquote></div><br><br clear="all"><br>-- <br>Roman Yakovenko<br>
C++ Python language binding<br><a href="http://www.language-binding.net/">http://www.language-binding.net/</a>