[Kde-bindings] possible conflicts in enums

Richard Dale rdale at foton.es
Mon Sep 7 10:51:19 UTC 2009


On Monday 07 September 2009 11:33:28 am Petr Vanek wrote:
> On Sep 7, 2009, at 11:47 AM, Richard Dale wrote:
> > On Monday 07 September 2009 10:25:02 am Petr Vanek wrote:
> >> Let's take for example these enums
> >> enum Qt::GlobalColor
> >> enum Qt::PenStyle
> >>
> >> and available constructors (Qt):
> >> QPen ( Qt::PenStyle style )
> >> QPen ( const QColor & color )
> >>
> >> If I use it in special case (pseudocode)
> >>
> >> // "enum", but it's just an alias for 3
> >> foo = Qt::DotLine
> >> // then call
> >> pen = new QPen(foo)
> >>
> >> so it's unclear which constructor to call. Just because Qt::DotLine
> >> equals Qt::white in this case.
> >
> > In QtRuby a Qt::Enum value is returned for enums. I don't think we
> > need to add
> > anything to smoke because converting from the long on the smoke
> > stack to a
> > Ruby Qt::Enum or whatever is needed for other languages, is
> > something than a
> > language specific marshaller can do. The enum 'MethodFlags' in
> > smoke.h has a
> > value mf_enum, and so it is easy to know if the method being called is
> > returning an enum value, and the stack union ha an 's_enum' variant:
> 
> OK, it's clear. But it doesn't explain how to find QPen constructor
> from my example above. Both constructors are accepting enum as an
> argument, both have the same signature "QPen#".
> I still think there should be any way how to identify *type of enum*
> in smoke.
> 
> I mean - there is a "white" method in "Qt" class (it's a namespace,
> but listed in classes in smoke). It's enum in MethodFlags. But there
> should be (IMHO) some link between an enum value (method) and
> Smoke::Type list.
In the marshaller code example I gave the name of the enum type is passed to 
the Ruby method to create the Qt::Enum:

rb_intern("create_qenum"),2, LONG2NUM(val), rb_str_new2( m->type().name())

So when I run some code under irb, I can print a description of the Qt::Enum 
with the type:

irb(main):005:0> mardigras rdale 531% irb -rpp -rQt4
irb(main):001:0> pen = Qt::Pen.new
=> #<Qt::Pen:0xb7a1f240>
irb(main):002:0> pp pen.style
#<Qt::Enum:0xfdbd0eafc @type=Qt::PenStyle, @value=1>
=> nil

The type of the Qt::Enum can be used to resolve methods overloaded on enum 
types.

-- Richard



More information about the Kde-bindings mailing list