Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Using enums (in C++)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Wichert Akkerman  
View profile  
 More options Feb 11 2011, 7:27 am
From: Wichert Akkerman <wich...@wiggy.net>
Date: Fri, 11 Feb 2011 13:27:30 +0100
Local: Fri, Feb 11 2011 7:27 am
Subject: Using enums (in C++)
I have a C++ API which looks like this:

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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dag Sverre Seljebotn  
View profile  
 More options Feb 11 2011, 7:37 am
From: Dag Sverre Seljebotn <da...@student.matnat.uio.no>
Date: Fri, 11 Feb 2011 13:37:39 +0100
Local: Fri, Feb 11 2011 7:37 am
Subject: Re: [cython-users] Using enums (in C++)
On 02/11/2011 01:27 PM, Wichert Akkerman wrote:

> I have a C++ API which looks like this:

> class Region {
> public:
>     enum region_type { west, east };
>     void setRegion(region_type region);
> }

> the cython wrapper looks like this:

> cdef:

Should have:

cdef extern from "region.hh":

As it is, you made Cython recreate a (different) enum type.

Dag


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wichert Akkerman  
View profile  
 More options Feb 11 2011, 7:51 am
From: Wichert Akkerman <wich...@wiggy.net>
Date: Fri, 11 Feb 2011 13:51:15 +0100
Local: Fri, Feb 11 2011 7:51 am
Subject: Re: [cython-users] Using enums (in C++)
On 2/11/11 13:37 , Dag Sverre Seljebotn wrote:

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Bradshaw  
View profile  
 More options Feb 11 2011, 12:57 pm
From: Robert Bradshaw <rober...@math.washington.edu>
Date: Fri, 11 Feb 2011 09:57:54 -0800
Local: Fri, Feb 11 2011 12:57 pm
Subject: Re: [cython-users] Using enums (in C++)

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wichert Akkerman  
View profile  
 More options Feb 12 2011, 4:05 am
From: Wichert Akkerman <wich...@wiggy.net>
Date: Sat, 12 Feb 2011 10:05:11 +0100
Local: Sat, Feb 12 2011 4:05 am
Subject: Re: [cython-users] Using enums (in C++)
On 2011-2-11 18:57, Robert Bradshaw wrote:

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 <wich...@wiggy.net>   It is simple to make things.
http://www.wiggy.net/                  It is hard to make things simple.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Bradshaw  
View profile  
 More options Feb 12 2011, 12:24 pm
From: Robert Bradshaw <rober...@math.washington.edu>
Date: Sat, 12 Feb 2011 09:24:38 -0800
Local: Sat, Feb 12 2011 12:24 pm
Subject: Re: [cython-users] Using enums (in C++)

On Sat, Feb 12, 2011 at 1:05 AM, Wichert Akkerman <wich...@wiggy.net> wrote:
> 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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »