[C++-sig] using boost::python::list ....

Eric Texier erictexier at gmail.com
Thu Jul 24 21:49:25 CEST 2008


Hi,
I was wondering if you someone can help me on this one.
I would like to return a dictionary with all the key/value of a c++ object
(a camera is this case)
some of these values are list ( position = [x,y,z]).  I'm tempted to
allocate those list dynamically but
I'm concern about who is going to manage them.(delete  ...reference count)

To make it short:
- should I use the way I do "position" (dynamic) or the way I do for
"lookat"(static).?
- if I allocate the list as a value of my dictionary key, is there anything
else to do in term of reference count etc...?

Thanks for you help.
Eric


namespace bp=boost::python;

bp::dict
getAsDict(ICam& myCam)
{
       bp::dict  retvals;
       // position
        bp::list  *plist = new bp::list();
        const Imath::V3f& p = myCam.position();
        plist->append(p.x);
        plist->append(p.y);
        plist->append(p.z);
        retvals["position"] = plist;

        // lookat
        const Imath::V3f& d = myCam.lookat();
        bp::list  llist;
        llist.append(d.x);
        llist.append(d.y);
        llist.append(d.z);
        retvals["direction"] = llist;

return retvals;
}



BOOST_PYTHON_MODULE(iParts)
{

class_<ICam>("ICam")
     .def("getAsDict",&getAsDict,"return all the value in a dict")
     ;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080724/560095a9/attachment.htm>


More information about the Cplusplus-sig mailing list