[vtk-developers] Wrapping enum types

David Gobbi david.gobbi at gmail.com
Tue Dec 2 11:46:36 EST 2014


Still waiting for reviewers for http://review.source.kitware.com/#/c/17993
(refactoring the python wrappers and wrapping enum types).  Big thanks
to Ben for his comments so far.

 - David


On Fri, Nov 21, 2014 at 10:58 AM, David Gobbi <david.gobbi at gmail.com> wrote:

> Hi All,
>
> The enum support for the wrappers is done (pending merge).  The caveat
> that I mentioned in my previous email no longer applies, i.e. with this new
> patch _all_ enum types are wrapped, whether they are in the global
> namespace, in a class namespace, or in any other namespace (except for
> nested namespaces, which aren't supported by the wrappers yet).
>
> This change isn't going to have much impact on the VTK core, because
> most VTK class methods simply take "int" parameters instead of requiring
> the use of enums.  However, it will have a _big_ impact for the wrapping
> of third-party VTK classes which tend to use enum parameters quite often.
> (In fact the change was motivated by the need to wrap some of my own
> external classes).
>
> Enum parameter support is only provided for the python wrappers, not for
> Java or Tcl.
>
>  - David
>
>
> On Mon, Nov 17, 2014 at 7:04 AM, David Gobbi <david.gobbi at gmail.com>
> wrote:
>
>> 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/20141202/2abb67f1/attachment.html>


More information about the vtk-developers mailing list