[email protected] wrote:
> Hi Eskil,
> thank you very much for your suggestions, that's a good starting
> point to manage this issue.
> Anyway i would ask you how to handle this simpler
> subcase ( i refer to the code i posted first):
> suppose that the class
> ContacsManager derived from the singletontemplate class is instantiated
> in a
> dll (of course wrapped with all the stuff produced by generator) , how could
> i
> have the getInstance() method in java ? that is how could i access
> the
> contactsmanager instance from a java application ?
>
The support for templates in the generator at the moment is tailored to
support specific containers and template classes where the type is a
storage type, and not actually used in the code. In order to do what you
are suggesting, if I read you correctly, you will have to apply some hacks.
I'll assume code that looks something like this:
--
template <typename T>
class SingletonTemplate
{
public:
T somethingSomething();
};
class SomeClass
{
};
class ContactsManager: public SingletonTemplate<SomeClass *>
{
public:
static ContactsManager *getInstance();
};
--
I have two ideas, depending on what is acceptable to you. The first
involves mimicking the mapping of the Tulip container classes, where the
class itself does not get a direct equivalent in Java, but its
functionality is copied into all its subclasses. The SingletonTemplate
class will not exist in Java at all, in this case, so ContactsManager
will inherit QtJambiObject which is the base class for all generated
classes. For the code above, you can achieve this with the following
type system entries:
--
<object-type name="SingletonTemplate" generate="no" />
<object-type name="SomeClass" />
<object-type name="ContactsManager" />
--
The other idea involves using the generic mapping mechanism we created
for certain classes in QtConcurrent, like QFuture. You will typedef a
special parameterization of your SingletonTemplate and then map this
typedef to get the correct API in Java. The trick to get the right
inheritance hierarchy as well, is to override the generator's selection
of superclass for ContactsManager and specify this manually, using the
"default-superclass" attribute. This will work, except for the fact that
the generator will already have copied the contents of SingletonTemplate
into ContactsManager with the generic type replaced by SomeClass*. If
SingletonTemplate contains any final methods (and it does) the compiler
will complain that ContactsManager is trying to override a final method.
This can be fixed by manually removing all SingletonTemplate's final
methods from ContactsManager in the type system. Something like this:
First, in your global header file somewhere, define a specialization of
SingletonTemplate:
--
#include <qtjambi.h>
typedef SingletonTemplate<JObjectWrapper> SingletonTemplateSpecialization;
--
Then, in your type system:
--
<object-type name="SingletonTemplate" generate="no" />
<object-type name="SingletonTemplateSpecialization"
generic-class="yes" java-name="SingletonTemplate" />
<object-type name="SomeClass" />
<object-type name="ContactsManager"
default-superclass="SingletonTemplate<SomeClass>">
<modify-function signature="somethingSomething()" remove="all" />
</object-type>
--
Please note that I have not tested whether the code produced for this
actually compiles, but I do at least think/hope you should be able to
tweak it into something that works.
-- Eskil
_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest