So I have this Point class. So I want it to be able to recieve double
and SomeType
parameters.
[Point.pxd]
from libcpp.memory cimport shared_ptr, weak_ptr, make_shared
from SomeType cimport _SomeType, SomeType
cdef extern from "Point.h":
cdef cppclass _Point:
_Point(shared_ptr[double] x, shared_ptr[double] y)
_Point(shared_ptr[double] x, shared_ptr[double] y, shared_ptr[double] z)
_Point(shared_ptr[_SomeType] x, shared_ptr[_SomeType] y)
_Point(shared_ptr[_SomeType] x, shared_ptr[_SomeType] y, shared_ptr[_SomeType] z)
shared_ptr[_SomeType] get_x()
shared_ptr[_SomeType] get_y()
shared_ptr[_SomeType] get_z()
cdef class Point:
cdef shared_ptr[_Point] c_point
[Point.pyx]
from Point cimport *
cdef class Point:
def __cinit__(self, SomeType x=SomeType("0", None), SomeType y=SomeType("0", None), SomeType z=SomeType("0", None)):
self.c_point = make_shared[_Point](x.thisptr, y.thisptr, z.thisptr)
def __dealloc(self):
self.c_point.reset()
def get_x(self) -> SomeType:
cdef shared_ptr[_SomeType] result = self.c_point.get().get_x()
cdef SomeType coord = SomeType("", None, make_with_pointer = True)
coord.thisptr = result
return coord
def get_y(self) -> SomeType:
cdef shared_ptr[_SomeType] result = self.c_point.get().get_y()
cdef SomeType coord = SomeType("", None, make_with_pointer = True)
coord.thisptr = result
return coord
def get_z(self) -> SomeType:
cdef shared_ptr[_SomeType] result = self.c_point.get().get_z()
cdef SomeType coord = SomeType("", None, make_with_pointer = True)
coord.thisptr = result
return coord
property x:
def __get__(self):
return self.get_x()
property y:
def __get__(self):
return self.get_y()
property z:
def __get__(self):
return self.get_z()
How should I write my .pxd and .pyx file so that my Point constructor can recieve different type of parameters?
I would really appreciate your help.