1
我有以下C++類接口,我試圖cythonize。Cython:複製構造函數
class NetInfo
{
public:
NetInfo();
NetInfo(NetInfo const& rhs);
virtual ~NetInfo();
void swap(NetInfo& rhs) throw();
NetInfo& operator=(NetInfo rhs);
...
}
這是我到目前爲止。我不完全確定如何實現複製構造函數。我在Cython用戶指南中沒有看到任何示例。複製構造中的問題是如何從'other'(一個PyNetInfo對象)獲取NetInfo對象。有任何想法嗎?
cdef extern from 'NetInfo.h' namespace '...':
cdef cppclass NetInfo:
NetInfo() except +
NetInfo(NetInfo&) except +
operator=(NetInfo) except +
...
cdef class PyNetInfo:
cdef NetInfo* thisptr
def __cinit__(self, PyNetInfo other=None):
cdef PyNetInfo ostr
if other and type(other) is PyNetInfo:
ostr = <PyNetInfo> other
self.thisptr = ostr.thisptr
else:
self.thisptr = new NetInfo()
def __dealloc__(self):
del self.thisptr