有没有一种方法可以用Boost.Python将所有对象包含在C++头文件中?

2024-06-16 10:33:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码:

#include "boost_facade.h"

BOOST_PYTHON_MODULE (libdtlinux) {
    using namespace boost::python;
    class_<DtSearch>("DtSearch")
            .def("DoSearch", &DtSearch::DoSearch)
            .def("CreateIndex", &DtSearch::CreateIndex);
}

我想做的是让Boost自动添加class DtSearch和所有子方法,而不必在BOOST_PYTHON_MODULE中逐个定义它们。你知道吗

有没有办法在头文件中包含所有对象,或者我需要像现在这样指定它们?你知道吗

更新

SWIG有我正在寻找的功能,但是我需要使用Boost.Python版本. 以下是swig示例:

%module example
 %{
 /* Includes the header in the wrapper code */
 #include "header.h"
 %}

 /* Parse the header file to generate wrappers */
 %include "header.h"

参考:http://www.swig.org/tutorial.html位于SWIG下,用于真正懒惰的人


Tags: the代码includedefclassswigheadermodule