[PyKDE] Sip does not wrap static const members of mapped type?

Jacob M. Burbach jacobb at cfl.rr.com
Tue Apr 18 05:14:20 BST 2006


I'm wrapping some classes and find that Sip will not wrap static const members 
that are defined as a MappedType. Standard types, wrapped types, and
non const members are wrapped ok, just not const mapped types. This seems like 
a bug in sip?

As a work around I can remove the  'const' and provide hand written code to do 
the conversions and it will work. I have hundreds of such members though so 
that is less than ideal for me. 

//--- Example module --//
%Module Test 0

// Map std string
%MappedType std::string
{
%TypeHeaderCode
#include <string>
%End

%ConvertToTypeCode
if (sipIsErr == 0)
    return PyString_Check(sipPy);

*sipCppPtr = new std::string( PyString_AsString(sipPy) );
return sipGetState(sipTransferObj);
%End

%ConvertFromTypeCode
return PyString_FromString( sipCpp->c_str() );
%End
};


// Define two class to wrap

%ModuleHeaderCode
#include <string>
class NotAMappedType {
public:
    NotAMappedType() {}
};

class Test {
public:
    static const std::string StringOne;
    static const std::string StringTwo;
    static const NotAMappedType NonMappedType;
    static const double MyDouble;
    static const int MyInt;
};
%End

%ModuleCode
const std::string Test::StringOne = "StringOne";
const std::string Test::StringTwo = "StringTwo";
const NotAMappedType Test::NonMappedType;
const double Test::MyDouble = 102.021;
const int Test::MyInt = 32;
%End


// Wrapper specs

class NotAMappedType
{
public:
    NotAMappedType();
};


class Test
{
public:
    static const std::string StringOne; // Sip will not wrap.
    
    //static const std::string StringTwo;
    static std::string StringTwo; // Work around
%GetCode
     sipPy = 
sipConvertFromMappedType(const_cast<std::string*>(&Test::StringTwo), 
sipMappedType_std_string, 0);
%End
%SetCode
    sipErr = 1;
    PyErr_SetString(PyExc_AttributeError, "Read only member");
%End

    static const int MyInt; // Ok 
    static const double MyDouble; Ok
    static const NotAMappedType NonMappedType; // Ok
};







More information about the PyQt mailing list