[Kde-bindings] question of c++ template class

Richard Dale rdale at foton.es
Sat Apr 28 08:33:24 UTC 2007


On Friday 27 April 2007, Dongxu Ma wrote:
> > > Hi Richard, CC: all,
> > >
> > > I am recently thinking about how to deal with c++ template class in
> >
> > QT/KDE
> >
> > > bindings.
> > > Inside QT4 I found three places where templates get involved:
> > > 1) typedef
> >
> > You need to be able to marshaller each typedef'd variant of the template
>
> yes, the disadvantage is to collect all involved ones priorly.  I am
> working on a
> script to build the list.
OK, I think you could generate some marshallers along with the bindings, but 
not all of them. The bindings that use the smoke lib have a hash of strings 
for the various types as keys, with a values as function pointer of the 
corresponding marshaller

> > 2) function parameter, return type
> > A lot of the template types are lists or hashes, and the solution that
> > qtruby/qyoto uses is to have marshallers <--> bindings language as
> > templated
> > code. This means you only write the marshalling code once, and then have
> > a different template type for each the the C++ template types with a
> > macro to
> > invoke it. See the code in handlers.cpp of either the QtRuby or Qyoto
> > projects for a example. For instance, this line:
> >
> > DEF_VALUELIST_MARSHALLER( QUrlList, QList<QUrl>, QUrl )
> >
> > The DEF_VALUELIST_MARSHALLER() will define a new template based
> > marshaller for
> > QLists of QUrls.
> >
> > > 3) QT signal, slot
> >
> > You can't have have commas in signal and slot types, but you can have
> > simple
> > template types. The template types are mostly lists which have to be
> > marshalled as Arrays or Lists in the bindings language.
>
> yes, noticed that. Just 4 or 5 found in my current QT4 headers.
I think there are more than that.

> > It is a little bit hard to support template class inside scripting
> >
> > > language, how do you
> > > make it available for qtruby (or not) ? This was not mentioned on
> > > kdebindings ruby
> > > page. Sorry I am totally new to ruby.
> > >
> > > Idea in my mind is:
> > > 1) get all template declarations from source;
> > > 2) introduce a base template in perl for those types which share the
> >
> > same
> >
> > > base template
> > >     like QList<Q3DockWindow *>, QList<Q3ToolBar *> we create QList.
> > >     such base template can create a specific namespace for demanded
> > > type runtimely, say
> > >     QList_Q3DockWindow_Ptr (cached in future), and push all available
> > > methods into it.
> > >     Inside QList c++ code holds a function dictionary to cast generic
> > > pointer from vm to
> > >     template type instance (possibly by interpret_cast or static_cast);
> >
> > Yes, that sounds similar to the code in handlers.cpp that I describe
> > above.
> >
> > > Could you pls explain something you've done in qtbudy or your ideas?
> > > From my personal point of view, that'll be nice if we can setup a
> >
> > generic
> >
> > > solution, across
> > > different scripting languages.
> >
> > Well, yes that is the idea of the Smoke library. And it allows the code
> > for
> > the QtRuby bindings (derived from PerlQt), and the Qyoto C# bindings to
> > be very similar.
>
> The way to keep instance pointer differ in various languages. That'll be
> nice
> to define marshall layer plugin for each one and plug to use.
>
> Note that I think someone is working on a Qt4 version of the Smoke based
>
> > PerlQt, and you need to be a bit careful about naming your project
> > something
> > different from just 'PerlQt' to avoid confusion.
>
> namespace is ok.  I'd like to know him/her. Is him/her on the maillist?
Yes, there is a mailing list kde-perl at kde.org

-- Richard





More information about the Kde-bindings mailing list