class Region {
public:
enum region_type { west, east };
void setRegion(region_type region);
}
the cython wrapper looks like this:
cdef:
enum region_type:
Europe
Asia
cdef extern from "region.hh":
cdef cppclass Region:
void setRegion(region_type region)
This fails to compile:
region.cpp: In function �PyObject*
__pyx_f_8blackbox_SetRegion(__pyx_t_7cregion_region_type)�:
region.cpp:437: error: no matching function for call to
�Region.setRegion(__pyx_t_7cregion_region_type&)�
region.hh:52: note: candidates are: void
Region::setRegion(Region::region_type)
Is there a way to use the real Region::region_type enum?
Wichert.
Should have:
cdef extern from "region.hh":
As it is, you made Cython recreate a (different) enum type.
Dag
That's certainly an improvement and an obvious mistake om my side.
Unfortunately that assumes a global enum, while I have an enum inside
the class. Some quick experiments suggest that cython does not support
nested types inside classes other than other classes. For example:
// C++ source
class Foo {
public:
enum my_enum { one, two };
type std::vector<int> int_vector;
};
# Cython source
from libcpp.vector import vector
cdef extern from "foo.hh":
cdef cppclass Foo:
enum my_enum:
one
two
ctypedef vector[int_vector]
results in syntax errors both for the enum and the ctypedef lines. Is
that analysis correct, or am I making another mistake here?
Wichert.
You are correct, it's not supported yet. You may be able to get the
behavior you want by specifying
cdef extern from "foo.hh":
enum my_enum "Foo::my_enum":
one "Foo::one"
...
I've created http://trac.cython.org/cython_trac/ticket/659
- Robert
Unfortunately I appear to run into another issue: Cython does not like a
ctypedef for a template type. This code:
from libcpp.vector cimport vector
cdef extern from "foo.hh":
ctypedef vector[int] my_type
Results in a syntax error for the ctypedef statement.
Wichert.
--
Wichert Akkerman <wic...@wiggy.net> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.
> Unfortunately I appear to run into another issue: Cython does not like a
> ctypedef for a template type. This code:
>
> from libcpp.vector cimport vector
> cdef extern from "foo.hh":
> ctypedef vector[int] my_type
>
> Results in a syntax error for the ctypedef statement.
>
> Wichert.
Yep, this is a known issue: http://trac.cython.org/cython_trac/ticket/551
C++ support is a relatively recent and still incomplete addition.
- Robert