[vtk-developers] Wrapping enum types

Marcus D. Hanwell marcus.hanwell at kitware.com
Tue Dec 2 23:01:07 EST 2014


Hi David,

I will try to take a look soon, travel and proposals have taken up
more of my time than I might like. I am really pleased to see this
added to the Python wrapping (although in truth would love to see it
in Java/Tcl so we could actually use it in our API).

Marcus

On Tue, Dec 2, 2014 at 11:46 AM, David Gobbi <david.gobbi at gmail.com> wrote:
> 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
>>
>>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtk-developers
>
>


More information about the vtk-developers mailing list