[vtk-developers] Wrapping enum types

David Gobbi david.gobbi at gmail.com
Mon Nov 17 09:04:21 EST 2014


Hi All,

I have a patch in gerrit that modifies the python wrappers so that enum
types are wrapped.  This means that method parameters can be enum
types, something that wasn't possible for wrapped methods before.
http://review.source.kitware.com/#/c/17993

E.g.:

class vtkSomeObject
{
public:
  enum ColorEnum { Red, Blue };
  void SetColor(enum ColorEnum);
};

Each enum type is wrapped as a unique python type subclassed from
python's "int" type.  So an enum can be used wherever an int can be
used, but methods that take an enum will raise a TypeError unless
given a value of the correct enum type.

One caveat is that this only works if the method and the enum type are
members of the same class.  Sometime later I'll generalize it so that a
method can use an enum defined in a different class, but method & enum
in the same class seems to be the most common use case.

Cheers,

  - David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20141117/b5530f5a/attachment.html>


More information about the vtk-developers mailing list