[PyKDE] Interfacing to C++ standard library
jbublitz at nwinternet.com
Wed Dec 11 21:54:01 GMT 2002
On 11-Dec-02 Paul F. Kunz wrote:
> To complete my SIP based Python extension module, I need to
> convert from C++ to Python and vica versa an std::vector<double>
> and std::vector<std::string>. I found some hints in this
> mailing list's archive dated 13 Apr 2002. Is there a better
> source of information on how to proceed?
grep either the PyQt or PyKDE sip files for QList or QValueList.
You should find examples of converting those using either
%MemberCode or %MappedType. (QValueList should be very similar to
std::vector). %MappedType is probably easier.
If you use %MemberCode, you'll need to handwrite a small piece of C
code for each method that uses one of the vector types (to take or
return a Python list instead). IIRC your example used a template
type in a virtual method, so if you use %MemberCode with that
method, you'll also need to write a %VirtualCode block.
If you use %MappedType, you write two small pieces of C code to
convert between Python list and C++ std::vector<type> (one for each
direction), and then any place std:vector<double> is referenced,
the conversions will be done automatically. You'd need one mapped
type for std::vector<double> and another for
std::vector<std::string>. sip will generate the %VirtualCode
equivalents for you in this case, and sip will consider
std::vector<double> to be just another type name, defined by the
You'll might also need to use the same methods for std::string
to convert to/from either a Python string or QString if it's used
outside the mapped type/member code for std::vector<std::string>.
More information about the PyQt