Commit ba71f950 authored by Jonathan Beck's avatar Jonathan Beck

Reduce Python specific code in swig header.

parent 7fa91f0b
......@@ -6,10 +6,6 @@
#include <plist/plist.h>
#include <plist/plist++.h>
#include <ctime>
//for datetime in python
#include <datetime.h>
typedef struct {
plist_t node;
char should_keep_plist;
......@@ -29,22 +25,26 @@ PListNode *allocate_plist_wrapper(plist_t plist, char should_keep_plist) {
%include "std_string.i"
#if SWIGPYTHON
%typemap(out) std::vector<char> {
$result = PyString_FromStringAndSize((const char*)&($1[0]),(int)($1.size()));
$result = SWIG_FromCharPtrAndSize((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);
char* buffer = NULL;
int length = 0;
SWIG_AsCharPtrAndSize($input, &buffer, &length, NULL);
$1 = std::vector<char>(buffer, buffer + length);
}
#if SWIGPYTHON
//for datetime in python
%{
#include <ctime>
#include <datetime.h>
%}
%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) timeval {
PyDateTime_IMPORT;
$1 = PyDateTime_Check($input) ? 1 : 0;
......@@ -78,6 +78,7 @@ PListNode *allocate_plist_wrapper(plist_t plist, char should_keep_plist) {
timeval ret = {(int)mktime(&t), PyDateTime_DATE_GET_MICROSECOND($input)};
$1 = ret;
}
#endif
%apply SWIGTYPE *DYNAMIC { PList::Node* };
%apply SWIGTYPE *DYNAMIC { PList::Structure* };
......@@ -127,9 +128,6 @@ static swig_type_info *Node_dynamic(void **ptr)
DYNAMIC_CAST(SWIGTYPE_p_PList__Node, Node_dynamic);
DYNAMIC_CAST(SWIGTYPE_p_PList__Structure, Node_dynamic);
#else
#endif
%rename(__assign__) *::operator=;
%rename(__getitem__) *::operator[];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment