SIP template

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

SIP template

Denis Rouzaud
Dear all,

I am facing an issue with correcty implementing a template (container)) in SIP.

Let’s say I have

qgsoptional:
template<class T>
class QgsOptional
{
  public:
    QgsOptional( const T &data, bool enabled )
      : mEnabled( enabled )
      , mData( data )
    {}
  private:
    bool mEnabled;
    T mData;
};

qgsoptionalexpression.h:

class QgsOptionalExpression : public QgsOptional<QgsExpression>
{
  public:
    QgsOptionalExpression();
}


Now, I’d like to create the SIP file for QgsOptioalExpression. I tried with what I found in another topic [0]:

class QgsOptionalExpression
{
%TypeHeaderCode
#include "qgsoptional.h"
typedef QgsOptional<QgsExpression> QgsOptionalExpression;
%End
  public:
    QgsOptionalExpression();
}

But this gives me this error:
python/core/qgsoptionalexpression.sip:29:36: error: typedef redefinition with different types ('QgsOptional' vs 'QgsOptionalExpression')
typedef QgsOptional QgsOptionalExpression;
The error points that the definition is already included in the header qgsoptionalepxression.h while I am actually not including it here (also gave it a try with including it).

I understand the point, but how shall I tackle this?
If I remove the inheritance, I’m of course not getting any of the container methods.
I also gave it a try with a ModuleHeaderCode:

 %ModuleHeaderCode
 #include "qgsoptional.h"
 #include "qgsexpression.h"
 typedef QgsOptional<QgsExpression> QgsOptionalExpression;
 %End

But it fails with the same kind of error, complaining the type is already defined in the header (also with or without including it in the TypeHeaderCode.


Any idea how to solve this?
Thanks a lot!

Denis



_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

David Boddie
On Tue May 16 20:49:57 BST 2017, Denis Rouzaud wrote:

> I am facing an issue with correcty implementing a template (container)) in
> SIP.
>
> Let’s say I have
>
> qgsoptional:
> template<class T>
> class QgsOptional
> {
>   public:
>     QgsOptional( const T &data, bool enabled )
>       : mEnabled( enabled )
>       , mData( data )
>     {}
>   private:
>     bool mEnabled;
>     T mData;
> };
>
> qgsoptionalexpression.h:
>
> class QgsOptionalExpression : public QgsOptional<QgsExpression>
> {
>   public:
>     QgsOptionalExpression();
> }

OK, so you are defining a class called QgsOptionalExpression here. As far as
I can see, this will conflict with what you are doing next:

> Now, I’d like to create the SIP file for QgsOptioalExpression. I tried with
> what I found in another topic [0]:
>
> class QgsOptionalExpression
> {
> %TypeHeaderCode
> #include "qgsoptional.h"
> typedef QgsOptional<QgsExpression> QgsOptionalExpression;
> %End
>   public:
>     QgsOptionalExpression();
> }

Here, you define QgsOptionalExpression again using a typedef, resulting in
the following error:

> But this gives me this error:
> python/core/qgsoptionalexpression.sip:29:36: error: typedef redefinition
> with different types ('QgsOptional' vs 'QgsOptionalExpression')
> typedef QgsOptional QgsOptionalExpression;
> The error points that the definition is already included in the header
> qgsoptionalepxression.h while I am actually not including it here (also gave
> it a try with including it).
>
> I understand the point, but how shall I tackle this?

Good. :-) Just for others reading this, the reason for the conflict is that
the typedef is included in the generated C++ code, so the compiler will
encounter both the class definition and the typedef.

If you don't need the class definition then remove it.

If you do need it then I think you should be able to leave out the typedef
and include the custom qgsoptionalexpression.h header instead:

class QgsOptionalExpression
{
%TypeHeaderCode
#include "qgsoptionalexpression.h"
%End
  public:
    QgsOptionalExpression();
}

Does that help?

David
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Denis Rouzaud
Hi Davod,

Thanks a lot for you reply.

Le mar. 16 mai 2017 à 23:38, David Boddie <[hidden email]> a écrit :
On Tue May 16 20:49:57 BST 2017, Denis Rouzaud wrote:

> I am facing an issue with correcty implementing a template (container)) in
> SIP.
>
> Let’s say I have
>
> qgsoptional:
> template<class T>
> class QgsOptional
> {
>   public:
>     QgsOptional( const T &data, bool enabled )
>       : mEnabled( enabled )
>       , mData( data )
>     {}
>   private:
>     bool mEnabled;
>     T mData;
> };
>
> qgsoptionalexpression.h:
>
> class QgsOptionalExpression : public QgsOptional<QgsExpression>
> {
>   public:
>     QgsOptionalExpression();
> }

OK, so you are defining a class called QgsOptionalExpression here. As far as
I can see, this will conflict with what you are doing next:

> Now, I’d like to create the SIP file for QgsOptioalExpression. I tried with
> what I found in another topic [0]:
>
> class QgsOptionalExpression
> {
> %TypeHeaderCode
> #include "qgsoptional.h"
> typedef QgsOptional<QgsExpression> QgsOptionalExpression;
> %End
>   public:
>     QgsOptionalExpression();
> }

Here, you define QgsOptionalExpression again using a typedef, resulting in
the following error:

> But this gives me this error:
> python/core/qgsoptionalexpression.sip:29:36: error: typedef redefinition
> with different types ('QgsOptional' vs 'QgsOptionalExpression')
> typedef QgsOptional QgsOptionalExpression;
> The error points that the definition is already included in the header
> qgsoptionalepxression.h while I am actually not including it here (also gave
> it a try with including it).
>
> I understand the point, but how shall I tackle this?

Good. :-) Just for others reading this, the reason for the conflict is that
the typedef is included in the generated C++ code, so the compiler will
encounter both the class definition and the typedef.

If you don't need the class definition then remove it.

If you do need it then I think you should be able to leave out the typedef
and include the custom qgsoptionalexpression.h header instead:

class QgsOptionalExpression
{
%TypeHeaderCode
#include "qgsoptionalexpression.h"
%End
  public:
    QgsOptionalExpression();
}

Does that help?


This compiles but I don't have access to enabled() and data() methods in the template class (QgsOptional), which is a major issue.

With the inheritance written: 
class QgsOptionalExpression : public QgOptional<QgsExpression> 
I get a "syntax error".

Any idea?

Cheers,
Denis

 

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Phil Thompson-5
On 17 May 2017, at 5:56 am, Denis Rouzaud <[hidden email]> wrote:

>
> Hi Davod,
>
> Thanks a lot for you reply.
>
> Le mar. 16 mai 2017 à 23:38, David Boddie <[hidden email]> a écrit :
> On Tue May 16 20:49:57 BST 2017, Denis Rouzaud wrote:
>
> > I am facing an issue with correcty implementing a template (container)) in
> > SIP.
> >
> > Let’s say I have
> >
> > qgsoptional:
> > template<class T>
> > class QgsOptional
> > {
> >   public:
> >     QgsOptional( const T &data, bool enabled )
> >       : mEnabled( enabled )
> >       , mData( data )
> >     {}
> >   private:
> >     bool mEnabled;
> >     T mData;
> > };
> >
> > qgsoptionalexpression.h:
> >
> > class QgsOptionalExpression : public QgsOptional<QgsExpression>
> > {
> >   public:
> >     QgsOptionalExpression();
> > }
>
> OK, so you are defining a class called QgsOptionalExpression here. As far as
> I can see, this will conflict with what you are doing next:
>
> > Now, I’d like to create the SIP file for QgsOptioalExpression. I tried with
> > what I found in another topic [0]:
> >
> > class QgsOptionalExpression
> > {
> > %TypeHeaderCode
> > #include "qgsoptional.h"
> > typedef QgsOptional<QgsExpression> QgsOptionalExpression;
> > %End
> >   public:
> >     QgsOptionalExpression();
> > }
>
> Here, you define QgsOptionalExpression again using a typedef, resulting in
> the following error:
>
> > But this gives me this error:
> > python/core/qgsoptionalexpression.sip:29:36: error: typedef redefinition
> > with different types ('QgsOptional' vs 'QgsOptionalExpression')
> > typedef QgsOptional QgsOptionalExpression;
> > The error points that the definition is already included in the header
> > qgsoptionalepxression.h while I am actually not including it here (also gave
> > it a try with including it).
> >
> > I understand the point, but how shall I tackle this?
>
> Good. :-) Just for others reading this, the reason for the conflict is that
> the typedef is included in the generated C++ code, so the compiler will
> encounter both the class definition and the typedef.
>
> If you don't need the class definition then remove it.
>
> If you do need it then I think you should be able to leave out the typedef
> and include the custom qgsoptionalexpression.h header instead:
>
> class QgsOptionalExpression
> {
> %TypeHeaderCode
> #include "qgsoptionalexpression.h"
> %End
>   public:
>     QgsOptionalExpression();
> }
>
> Does that help?
>
>
> This compiles but I don't have access to enabled() and data() methods in the template class (QgsOptional), which is a major issue.
>
> With the inheritance written:
> class QgsOptionalExpression : public QgOptional<QgsExpression>
> I get a "syntax error".
>
> Any idea?

Just lie to SIP and add them to the definition of QgsOptionalExpression.

See QItemSelection in qitemselectionmodel.sip in PyQt5.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Denis Rouzaud

Hi Phil,

Thanks a lot for your reply.
I was hoping not to go that way to avoid any redundancy and some weakness in the code (any change to the template class methods would need to be propagated to all implementations).

There is no other way?
Cheers,
Denis



Le mer. 17 mai 2017 à 09:44, Phil Thompson <[hidden email]> a écrit :
On 17 May 2017, at 5:56 am, Denis Rouzaud <[hidden email]> wrote:
>
> Hi Davod,
>
> Thanks a lot for you reply.
>
> Le mar. 16 mai 2017 à 23:38, David Boddie <[hidden email]> a écrit :
> On Tue May 16 20:49:57 BST 2017, Denis Rouzaud wrote:
>
> > I am facing an issue with correcty implementing a template (container)) in
> > SIP.
> >
> > Let’s say I have
> >
> > qgsoptional:
> > template<class T>
> > class QgsOptional
> > {
> >   public:
> >     QgsOptional( const T &data, bool enabled )
> >       : mEnabled( enabled )
> >       , mData( data )
> >     {}
> >   private:
> >     bool mEnabled;
> >     T mData;
> > };
> >
> > qgsoptionalexpression.h:
> >
> > class QgsOptionalExpression : public QgsOptional<QgsExpression>
> > {
> >   public:
> >     QgsOptionalExpression();
> > }
>
> OK, so you are defining a class called QgsOptionalExpression here. As far as
> I can see, this will conflict with what you are doing next:
>
> > Now, I’d like to create the SIP file for QgsOptioalExpression. I tried with
> > what I found in another topic [0]:
> >
> > class QgsOptionalExpression
> > {
> > %TypeHeaderCode
> > #include "qgsoptional.h"
> > typedef QgsOptional<QgsExpression> QgsOptionalExpression;
> > %End
> >   public:
> >     QgsOptionalExpression();
> > }
>
> Here, you define QgsOptionalExpression again using a typedef, resulting in
> the following error:
>
> > But this gives me this error:
> > python/core/qgsoptionalexpression.sip:29:36: error: typedef redefinition
> > with different types ('QgsOptional' vs 'QgsOptionalExpression')
> > typedef QgsOptional QgsOptionalExpression;
> > The error points that the definition is already included in the header
> > qgsoptionalepxression.h while I am actually not including it here (also gave
> > it a try with including it).
> >
> > I understand the point, but how shall I tackle this?
>
> Good. :-) Just for others reading this, the reason for the conflict is that
> the typedef is included in the generated C++ code, so the compiler will
> encounter both the class definition and the typedef.
>
> If you don't need the class definition then remove it.
>
> If you do need it then I think you should be able to leave out the typedef
> and include the custom qgsoptionalexpression.h header instead:
>
> class QgsOptionalExpression
> {
> %TypeHeaderCode
> #include "qgsoptionalexpression.h"
> %End
>   public:
>     QgsOptionalExpression();
> }
>
> Does that help?
>
>
> This compiles but I don't have access to enabled() and data() methods in the template class (QgsOptional), which is a major issue.
>
> With the inheritance written:
> class QgsOptionalExpression : public QgOptional<QgsExpression>
> I get a "syntax error".
>
> Any idea?

Just lie to SIP and add them to the definition of QgsOptionalExpression.

See QItemSelection in qitemselectionmodel.sip in PyQt5.

Phil

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Phil Thompson-5
On 17 May 2017, at 8:55 am, Denis Rouzaud <[hidden email]> wrote:
>
>
> Hi Phil,
>
> Thanks a lot for your reply.
> I was hoping not to go that way to avoid any redundancy and some weakness in the code (any change to the template class methods would need to be propagated to all implementations).
>
> There is no other way?

I don't think so.

Phil

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Denis Rouzaud


Le mer. 17 mai 2017 à 10:31, Phil Thompson <[hidden email]> a écrit :
On 17 May 2017, at 8:55 am, Denis Rouzaud <[hidden email]> wrote:
>
>
> Hi Phil,
>
> Thanks a lot for your reply.
> I was hoping not to go that way to avoid any redundancy and some weakness in the code (any change to the template class methods would need to be propagated to all implementations).
>
> There is no other way?

I don't think so.

It's a pity, I thought it would have been a more common issue.
Thanks a lot for your feedback! 

Phil


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Shaheed Haque
I've possibly missed soemthing, but does this help:

https://www.riverbankcomputing.com/pipermail/pyqt/2017-January/038660.html

(I've not implemented this myself yet, but the SIP file certainly compiles :-))

On 17 May 2017 at 09:32, Denis Rouzaud <[hidden email]> wrote:

>
>
> Le mer. 17 mai 2017 à 10:31, Phil Thompson <[hidden email]> a
> écrit :
>>
>> On 17 May 2017, at 8:55 am, Denis Rouzaud <[hidden email]> wrote:
>> >
>> >
>> > Hi Phil,
>> >
>> > Thanks a lot for your reply.
>> > I was hoping not to go that way to avoid any redundancy and some
>> > weakness in the code (any change to the template class methods would need to
>> > be propagated to all implementations).
>> >
>> > There is no other way?
>>
>> I don't think so.
>
>
> It's a pity, I thought it would have been a more common issue.
> Thanks a lot for your feedback!
>>
>>
>> Phil
>>
>
> _______________________________________________
> PyQt mailing list    [hidden email]
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Denis Rouzaud
Hi Shaheed,

This helped a bit, thanks a lot.

But when doing 
class QgsOptionalExpression : QgsOptional<QgsExpression>
I fall back to a syntax error on this line (on sip 4.18.1)

I also tried to use a typedef, similarly to the example you provided:

%ModuleHeaderCode
#include "qgsoptional.h"
%End
typedef QgsOptional<QgsExpression> QgsOptionalExpressionBase;
class QgsOptionalExpression : QgsOptionalExpressionBase
{
.....
}

But I get: qgsoptionalexpression.sip:18: Super-class list contains an invalid type

It just seems not possible to inherit from a template, I wonder why it works in the example you pointed and not in my case.

Cheers,
Denis









Le mer. 17 mai 2017 à 15:58, Shaheed Haque <[hidden email]> a écrit :
I've possibly missed soemthing, but does this help:

https://www.riverbankcomputing.com/pipermail/pyqt/2017-January/038660.html

(I've not implemented this myself yet, but the SIP file certainly compiles :-))

On 17 May 2017 at 09:32, Denis Rouzaud <[hidden email]> wrote:
>
>
> Le mer. 17 mai 2017 à 10:31, Phil Thompson <[hidden email]> a
> écrit :
>>
>> On 17 May 2017, at 8:55 am, Denis Rouzaud <[hidden email]> wrote:
>> >
>> >
>> > Hi Phil,
>> >
>> > Thanks a lot for your reply.
>> > I was hoping not to go that way to avoid any redundancy and some
>> > weakness in the code (any change to the template class methods would need to
>> > be propagated to all implementations).
>> >
>> > There is no other way?
>>
>> I don't think so.
>
>
> It's a pity, I thought it would have been a more common issue.
> Thanks a lot for your feedback!
>>
>>
>> Phil
>>
>
> _______________________________________________
> PyQt mailing list    [hidden email]
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Denis Rouzaud

Sorry, for the noise.

I missed the second typedef in the ModuleHeaderCode, it works!
Thanks to David, Phil and Shaheed for the hints!

Cheers,
Denis

Le jeu. 18 mai 2017 à 11:21, Denis Rouzaud <[hidden email]> a écrit :
Hi Shaheed,

This helped a bit, thanks a lot.

But when doing 
class QgsOptionalExpression : QgsOptional<QgsExpression>
I fall back to a syntax error on this line (on sip 4.18.1)

I also tried to use a typedef, similarly to the example you provided:

%ModuleHeaderCode
#include "qgsoptional.h"
%End
typedef QgsOptional<QgsExpression> QgsOptionalExpressionBase;
class QgsOptionalExpression : QgsOptionalExpressionBase
{
.....
}

But I get: qgsoptionalexpression.sip:18: Super-class list contains an invalid type

It just seems not possible to inherit from a template, I wonder why it works in the example you pointed and not in my case.

Cheers,
Denis









Le mer. 17 mai 2017 à 15:58, Shaheed Haque <[hidden email]> a écrit :
I've possibly missed soemthing, but does this help:

https://www.riverbankcomputing.com/pipermail/pyqt/2017-January/038660.html

(I've not implemented this myself yet, but the SIP file certainly compiles :-))

On 17 May 2017 at 09:32, Denis Rouzaud <[hidden email]> wrote:
>
>
> Le mer. 17 mai 2017 à 10:31, Phil Thompson <[hidden email]> a
> écrit :
>>
>> On 17 May 2017, at 8:55 am, Denis Rouzaud <[hidden email]> wrote:
>> >
>> >
>> > Hi Phil,
>> >
>> > Thanks a lot for your reply.
>> > I was hoping not to go that way to avoid any redundancy and some
>> > weakness in the code (any change to the template class methods would need to
>> > be propagated to all implementations).
>> >
>> > There is no other way?
>>
>> I don't think so.
>
>
> It's a pity, I thought it would have been a more common issue.
> Thanks a lot for your feedback!
>>
>>
>> Phil
>>
>
> _______________________________________________
> PyQt mailing list    [hidden email]
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Shaheed Haque
Hi,

On 18 May 2017 at 13:14, Denis Rouzaud <[hidden email]> wrote:
>
> Sorry, for the noise.
>
> I missed the second typedef in the ModuleHeaderCode, it works!
> Thanks to David, Phil and Shaheed for the hints!

Is there a variation on this technique that works for nested classes?
It turns out that in all 17 places this affects PyKF5 involve nested
classes, and attempting to modify this SIP:

=============
namespace KContacts
{
    class AddresseeList: QVector<KContacts::Addressee>
    {
=============

into this SIP:

=============
namespace KContacts
{
%TypeHeaderCode
typedef QVector<KContacts::Addressee> foo_t;
%End
typedef QVector<KContacts::Addressee> foo_t;
    class AddresseeList: KContacts::foo_t
    {
=============

only results in:

sip: tmp/KContacts/KContacts/AddresseeList.sip:121: Super-class list
contains an invalid type

I stared a the code that emits the message in parser.y (and also tried
moving foo_t to global scope), without the solution becoming obvious.
So, any clues or ideas welcomed!

Thanks, Shaheed

> Cheers,
> Denis
>
> Le jeu. 18 mai 2017 à 11:21, Denis Rouzaud <[hidden email]> a écrit
> :
>>
>> Hi Shaheed,
>>
>> This helped a bit, thanks a lot.
>>
>> But when doing
>> class QgsOptionalExpression : QgsOptional<QgsExpression>
>> I fall back to a syntax error on this line (on sip 4.18.1)
>>
>> I also tried to use a typedef, similarly to the example you provided:
>>
>> %ModuleHeaderCode
>> #include "qgsoptional.h"
>> %End
>> typedef QgsOptional<QgsExpression> QgsOptionalExpressionBase;
>> class QgsOptionalExpression : QgsOptionalExpressionBase
>> {
>> .....
>> }
>>
>> But I get: qgsoptionalexpression.sip:18: Super-class list contains an
>> invalid type
>>
>> It just seems not possible to inherit from a template, I wonder why it
>> works in the example you pointed and not in my case.
>>
>> Cheers,
>> Denis
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> Le mer. 17 mai 2017 à 15:58, Shaheed Haque <[hidden email]> a écrit :
>>>
>>> I've possibly missed soemthing, but does this help:
>>>
>>>
>>> https://www.riverbankcomputing.com/pipermail/pyqt/2017-January/038660.html
>>>
>>> (I've not implemented this myself yet, but the SIP file certainly
>>> compiles :-))
>>>
>>> On 17 May 2017 at 09:32, Denis Rouzaud <[hidden email]> wrote:
>>> >
>>> >
>>> > Le mer. 17 mai 2017 à 10:31, Phil Thompson
>>> > <[hidden email]> a
>>> > écrit :
>>> >>
>>> >> On 17 May 2017, at 8:55 am, Denis Rouzaud <[hidden email]>
>>> >> wrote:
>>> >> >
>>> >> >
>>> >> > Hi Phil,
>>> >> >
>>> >> > Thanks a lot for your reply.
>>> >> > I was hoping not to go that way to avoid any redundancy and some
>>> >> > weakness in the code (any change to the template class methods would
>>> >> > need to
>>> >> > be propagated to all implementations).
>>> >> >
>>> >> > There is no other way?
>>> >>
>>> >> I don't think so.
>>> >
>>> >
>>> > It's a pity, I thought it would have been a more common issue.
>>> > Thanks a lot for your feedback!
>>> >>
>>> >>
>>> >> Phil
>>> >>
>>> >
>>> > _______________________________________________
>>> > PyQt mailing list    [hidden email]
>>> > https://www.riverbankcomputing.com/mailman/listinfo/pyqt
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Phil Thompson-5
On 2 Aug 2017, at 9:21 am, Shaheed Haque <[hidden email]> wrote:

>
> Hi,
>
> On 18 May 2017 at 13:14, Denis Rouzaud <[hidden email]> wrote:
>>
>> Sorry, for the noise.
>>
>> I missed the second typedef in the ModuleHeaderCode, it works!
>> Thanks to David, Phil and Shaheed for the hints!
>
> Is there a variation on this technique that works for nested classes?
> It turns out that in all 17 places this affects PyKF5 involve nested
> classes, and attempting to modify this SIP:
>
> =============
> namespace KContacts
> {
>    class AddresseeList: QVector<KContacts::Addressee>
>    {
> =============
>
> into this SIP:
>
> =============
> namespace KContacts
> {
> %TypeHeaderCode
> typedef QVector<KContacts::Addressee> foo_t;
> %End
> typedef QVector<KContacts::Addressee> foo_t;
>    class AddresseeList: KContacts::foo_t
>    {
> =============
>
> only results in:
>
> sip: tmp/KContacts/KContacts/AddresseeList.sip:121: Super-class list
> contains an invalid type
>
> I stared a the code that emits the message in parser.y (and also tried
> moving foo_t to global scope), without the solution becoming obvious.
> So, any clues or ideas welcomed!

PyQt has the same problem with QPolygon. The workaround is to say that AddresseeList does not have a super-class and to add any QVector methods you want to AddresseeList. See qpolygon.sip in PyQt.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Shaheed Haque
On 8 August 2017 at 17:23, Phil Thompson <[hidden email]> wrote:

> On 2 Aug 2017, at 9:21 am, Shaheed Haque <[hidden email]> wrote:
>>
>> Hi,
>>
>> On 18 May 2017 at 13:14, Denis Rouzaud <[hidden email]> wrote:
>>>
>>> Sorry, for the noise.
>>>
>>> I missed the second typedef in the ModuleHeaderCode, it works!
>>> Thanks to David, Phil and Shaheed for the hints!
>>
>> Is there a variation on this technique that works for nested classes?
>> It turns out that in all 17 places this affects PyKF5 involve nested
>> classes, and attempting to modify this SIP:
>>
>> =============
>> namespace KContacts
>> {
>>    class AddresseeList: QVector<KContacts::Addressee>
>>    {
>> =============
>>
>> into this SIP:
>>
>> =============
>> namespace KContacts
>> {
>> %TypeHeaderCode
>> typedef QVector<KContacts::Addressee> foo_t;
>> %End
>> typedef QVector<KContacts::Addressee> foo_t;
>>    class AddresseeList: KContacts::foo_t
>>    {
>> =============
>>
>> only results in:
>>
>> sip: tmp/KContacts/KContacts/AddresseeList.sip:121: Super-class list
>> contains an invalid type
>>
>> I stared a the code that emits the message in parser.y (and also tried
>> moving foo_t to global scope), without the solution becoming obvious.
>> So, any clues or ideas welcomed!
>
> PyQt has the same problem with QPolygon. The workaround is to say that AddresseeList does not have a super-class and to add any QVector methods you want to AddresseeList. See qpolygon.sip in PyQt.

Thanks Phil...

>
> Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Shaheed Haque
On 8 August 2017 at 22:12, Shaheed Haque <[hidden email]> wrote:
On 8 August 2017 at 17:23, Phil Thompson <[hidden email]> wrote:
> On 2 Aug 2017, at 9:21 am, Shaheed Haque <[hidden email]> wrote:
>>
>> Hi,
>>
>> On 18 May 2017 at 13:14, Denis Rouzaud <[hidden email]> wrote:
>>>
>>> Sorry, for the noise.
>>>
>>> I missed the second typedef in the ModuleHeaderCode, it works!
>>> Thanks to David, Phil and Shaheed for the hints!
>>
>> Is there a variation on this technique that works for nested classes?
>> It turns out that in all 17 places this affects PyKF5 involve nested
>> classes, and attempting to modify this SIP:
>>
>> =============
>> namespace KContacts
>> {
>>    class AddresseeList: QVector<KContacts::Addressee>
>>    {
>> =============
>>
>> into this SIP:
>>
>> =============
>> namespace KContacts
>> {
>> %TypeHeaderCode
>> typedef QVector<KContacts::Addressee> foo_t;
>> %End
>> typedef QVector<KContacts::Addressee> foo_t;
>>    class AddresseeList: KContacts::foo_t
>>    {
>> =============
>>
>> only results in:
>>
>> sip: tmp/KContacts/KContacts/AddresseeList.sip:121: Super-class list
>> contains an invalid type
>>
>> I stared a the code that emits the message in parser.y (and also tried
>> moving foo_t to global scope), without the solution becoming obvious.
>> So, any clues or ideas welcomed!
>
> PyQt has the same problem with QPolygon. The workaround is to say that AddresseeList does not have a super-class and to add any QVector methods you want to AddresseeList. See qpolygon.sip in PyQt.

Thanks Phil...

I'm still working on variations of this topic. The problem I am having at the moment is that a sequence like this, where Bar has a base which is a %MappedType:

=======
%Module(name=xxx)

%MappedType FooBad
{
%ConvertFromTypeCode
// blah.
%End
%ConvertToTypeCode
// blah.
%End
};

class FooOK
{
public:
    FooOK();
};

class Bar: FooBad
{  <<<<<<<<<<<<<<<< This is line 20
public:
    Bar();
};
=======

gives the error "sip: tmp.sip:20: A class, exception, namespace or mapped type has already been defined with the same name" but if I change the base class from FooBad to the non-%MappedType normal class FooOK, it compiles just fine. I'm on 4.19.4.dev1708081632...have I gone mad?

Thanks, Shaheed
 
>
> Phil


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Phil Thompson-5
On 14 Aug 2017, at 11:13 am, Shaheed Haque <[hidden email]> wrote:

> I'm still working on variations of this topic. The problem I am having at the moment is that a sequence like this, where Bar has a base which is a %MappedType:
>
> =======
> %Module(name=xxx)
>
> %MappedType FooBad
> {
> %ConvertFromTypeCode
> // blah.
> %End
> %ConvertToTypeCode
> // blah.
> %End
> };
>
> class FooOK
> {
> public:
>     FooOK();
> };
>
> class Bar: FooBad
> {  <<<<<<<<<<<<<<<< This is line 20
> public:
>     Bar();
> };
> =======
>
> gives the error "sip: tmp.sip:20: A class, exception, namespace or mapped type has already been defined with the same name" but if I change the base class from FooBad to the non-%MappedType normal class FooOK, it compiles just fine. I'm on 4.19.4.dev1708081632...have I gone mad?

It's a terrible error message, but you can't sub-class from mapped types.

Phil
_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: SIP template

Shaheed Haque

On 14 August 2017 at 17:22, Phil Thompson <[hidden email]> wrote:
On 14 Aug 2017, at 11:13 am, Shaheed Haque <[hidden email]> wrote:
> I'm still working on variations of this topic. The problem I am having at the moment is that a sequence like this, where Bar has a base which is a %MappedType:
>
> =======
> %Module(name=xxx)
>
> %MappedType FooBad
> {
> %ConvertFromTypeCode
> // blah.
> %End
> %ConvertToTypeCode
> // blah.
> %End
> };
>
> class FooOK
> {
> public:
>     FooOK();
> };
>
> class Bar: FooBad
> {  <<<<<<<<<<<<<<<< This is line 20
> public:
>     Bar();
> };
> =======
>
> gives the error "sip: tmp.sip:20: A class, exception, namespace or mapped type has already been defined with the same name" but if I change the base class from FooBad to the non-%MappedType normal class FooOK, it compiles just fine. I'm on 4.19.4.dev1708081632...have I gone mad?

It's a terrible error message, but you can't sub-class from mapped types.

Ah, OK.

Thanks, Shaheed
 
Phil


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt