[prev in list] [next in list] [prev in thread] [next in thread] 

List:       vtk-developers
Subject:    Re: [vtk-developers] Wrapping enum types
From:       Berk Geveci <berk.geveci () kitware ! com>
Date:       2014-12-09 14:49:59
Message-ID: CAE32kpW6HSkaRTVhLiQFC7JEZAArz6B-p1J7T5Mu=bE+OktEFw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


You rock David.

-berk

On Tue, Dec 9, 2014 at 7:30 AM, David Gobbi <david.gobbi@gmail.com> wrote:

> I've merged the fixes for the Java and Tcl wrappers so that they can wrap
> methods that take enum types as parameters.  Together with the python
> fixes, this means that there should be no barrier to people who want to use
> enum types in their class interfaces.
>
>
> On Tue, Dec 2, 2014 at 9:17 PM, David Gobbi <david.gobbi@gmail.com> wrote:
>
>> 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@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@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@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@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
>
>
>

[Attachment #5 (text/html)]

<div dir="ltr">You rock David.<div><br></div><div>-berk</div></div><div \
class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 9, 2014 at 7:30 AM, \
David Gobbi <span dir="ltr">&lt;<a href="mailto:david.gobbi@gmail.com" \
target="_blank">david.gobbi@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">I&#39;ve merged the fixes for the Java and Tcl \
wrappers so that they can wrap<div>methods that take enum types as parameters.   \
Together with the python</div><div>fixes, this means that there should be no barrier \
to people who want to use</div><div>enum types in their class \
interfaces.</div><div><div class="h5"><div><br></div><div><div \
class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 2, 2014 at 9:17 PM, \
David Gobbi <span dir="ltr">&lt;<a href="mailto:david.gobbi@gmail.com" \
target="_blank">david.gobbi@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">Thanks, Marcus.   I&#39;ve been thinking about \
Java and Tcl, and I might<div>implement enums in those wrappers via a simple type \
cast.</div><div><br></div><div>For example,</div><div><br></div><div>   void \
SetColorMode(ColorModeEnum val);</div><div><br></div><div>would be called from the \
Tcl and Java wrappers like this</div><div><br></div><div>   \
SetColorMode(static_cast&lt;ColorModeEnum&gt;(val));</div><div><br></div><div>with no \
type checking.   It would be much easier to implement</div><div>than making each enum \
into a first-class type like I&#39;ve done</div><div>for the Python \
wrappers.</div><span><font color="#888888"><div><br></div><div>  - \
David</div></font></span><div><div><div><br><div class="gmail_extra"><br><div \
class="gmail_quote">On Tue, Dec 2, 2014 at 9:01 PM, Marcus D. Hanwell <span \
dir="ltr">&lt;<a href="mailto:marcus.hanwell@kitware.com" \
target="_blank">marcus.hanwell@kitware.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">Hi David,<br> <br>
I will try to take a look soon, travel and proposals have taken up<br>
more of my time than I might like. I am really pleased to see this<br>
added to the Python wrapping (although in truth would love to see it<br>
in Java/Tcl so we could actually use it in our API).<br>
<br>
Marcus<br>
<div><div><br>
On Tue, Dec 2, 2014 at 11:46 AM, David Gobbi &lt;<a \
href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>&gt; \
wrote:<br> &gt; Still waiting for reviewers for <a \
href="http://review.source.kitware.com/#/c/17993" \
target="_blank">http://review.source.kitware.com/#/c/17993</a><br> &gt; (refactoring \
the python wrappers and wrapping enum types).   Big thanks<br> &gt; to Ben for his \
comments so far.<br> &gt;<br>
&gt;   - David<br>
&gt;<br>
&gt;<br>
&gt; On Fri, Nov 21, 2014 at 10:58 AM, David Gobbi &lt;<a \
href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>&gt; \
wrote:<br> &gt;&gt;<br>
&gt;&gt; Hi All,<br>
&gt;&gt;<br>
&gt;&gt; The enum support for the wrappers is done (pending merge).   The caveat<br>
&gt;&gt; that I mentioned in my previous email no longer applies, i.e. with this<br>
&gt;&gt; new<br>
&gt;&gt; patch _all_ enum types are wrapped, whether they are in the global<br>
&gt;&gt; namespace, in a class namespace, or in any other namespace (except for<br>
&gt;&gt; nested namespaces, which aren&#39;t supported by the wrappers yet).<br>
&gt;&gt;<br>
&gt;&gt; This change isn&#39;t going to have much impact on the VTK core, because<br>
&gt;&gt; most VTK class methods simply take &quot;int&quot; parameters instead of \
requiring<br> &gt;&gt; the use of enums.   However, it will have a _big_ impact for \
the wrapping<br> &gt;&gt; of third-party VTK classes which tend to use enum \
parameters quite often.<br> &gt;&gt; (In fact the change was motivated by the need to \
wrap some of my own<br> &gt;&gt; external classes).<br>
&gt;&gt;<br>
&gt;&gt; Enum parameter support is only provided for the python wrappers, not for<br>
&gt;&gt; Java or Tcl.<br>
&gt;&gt;<br>
&gt;&gt;   - David<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Mon, Nov 17, 2014 at 7:04 AM, David Gobbi &lt;<a \
href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>&gt;<br> \
&gt;&gt; wrote:<br> &gt;&gt;&gt;<br>
&gt;&gt;&gt; Hi All,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I have a patch in gerrit that modifies the python wrappers so that \
enum<br> &gt;&gt;&gt; types are wrapped.   This means that method parameters can be \
enum<br> &gt;&gt;&gt; types, something that wasn&#39;t possible for wrapped methods \
before.<br> &gt;&gt;&gt; <a href="http://review.source.kitware.com/#/c/17993" \
target="_blank">http://review.source.kitware.com/#/c/17993</a><br> &gt;&gt;&gt;<br>
&gt;&gt;&gt; E.g.:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; class vtkSomeObject<br>
&gt;&gt;&gt; {<br>
&gt;&gt;&gt; public:<br>
&gt;&gt;&gt;     enum ColorEnum { Red, Blue };<br>
&gt;&gt;&gt;     void SetColor(enum ColorEnum);<br>
&gt;&gt;&gt; };<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Each enum type is wrapped as a unique python type subclassed from<br>
&gt;&gt;&gt; python&#39;s &quot;int&quot; type.   So an enum can be used wherever an \
int can be<br> &gt;&gt;&gt; used, but methods that take an enum will raise a \
TypeError unless<br> &gt;&gt;&gt; given a value of the correct enum type.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; One caveat is that this only works if the method and the enum type \
are<br> &gt;&gt;&gt; members of the same class.   Sometime later I&#39;ll generalize \
it so that a<br> &gt;&gt;&gt; method can use an enum defined in a different class, \
but method &amp; enum<br> &gt;&gt;&gt; in the same class seems to be the most common \
use case.<br> &gt;&gt;&gt;<br>
&gt;&gt;&gt; Cheers,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     - David<br></div></div>
</blockquote></div><br></div></div></div></div></div>
</blockquote></div><br></div></div></div></div></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a \
href="http://www.kitware.com/opensource/opensource.html" \
target="_blank">http://www.kitware.com/opensource/opensource.html</a><br> <br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtk-developers" \
target="_blank">http://public.kitware.com/mailman/listinfo/vtk-developers</a><br> \
<br> <br></blockquote></div><br></div>



_______________________________________________
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



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic