[C++-sig] Re: Iterators + shared_ptr + Abstract base classes + Pass by reference = help :)
David Sankel
camio at yahoo.com
Sat Jan 4 15:23:35 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> > 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?
I would like the Python derived class to see a list of
Abstracts. I guess this is where I don't understand
how to expose vector<shared_ptr<Abstract> > with the
iterators.
>
> > }
> > }
> >
> > 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.
Wouldn't I need something so a python derived class
could access the Filter::data member?
Also, how would I allow python to see the
Abstract::clone() function?
> > ;
> >
> > }
> >
> > 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.
>
For example:
class specificFiler( Filter ):
def doFilter( self, result ):
result = [x.clone() for x in self.data]
result.reverse()
Does this make more sense?
Thanks,
David J. Sankel
More information about the Cplusplus-sig
mailing list