相关疑难解决方法(0)

将Python列表添加到使用Boost Python的向量中的函数中

我有一个带签名的功能:

function(std::vector<double> vector);
Run Code Online (Sandbox Code Playgroud)

而且我已经暴露了它,但它没有接受Python列表.我已经查看了其他的SO答案,并且大多数都涉及更改函数以接受boost :: python :: lists,但我不想更改函数.我想我可以使用vector_indexing_suite为这个函数编写一个简单的包装器,但是我有很多这种形式的函数,而不愿为每一个函数编写一个包装器.有没有办法自动生成Python list-> std :: vector映射?

boost iterator boost-python

23
推荐指数
1
解决办法
5424
查看次数

如何使用boost.python将预先填充的"unsigned char*"缓冲区传递给C++方法?

我有一个带有成员函数的C++类,它使用unsigned char*buffer和unsigned int length作为参数并对它们进行操作.我用Boost :: Python包装了这个类,并希望从Python脚本中将预先填充的缓冲区传递给该类.Python端缓冲区是用struct.pack创建的.我无法弄清楚如何使参数类型匹配并继续获取Boost.Python.ArgumentError.

包括/ example.h文件

#ifndef EXAMPLECLASS_H_
#define EXAMPLECLASS_H_

#include <cstdio>

class ExampleClass
{
public:
    ExampleClass() {}
    virtual ~ExampleClass() {}

    void printBuffer(unsigned char* buffer, unsigned int length)
    {
        for (unsigned int i = 0; i < length; ++i)
        {
            printf("%c", buffer[i]);
        }

        printf("\n");
    }
};

#endif
Run Code Online (Sandbox Code Playgroud)

SRC/example.cpp

#include "Example.h"

int main(int argc, char** argv)
{
    unsigned char buf[4];
    buf[0] = 0x41;
    buf[1] = 0x42;
    buf[2] = 0x43;
    buf[3] = 0x44;

    ExampleClass e;
    e.printBuffer(buf, 4);

    return 0;
} …
Run Code Online (Sandbox Code Playgroud)

c++ python boost ctypes boost-python

4
推荐指数
1
解决办法
1927
查看次数

标签 统计

boost ×2

boost-python ×2

c++ ×1

ctypes ×1

iterator ×1

python ×1