Commit 1b12d348 authored by Nikias Bassen's avatar Nikias Bassen

cython: added PLIST_UID support

parent ef734743
......@@ -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)
......
......@@ -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):
......
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