- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
如何在 swig 中使用 typemap 转换 python 列表。例如:
lst = [1.0,2.0,3.3] (Python list)
传递给
void print_arg(double *lst){} (c/c++ function)
我如何为此编写 swig 接口(interface)文件。
最佳答案
执行此操作的一种方法是使用 SWIG、carrays 和 cpointer
示例代码是:
SWIG 界面
%include "carrays.i"
%array_class(double, doubleArray);
Python模块
LEVEL = 3
thre = [1, 100, 10000]
a = example.doubleArray(LEVEL)
for i in xrange(LEVEL):
a[i] = thre[i]
gd=example.GradedDouble(LEVEL,a)
以上是我的工作示例...根据您的目的相应地更改代码...
关于c++ - 用于 python 列表的 SWIG typemap to double *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13523574/
假设我有nested.i像: %typemap(javaimports) Outer " /** * Outer class */" %typemap(javaimports) Outer::Inne
我正在使用 ModelMapper在对象之间做直接映射。 ModelMapper mapper = new ModelMapper(); // TypeMap created mapper.map(s
我正在使用 SWIG 将 c++ 包装在 python 中,并且需要使用类型映射以使我的 python 脚本尽可能简单。作为第一次尝试,我只是发送 2 个列表,将它们转换为 vector ,添加两个
我正在使用 SWIG 3.0 将我的 C 项目包装到 Python。我在接口(interface)文件中使用了一些指令,例如 %extend、%inline、%array_class,它们运行良好。我
我正在学习将 c++ 代码包装到 Python 模块中,像 int foo(int argc, char **argv); 这样的函数需要 typemap 例如,一个简单的 c++ 代码可以是 #in
我使用 ModelMapper 将模型转换为 DTO。我有一堆空值的默认转换器,它们已在映射器级别注册,如下所示: modelMapper.addConverter(new Conve
我正在使用 Swig 将 C/C++ 包装到 Java 中。 我有这个结构: struct score { void* goals; uint32_t goals_number; }
使用 vector 结构一切正常 %include %typemap(javaout) const S1& std::vector::get { //custom code } struct S
我正在尝试从 VARCHAR 类型的表字段 customernumber 中获取数据。就是这种情况,因为客户编号可以像“0024”和“1234”。 $query->getTypeMap() 告诉我它在
如何在 swig 中使用 typemap 转换 python 列表。例如: lst = [1.0,2.0,3.3] (Python list) 传递给 void print_arg(double *l
我正在尝试添加对 Augeas (Config::Augeas) 的 Perl 绑定(bind)的调用。我希望这个新调用返回一个 Perl 哈希。我写了这个: void
我有一个程序,其中的 C 函数有点像下面的代码。当我尝试通过 python 调用这个函数时,它抛出错误,说 参数 2 类型为“int *”。在 swig 中,我看到有一种方法可以通过类型映射来处理这个
我有一个 Java 应用程序调用 c 库来执行加密功能。这是一个用 c 实现的自定义库,我们需要从一些 Java 程序中使用它。我需要一种方法来定义 SWIG 类型映射,它允许我从 Java 调用一个
我目前有一个函数使用结构作为缓冲区来返回一些信息,如下所示: int example_reader(int code, void* return_struct); 我的目标是,当我使用 SWIG 包装
问题 我正在开发一个 Android 应用程序,其中我必须在 Java 代码和 C++ 代码之间传递 OpenCV Mat。为此,我创建了以下工作正常的 SWIG 类型映射: %include "st
我有一些 C 代码要公开给 Python。它有这样的调用约定: int add(int a, int b, int *err) 返回值是 (a+b) 或其他什么,但如果出现问题,那么我会在 *err
我正在尝试从 java 代码调用 c 函数。我正在使用 swig(1.3.40 版)并在 ubunto 下运行。 我的界面文件看起来: %module test %include "typemaps.
在 C++ 中 class A{ .. .. } class B{ .. .. } 现在在 java 中,我能够生成 A.java、B.java 类。现在我想在 java A 中扩展 B。所以我使用了
我正在尝试键入一个 typemap(out) std::vector。我希望它以数组的形式到达 perl 代码,而不是我得到一个数组数组,在双重取消引用之后它包含所需的数据。我怎样才能使它成为 per
我在尝试使用 %typemap(out) 包装一个将对 vector 对的常量引用返回到 Python 元组列表的 C++ 方法时遇到了很多麻烦。 我目前有这样的东西: 我的类.h: #inlcude
我是一名优秀的程序员,十分优秀!