2
我有一個很大的C++代碼,我用cython從python調用。我不確定在cython中應該如何調用枚舉。這是我已經嘗試過的。但這並不完整。幫幫我!如何訪問cython中的枚舉?
示範例子
class Foo{
public:
Foo1 bar(enum_is type = enum::any) const;
}
enum class enum_is:unsigned int{
any = 0,
one = 1,
two = 2,
};
abc.pxd
cdef extern from "headerfile.hpp":
cdef cpp class enum_is:
pass
cdef extern from "headerfile.hpp" namespace "enum_is":
cdef enum_is any
cdef enum_is one
cdef enum_is two
abc.pyx
cdef class Pyenum_is:
cdef enum_is thisobj
def __cinit__(self,unsigned int val):
self.pin_isthisobj = <pin_is> val
def get_pin_is_type(self)
cdef r={<unsigned int> any:"any",
<unsigned int> one:"one",
<unsigned int> two:"two"
}
return r[<unsigned int>self.thisobj]
我需要就如何實際使用Python的假設枚舉函數幫助我有enum類正確包裝
cdef class PyFoo1
cdef Foo1 Foo1thisobj
cdef Foo1* Foo1thisptr
cdef class PyFoo
cdef Foo Foothisobj
cdef Foo* Foothisptr
def bar(self,#pass enum_is object here):
cdef Foo tempv = self.thisobj.bar(#pass enum here)
abc = PyFoo()
abc.Foo1thisobj = tempv
return abc
有人能幫助我關於如何繼續前進,在用Cython
我聽不懂。你能否編輯你的答案來解釋示範例子 –