[Kde-bindings] question of c++ template class
Richard Dale
rdale at foton.es
Thu Apr 26 13:48:08 UTC 2007
On Thursday 26 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
> 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.
> 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.
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.
-- Richard
More information about the Kde-bindings
mailing list