[vtk-developers] Wrapping enum types
David Gobbi
david.gobbi at gmail.com
Tue Dec 2 23:17:52 EST 2014
Thanks, Marcus. I've been thinking about Java and Tcl, and I might
implement enums in those wrappers via a simple type cast.
For example,
void SetColorMode(ColorModeEnum val);
would be called from the Tcl and Java wrappers like this
SetColorMode(static_cast<ColorModeEnum>(val));
with no type checking. It would be much easier to implement
than making each enum into a first-class type like I've done
for the Python wrappers.
- David
On Tue, Dec 2, 2014 at 9:01 PM, Marcus D. Hanwell <
marcus.hanwell at kitware.com> wrote:
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20141202/5097285c/attachment.html>
More information about the vtk-developers
mailing list