[PyQt] Typedefs and SIP

Nate Reid gnatty7 at hotmail.com
Wed Jan 26 18:18:55 GMT 2011


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
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110126/1bb7fa9e/attachment.html>


More information about the PyQt mailing list