-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreq.pyx
34 lines (27 loc) · 879 Bytes
/
req.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# distutils: language = c++
from cython.operator cimport dereference
cdef extern from "req.h" namespace 'cstuff':
cdef cppclass Request[Loc]:
int request_id
double creation_timestamp
Request()
Request(int, double)
cdef class IntRequest:
cdef Request[int] *creq
def __init__(
self,
int request_id,
float creation_timestamp,
):
self.creq = new Request[int](
request_id, creation_timestamp
)
def asdict(self):
return dict(
request_id=dereference(self.creq).request_id,
creation_timestamp=dereference(self.creq).creation_timestamp,
)
def __repr__(self):
return f"{self.__class__.__name__}(" + ", ".join(f"{k}={v}" for k, v in self.asdict().items()) + ")"
def __dealloc__(self):
del self.creq