[C++-sig] Iterators + shared_ptr + Abstract base classes + Pass by reference = help :)
David Abrahams
dave at boost-consulting.com
Sat Jan 4 03:49:01 CET 2003
David Sankel <camio at yahoo.com> writes:
> Hello,
> I have several questions and I think they are all
> most easily answered by example:
>
> class Abstract
> {
> public:
> shared_ptr<Abstract> clone()=0;
> };
>
> class Filter
> {
> public:
> vector<shared_ptr<Abstract> > Abstract data;
> void doFilter( vector<shared_ptr<Abstract> > &result )=0;
> };
>
> How would I use boost.python to allow python code to
> use Filter as a base class?
>
> I figure there is going to be:
>
> class PythonFilter : public Filter
> {
> public:
> void doFilter( vector<shared_ptr<Abstract> >& result)
> {
> //What goes here?
Here you need to invoke call_method<void>(...) with some argument(s).
You could write:
call_method<void>( ref(result) );
But that will only work if you've exposed
vector<shared_ptr<Abstract> >
to Python. My guess is that you haven't.
What type would you like your Python derived class to see when you
override doFilter in Python?
> }
> }
>
> and:
>
> BOOST_PYTHON_MODULE(embedded_Filter)
> {
> class_< Abstract > ("Abstract", no_init );
> class_< Filter,
> PythonFilter >("Filter")
> //What goes here?
So far, nothing. You don't need to (and shouldn't) expose a pure
virtual function to Python.
> ;
>
> }
>
> The python code to look something like this:
>
> import ...
> class SpecificFilter( Filter ):
> def doFilter( self, result )
> #make result some modification of self.data
I don't understand the comment above.
HTH, though.
--
David Abrahams
dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution
More information about the Cplusplus-sig
mailing list