diff options
Diffstat (limited to 'cython')
-rw-r--r-- | cython/plist.pxd | 4 | ||||
-rw-r--r-- | cython/plist.pyx | 51 |
2 files changed, 55 insertions, 0 deletions
diff --git a/cython/plist.pxd b/cython/plist.pxd index c504599..ee8a65e 100644 --- a/cython/plist.pxd +++ b/cython/plist.pxd @@ -21,6 +21,10 @@ cdef class Integer(Node): cpdef set_value(self, object value) cpdef uint64_t get_value(self) +cdef class Uid(Node): + cpdef set_value(self, object value) + cpdef uint64_t get_value(self) + cdef class Key(Node): cpdef set_value(self, object value) cpdef unicode get_value(self) diff --git a/cython/plist.pyx b/cython/plist.pyx index 09c0bbc..4eccdb1 100644 --- a/cython/plist.pyx +++ b/cython/plist.pyx @@ -13,6 +13,7 @@ cdef extern from *: PLIST_DATE, PLIST_DATA, PLIST_KEY, + PLIST_UID, PLIST_NONE plist_t plist_new_bool(uint8_t val) @@ -35,6 +36,10 @@ cdef extern from *: void plist_get_key_val(plist_t node, char **val) void plist_set_key_val(plist_t node, char *val) + plist_t plist_new_uid(uint64_t val) + void plist_get_uid_val(plist_t node, uint64_t *val) + void plist_set_uid_val(plist_t node, uint64_t val) + plist_t plist_new_string(char *val) void plist_get_string_val(plist_t node, char **val) void plist_set_string_val(plist_t node, char *val) @@ -264,6 +269,52 @@ cdef Real Real_factory(plist_t c_node, bint managed=True): instance._c_node = c_node return instance +cdef class Uid(Node): + def __cinit__(self, object value=None, *args, **kwargs): + if value is None: + self._c_node = plist_new_uid(0) + else: + self._c_node = plist_new_uid(int(value)) + + def __repr__(self): + cdef uint64_t i = self.get_value() + return '<Uid: %s>' % i + + def __int__(self): + return self.get_value() + + def __float__(self): + return float(self.get_value()) + + def __richcmp__(self, other, op): + cdef int i = self.get_value() + if op == 0: + return i < other + if op == 1: + return i <= other + if op == 2: + return i == other + if op == 3: + return i != other + if op == 4: + return i > other + if op == 5: + return i >= other + + cpdef set_value(self, object value): + plist_set_uid_val(self._c_node, int(value)) + + cpdef uint64_t get_value(self): + cdef uint64_t value + plist_get_uid_val(self._c_node, &value) + return value + +cdef Uid Uid_factory(plist_t c_node, bint managed=True): + cdef Uid instance = Uid.__new__(Uid) + instance._c_managed = managed + instance._c_node = c_node + return instance + from cpython cimport PY_MAJOR_VERSION cdef class Key(Node): |