From 6f453688c0b97ea979b2b2b515f4030e69e846fb Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Sat, 17 Oct 2009 10:41:18 +0200 Subject: Use custom typemap for binary buffers as we want to hadle them as strings in python. --- swig/plist.i | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'swig/plist.i') diff --git a/swig/plist.i b/swig/plist.i index 91124b2..1b97451 100644 --- a/swig/plist.i +++ b/swig/plist.i @@ -23,11 +23,26 @@ PListNode *allocate_plist_wrapper(plist_t plist, char should_keep_plist) { } %} -%include "stl.i" +%include "std_string.i" + +#if SWIGPYTHON +%typemap(out) std::vector { + $result = PyString_FromStringAndSize((const char*)&($1[0]),(int)($1.size())); +} + +%typemap(in) (const std::vector& v) +{ + if (!PyString_Check($input)) { + PyErr_SetString(PyExc_ValueError,"Expected a string"); + return NULL; + } + char* buffer = PyString_AsString($input); + int length = PyString_Size($input); + $1 = std::vector(buffer, buffer + length); +} +#else +#endif -namespace std { - %template(vectorc) vector; -}; %rename(__assign__) *::operator=; %rename(__getitem__) *::operator[]; -- cgit v1.1-32-gdbae