用于C ++的SIP Python包装器

时间:2013-10-09 09:37:47

标签: python python-sip

我是SIP新手。我正在尝试为C ++文件创建一个简单的python包装器。如果您有一个C ++示例python包装,请帮助我。我有一个示例代码。但是当我运行命令时,我收到错误“sip:string.sip:72:这个Python插槽需要%MethodCode”:         mkdir sipcode     cp sipcode-Makefile sipcode / Makefile     $(SIP)-s“.cc”-c sipcode string.sip

string.sip的代码如下所示:

%Module String

命名空间标准 {

类字符串 {

%TypeHeaderCode

包括string.h

%完

公共:     串();

string(const char*);
string(const std::string&);

bool empty();
int length();
int size();
void resize(int, char);
void resize(int);
int capacity();
void reserve(int =0);

std::string& append(const std::string&);
std::string& append(const std::string&, int, int);
std::string& append(const char*);
std::string& append(const char*, int);
std::string& append(int, char);

std::string& insert(int, const std::string&);
std::string& insert(int, const std::string&, int, int);
std::string& insert(int, const char*);
std::string& insert(int, const char*, int);
std::string& insert(int, int, char);

int find(const std::string&, int = 0);
int find(const char*, int, int);
int find(const char*, int = 0);
int find(char, int = 0);

int rfind(const std::string&, int = -1);
int rfind(const char*, int, int);
int rfind(const char*, int = -1);
int rfind(char, int = -1);

int find_first_of(const std::string&, int = 0);
int find_first_of(const char*, int, int);
int find_first_of(const char*, int = 0);
int find_first_of(char, int = 0);

int find_first_not_of(const std::string&, int = 0);
int find_first_not_of(const char*, int, int);
int find_first_not_of(const char*, int = 0);
int find_first_not_of(char, int = 0);

int find_last_of(const std::string&, int = 0);
int find_last_of(const char*, int, int);
int find_last_of(const char*, int = 0);
int find_last_of(char, int = 0);

int find_last_not_of(const std::string&, int = 0);
int find_last_not_of(const char*, int, int);
int find_last_not_of(const char*, int = 0);
int find_last_not_of(char, int = 0);

std::string substr(int = 0, int = -1);

void str (); %MemberCode     const char * s;     std :: string * ptr;

    if (sipParseArgs(&sipArgsParsed,sipArgs,"J1",sipClass_std_string, &ptr))
    {
        s = ptr->c_str();
        /* Python API reference, P40 */
        return PyString_FromString(s);
    }

%完

无效 getitem (); %MemberCode         std :: string * ptr;         int i;

    if (sipParseArgs(&sipArgsParsed,sipArgs,"J1i",sipClass_std_string, &ptr, &i))
    {

        if (i >= ptr->length())
        {
                /* Python API Reference, Chapter 4 */
                PyErr_SetString ( PyExc_IndexError  ,"string index out of range" );
                return NULL;
        }
        else

                return Py_BuildValue("c", ptr->at(i));
    }

%完

}; };

0 个答案:

没有答案