Wrapping Enumerations

The first part of the .h file to convert are the enumerations. To convert a C enumeration to Pyrex:

  1. Replace the typedef enum with cdef enum,
  2. Move the name of the enumeration from after the closing bracket (}) to after the enum,
  3. Remove , from the end of each line, and
  4. Replace the {} blocking with a : and indenting.
X
O
S
D

For example, consider the following C enumeration, called xosd_pos, that is contained in xosd.h.

typedef enum
   {
   XOSD_top,
   XOSD_bottom
   } xosd_pos;

The above enumeration consists of two elements: XOSD_top and XOSD_bottom The Pyrex version of the enumeration looks similar.

cdef enum xosd_pos:
    XOSD_top
    XOSD_bottom
cdef
is a Pyrex declaration.
enum
tells Pyrex that you are declaring an enumeration.
xosd_pos
is the name of the enumeration.

The rest of the enumeration is then copied, with whitespace replacing {} as the blocking mechanism and the commas removed. The XOSD_ could also be removed from the start of each enumeration value, but I will leave them in to emphasise the mechanical nature of the conversion!

A further example is the xosd_command enumeration that is converted from the following C enumeration.

typedef enum
   {
   XOSD_percentage,
   XOSD_string,
   XOSD_printf,
   XOSD_slider
   } xosd_command;

The Pyrex version is as follows.

cdef enum xosd_command:
   XOSD_percentage
   XOSD_string
   XOSD_printf
   XOSD_slider
Previous Contents Next

Michael JasonSmith
Last modified: Mon Jun 24 11:53:58 NZST 2002