Note that there are some explanatory texts on larger screens.

plurals
  1. POBoost python wrapping a virtual method
    primarykey
    data
    text
    <p>I'm using boost python to create a binding to a c++ library. A number of classes in this library have virtual methods which accept iterator/const_iterator types as arguments. I don't particularly want to expose these types but would prefer to create some wrappers around these virtual methods that accept the appropriate container instead. My question is, is it safe to do this wrapping in the 'default implementation' function ?</p> <p>e.g. </p> <pre><code>class Test { public: Test(); virtual ~Test(); virtual void iterate(std::vector&lt;int&gt;::iterator it); }; </code></pre> <p>then with the wrapper class wrap the default..</p> <pre><code>struct Test_wrapper: Test, boost::python::wrapper&lt;Test&gt; { ..... virtual void iterate(std::vector&lt;int&gt;::iterator it); void default_iterate(std::vector&lt;int&gt; it) { Test::iterate(it.begin()); } }; </code></pre> <p>and setting up the binding with...</p> <pre><code>boost::python::class_&lt; Test_wrapper &gt;("Test") .def("iterate" ,(void ( Test_wrapper::* )(std::vector&lt;int&gt;))(&amp;Test_wrapper::default_iterate)); </code></pre> <p>I'm unsure about this because the tutorial says that two functions need to be passed to 'def' but just passing one seems to work.. (<a href="http://www.boost.org/doc/libs/1_43_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_virtual_functions" rel="nofollow">http://www.boost.org/doc/libs/1_43_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_virtual_functions</a>)</p> <p>Any advice with this would be greatly appreciated.<br> thanks in advance,<br> Babak</p> <p><strong>Edit</strong>:<br> More specifically I'm trying to bind a class which contains a method 'voxelToWorld'. This method transforms the positions in wsP based on points in vsP/end. I would like to wrap this function up so that its interface is more 'pythonic', however I'm not sure of the correct way to do this while kepping it virtual as well. </p> <pre><code>class FieldMapping { public: ... virtual void voxelToWorld(std::vector&lt;V3d&gt;::const_iterator vsP, std::vector&lt;V3d&gt;::const_iterator end, std::vector&lt;V3d&gt;::iterator wsP); }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload