[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Typedefs and SIP
From:       Phil Thompson <phil () riverbankcomputing ! com>
Date:       2011-01-27 10:28:23
Message-ID: 096a7d03ae41a4268da33e88eed2dd4a () localhost
[Download RAW message or body]

On Wed, 26 Jan 2011 10:18:55 -0800, Nate Reid <gnatty7@hotmail.com> wrote:
> If I'm using a typedef with a MappedType, and a container that's a
> MappedType,  it seems like I have to use a #define to tell SIP that the
> specific typedef is the same as the MappedType.
> E.g.
> 
> I've wrapped std::string with MappedType, so it's type is
> sipType_std_string
> 
> and I've also wrapped std::set in a MappedType where template<TYPE>
> std::set<TYPE> is defined.
> 
> If I do a typedef in my C++ code as:
> // C++ file...
> namespace foo {
>     typedef std::string NameType
> }
> 
> And also in my SIP file, create an equivalent typedef
> // SIP module file
> namespace foo {
>     typedef std::string NameType;
>     typedef std::set<foo::NameType> SetOfNames; // Aside, it'd be great
if
>     SIP knew that NameType was already a member of foo, and I didn't
have
>     to explicitly qualify it!
> };
> 
> SIP will come back with a compile error like this when using NameType in
> my MappedType for std::set
> python/util/set.sip(73): error: identifier "sipType_foo_NameType" is
> undefined
>               foo::NameType *copy = reinterpret_cast<foo::NameType
>               *>(sipConvertToType(item, sipType_foo_NameType,
>               sipTransferObj, SIP_NOT_NONE, &state, sipIsErr))
> 
> I was able to get rid of the compile error by adding a #define to my
> %ModuleHeaderCode section of the SIP file like this
> %ModuleHeaderCode
> ...
> #define sipType_foo_NameType sipType_std_string
> 
> It seems to me that this is fragile.  If I change the namespace of where
> NameType lives, I'd have to manually change all of the #defines,
typedefs
> in the SIP files, etc.  Also, requiring this 'hint' to SIP seems
erroneous
> to me.  Shouldn't the typedef be sufficient for creating a new sipType
in
> the API file?
> Or, am I doing something wrong? :)
> Thanks,
> -Nate

typedef shouldn't create a new sipType because you are creating an alias
to an existing type, not creating a new one. If you move the typedef to a
different namespace then you are changing its name and should expect to
have to make corresponding changes in the rest of your source.

Automatically generating the #defines seems to be a reasonable suggestion.

Phil


_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic