I'm currently wrapping C++ libraries making heavy uses of stl strings (const
strings, non const references and pointers...), and I'm having trouble
getting ways of calling all the functions with proper arguments.
I know that, strings being immutable in python, only const strings and const
references can be "naturally" converted between python and C++. That's why
I'd like to have both these natural conversion, and a proxy towards the real
STL string class, to instanciate and manipulate real C++ STL strings from
python (as remote pointers).
The problem is, natural conversions and remote string objects don't seem to
go on well together. If I just use "%include stl.i", natural conversions
occur, but I have no means to instanciate directly a C++ STL string -and get
a proxy to it).
If on the contrary I only "%include <std/std_string.i>", I get a proper
remote string class exposed, but I never have any automatic conversion
between, for example, python stringsand const stl string arguments.
I'm seeking a way to have both together, in spite of weird errors that occur
when I include several such interface files.
Curerntly, I've ended with :
typedef basic_string<char> string;
It compiles OK, I get natural conversions as well as an exposed STL string
class, but there are still problems when calling functions with "string*" or
"string&" arguments : internally, Swig still knows two different types,
(whereas they are supposed to be the same), and a wrapped function like "int
STRINGPTR(std::string* arg);" will only accept new STL C++ string objects
returned by a C++ function (known to python as <Swig Object of type
'std::string *' at 0x2aaaaaf39d50>), not STL C++ strings instanciated via
the exposed string class (known to python as <BaseCGI.string; proxy of <Swig
Object of type 'std::basic_string< char,std::char_traits< char
>,std::allocator< char > > *' at 0x2aaaab174ea0> >).
So has anyone an idea of how to get both natural conversions (for const
strings), and remote manipulation of C++ string objects (to be passed as
references or pointers to C++ functions, and manipulated with their
insert(), c_str() etc. methods) ? Has anyone alreay needed full STL string
Thanks a lot for your attention,