diff options
| -rw-r--r-- | swig/plist.i | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/swig/plist.i b/swig/plist.i index 41931b0..0a40cf6 100644 --- a/swig/plist.i +++ b/swig/plist.i | |||
| @@ -6,6 +6,10 @@ | |||
| 6 | #include <plist/plist.h> | 6 | #include <plist/plist.h> |
| 7 | #include <plist/plist++.h> | 7 | #include <plist/plist++.h> |
| 8 | 8 | ||
| 9 | #include <ctime> | ||
| 10 | //for datetime in python | ||
| 11 | #include <datetime.h> | ||
| 12 | |||
| 9 | typedef struct { | 13 | typedef struct { |
| 10 | plist_t node; | 14 | plist_t node; |
| 11 | char should_keep_plist; | 15 | char should_keep_plist; |
| @@ -41,6 +45,40 @@ PListNode *allocate_plist_wrapper(plist_t plist, char should_keep_plist) { | |||
| 41 | $1 = std::vector<char>(buffer, buffer + length); | 45 | $1 = std::vector<char>(buffer, buffer + length); |
| 42 | } | 46 | } |
| 43 | 47 | ||
| 48 | %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) timeval { | ||
| 49 | PyDateTime_IMPORT; | ||
| 50 | $1 = PyDateTime_Check($input) ? 1 : 0; | ||
| 51 | } | ||
| 52 | |||
| 53 | %typemap(out) timeval { | ||
| 54 | struct tm* t = gmtime ( &$1.tv_sec ); | ||
| 55 | if (t) | ||
| 56 | { | ||
| 57 | PyDateTime_IMPORT; | ||
| 58 | $result = PyDateTime_FromDateAndTime(t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, $1.tv_usec); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | %typemap(in) (timeval t) | ||
| 63 | { | ||
| 64 | PyDateTime_IMPORT; | ||
| 65 | if (!PyDateTime_Check($input)) { | ||
| 66 | PyErr_SetString(PyExc_ValueError,"Expected a datetime"); | ||
| 67 | return NULL; | ||
| 68 | } | ||
| 69 | struct tm t = { | ||
| 70 | PyDateTime_DATE_GET_SECOND($input), | ||
| 71 | PyDateTime_DATE_GET_MINUTE($input), | ||
| 72 | PyDateTime_DATE_GET_HOUR($input), | ||
| 73 | PyDateTime_GET_DAY($input), | ||
| 74 | PyDateTime_GET_MONTH($input)-1, | ||
| 75 | PyDateTime_GET_YEAR($input)-1900, | ||
| 76 | 0,0,0 | ||
| 77 | }; | ||
| 78 | timeval ret = {(int)mktime(&t), PyDateTime_DATE_GET_MICROSECOND($input)}; | ||
| 79 | $1 = ret; | ||
| 80 | } | ||
| 81 | |||
| 44 | %apply SWIGTYPE *DYNAMIC { PList::Node* }; | 82 | %apply SWIGTYPE *DYNAMIC { PList::Node* }; |
| 45 | %apply SWIGTYPE *DYNAMIC { PList::Structure* }; | 83 | %apply SWIGTYPE *DYNAMIC { PList::Structure* }; |
| 46 | 84 | ||
