Boost logo

Boost Users :

Subject: [Boost-users] Boost.python - How to export shared_ptr<vector<shared_ptr<string> > >?
From: blp330 (blp330_at_[hidden])
Date: 2009-03-07 11:19:42


Hi,

I have a function that returns type
boost::shared_ptr<std::vector<boost::shared_ptr<std::string> > >,
I have registered that:

// boost::shared_ptr<std::string> -> PyString Converter.
struct StringPointerToPyString {
    static ::PyObject* convert( ::boost::shared_ptr<::std::string> const&
p_str ){
        return ::PyString_FromStringAndSize( p_str->data(), p_str->size() );
    }
};

bp::class_< std::vector<StringPtr> > ("vector_StringPtr")
    .def (bp::vector_indexing_suite< std::vector<StringPtr> >());
bp::register_ptr_to_python< boost::shared_ptr< std::vector<StringPtr> > >();

It works fine but when I try to access the returned vector, I got error:

>>> v = my_function()
>>> v[0]
TypeError: No Python class registered for C++ class class
boost::shared_ptr<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > >

I tried to add

bp::register_ptr_to_python< boost::shared_ptr< std::string > >();

But still not work.

How can I make it work?

Thanks you very much.

-- 
View this message in context: http://www.nabble.com/Boost.python---How-to-export-shared_ptr%3Cvector%3Cshared_ptr%3Cstring%3E-%3E-%3E--tp22389131p22389131.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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