Boost logo

Boost Users :

Subject: Re: [Boost-users] multi-type containers
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-04-19 10:38:40


AMDG

László Marák wrote:
> I am getting started with boost.python. I want to port an image processing
> library into python. My problem is, that I have several pixel types (like
> int, float, etc.) which I'd love to handle in the same object by
> downcasting. In c++ it's something like this:
>
> class image {};
>
> class float_image : image {
> float * pixels; // or boost::array_ptr<float>
> }
>
> class int_image : image {
> int * pixels; // or boost::array_ptr<int>
> }
>
> I can create the image object by:
>
> image * A = new float_image()
> image * B = new int_image()
>
> Now I'd have a virtual functions
>
> virtual float image::get_element()
> virtual int image::get_element()
>
> obviously this won't pass in c++, but in python it should pose no
> difficulty, as python uses dynamic casting. Is there a manner to do this
> with c++/boost/python?
>
> thank you for considering,
>

Because python is dynamically typed, you don't necessarily need to
use inheritance. You can just have both classes provide a function
called get_elements.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net