[C++-sig] Boost Python - How to export boost::shared_ptr<std::string>

Roman Yakovenko roman.yakovenko at gmail.com
Tue Dec 15 09:01:01 CET 2009


On Tue, Dec 15, 2009 at 9:36 AM, Romain CHANU <romainchanu at gmail.com> wrote:
> Hi,
>
> I want to export an attribute which is a boost::shared_ptr<std::string> and
> I got the following error:
> " 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 found an old post on a similar issue :
> http://old.nabble.com/Boost.python---How-to-export-shared_ptr%3Cvector%3Cshared_ptr%3Cstring%3E-%3E-%3E--tt22389131.html#a22389131
> but no one has replied :-\
>
> Can anyone tell me how can I export this type?

If I were you, I would not export it. In any case Python strings are
immutable and you always returns a copy of the string.

Instead of exposing that attribute directly create a get/set functions
which use "raw" "std::string" in their interface and expose them.

May be "custom converter" could help you (
http://www.boost.org/doc/libs/1_41_0/libs/python/doc/v2/faq.html#custom_string
), but I never tried it on such use case.



-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/


More information about the Cplusplus-sig mailing list