summaryrefslogtreecommitdiffstats
path: root/swig/plist.i
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2009-10-17 10:41:18 +0200
committerGravatar Jonathan Beck2009-10-17 10:41:18 +0200
commit6f453688c0b97ea979b2b2b515f4030e69e846fb (patch)
tree68ea509582004bfb5e5df61756e7e8b30ac56dd4 /swig/plist.i
parente6a0149e3be353da436c9b3cbc960233c2df2076 (diff)
downloadlibplist-6f453688c0b97ea979b2b2b515f4030e69e846fb.tar.gz
libplist-6f453688c0b97ea979b2b2b515f4030e69e846fb.tar.bz2
Use custom typemap for binary buffers as we want to hadle them as strings in python.
Diffstat (limited to 'swig/plist.i')
-rw-r--r--swig/plist.i23
1 files changed, 19 insertions, 4 deletions
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<char> {
+ $result = PyString_FromStringAndSize((const char*)&($1[0]),(int)($1.size()));
+}
+
+%typemap(in) (const std::vector<char>& 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<char>(buffer, buffer + length);
+}
+#else
+#endif
-namespace std {
- %template(vectorc) vector<char>;
-};
%rename(__assign__) *::operator=;
%rename(__getitem__) *::operator[];