[C++-sig] conversion of std::list<...> parameters in function call

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Thu Jun 20 15:09:50 CEST 2002


--- David Abrahams <david.abrahams at rcn.com> wrote:
> From: "Achim Domma" <achim.domma at syynx.de>
> 
> > once again a conversion question:
> >
> > I want to call a ctor which expects a 'const std::list<Magick::VPath>&'.
> In
> > python I build a list like this:
> >
> > path =
> >
> [PathMovetoAbs(Coordinate(50,50)),PathLinetoVerticalRel(-40),PathClosePath(
> )
> > ]
> >
> > All three PathXXX classes are derived from VPathBase and their
> boost.python
> > wrappers are defined with bases<VPathBase>. VPathBase is declared as
> > implicit convertible to VPath.
> >
> > Is it already possible to do such a conversion at the moment? Should I
> write
> > my own converter or is there a better way?
> 
> I think Ralf has done something like this. Ralf?

The code that David is eluding to is here:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/cctbx/cctbx/include/cctbx/bpl_utils.h?rev=1.2.2.11&only_with_tag=boost_python_v2_transition&content-type=text/vnd.viewcvs-markup

The interesting bit is struct register_container_from_python_list_or_tuple.

See also:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/cctbx/cctbx/misc/bpl_utils.cpp?rev=1.1.2.6&only_with_tag=boost_python_v2_transition&content-type=text/vnd.viewcvs-markup

This code has a flaw (marked with XXX) and will not compile with the latest
CVS. Replacing "ref" by "handle<>" and "make_ref" by "object" is the minimum
that has to be done, but more adjustment might be necessary. A week ago it
worked with std::vector and boost::array. I have not tested it with std::list.
Another adaptor might be required (see struct
variable_size_container_registration_adaptor).

Sorry for all the vagueness. I would not normally have advertised the code, but
who am I to resist David's challenges?

Ralf


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com





More information about the Cplusplus-sig mailing list