[C++-sig] newbie questions
David Abrahams
dave at boost-consulting.com
Mon Oct 7 20:04:25 CEST 2002
Stefan Seefeld <stefan.seefeld at orthosoft.ca> writes:
> hi there,
>
> now that I have taken the first hurdles, I come back
> with more questions :)
>
> I want to create a python frontend for a set of libraries /
> modules I'm working with.
You've come to the right place!
> I'v got an interface ('Foo') that is implemented
> at a couple of places ('FooImpl1', 'FooImpl2', etc.),
> and I have a factory that instantiates them depending
> on a string argument.
>
> It looks like the natural thing to do would be to make the python
> front end expose the interface 'Foo', but instead of exposing
> Foo's constructor, the Foo factory is used:
>
> > foo1 = Foo("FooImpl1")
> > foo2 = Foo("FooImpl2")
>
> How is this to be done ? It looks like I should play with
> 'HeldType', but I could't get it working yet.
How about using boost::shared_ptr<Foo> as your HeldType and returning
boost::shared_ptr<Foo> from your factory function?
> Also, If I use
> a 'class_' where the HeldType is a pointer type, how should
> I manage ownership ?
Best not to use a raw pointer, since (I guess it's obvious) managing
ownership is tough. If you use boost::shared_ptr or std::auto_ptr
ownership will be managed for you.
HTH,
Dave
--
David Abrahams * Boost Consulting
dave at boost-consulting.com * http://www.boost-consulting.com
More information about the Cplusplus-sig
mailing list