boost python def 函数导出
来源:互联网 发布:oracle数据库软件 编辑:程序博客网 时间:2024/06/05 07:41
Introduction
def()
is the function which can be used to expose C++ functions and callable objects as Python functions in the current scope
.
这个函数可以帮助我们将C++中的函数导出到Python中,供Python使用。说实话,真的很好用。
Functions
def
template <class F>void def(char const* name, F f);template <class Fn, class A1>void def(char const* name, Fn fn, A1 const&);template <class Fn, class A1, class A2>void def(char const* name, Fn fn, A1 const&, A2 const&);template <class Fn, class A1, class A2, class A3>void def(char const* name, Fn fn, A1 const&, A2 const&, A3 const&);
Requires: name
is an ntbs which conforms to Python's identifier naming rules.
- If
Fn
is [derived from]object
, it will be added to the current scope as a single overload. To be useful,fn
should be callable. - If
a1
is the result of an overload-dispatch-expression, only the second form is allowed and fn must be a pointer to function or pointer to member function whose arity is the same as A1's maximum arity.- Effects: For each prefix P of
Fn
's sequence of argument types, beginning with the one whose length isA1
's minimum arity, adds aname(
...)
function overload to the current scope. Each overload generated invokesa1
's call-expression with P, using a copy ofa1
's call policies. If the longest valid prefix ofA1
contains N types anda1
holds M keywords, an initial sequence of the keywords are used for all but the first N - M arguments of each overload.
- Effects: For each prefix P of
- Otherwise, fn must be a non-null function or member function pointer, and a single function overload built around fn is added to the current scope. If any of
a1
-a3
are supplied, they may be selected in any order from the table below.
Memnonic Name Requirements/Type properties Effects docstringAny ntbs.Value will be bound to the__doc__
attribute of the resulting method overload.policiesA model of CallPoliciesA copy will be used as the call policies of the resulting method overload.keywordsThe result of a keyword-expression specifying no more arguments than thearity offn
.A copy will be used as the call policies of the resulting method overload.- If
Example
例子,其实按照下面的例子,很容易就明白了。
主要是
第一个参数,填写你在Python中使用他的名字第二个参数,写上函数指针第三个参数,填上参数名,好让boost只要你的函数有几个参数。第四个参数,是描述,可以忽略其实还有个很重要的是返回协议(return policy ),详见:http://blog.csdn.net/cedricporter/article/details/6828322#include <boost/python/def.hpp>#include <boost/python/module.hpp>#include <boost/python/args.hpp>using namespace boost::python;char const* foo(int x, int y) { return "foo"; }BOOST_PYTHON_MODULE(def_test){ def("foo", foo, args("x", "y"), "foo's docstring");}
7 March, 2003
© Copyright Dave Abrahams 2002.
- boost python def 函数导出
- Python 基础 def函数
- Python基础-def函数
- 用.DEF文件导出DLL中的函数
- 用.DEF文件导出DLL中的函数
- DEF文件中导出DLL函数
- EXE导出函数及def文件格式说明
- dllexport和.def导出函数区别
- def文件&导出函数&lib文件关联
- def文件 导出dll重载函数
- 【Python】Python_learning1:python的def函数用法
- python def 定义函数(一)
- __declspec(dllexport)的意思与DEF导出函数的区别
- __declspec(dllexport)的意思与DEF导出函数的区别
- __declspec(dllexport)的意思与DEF导出函数的区别
- __declspec(dllexport)的意思与DEF导出函数的区别
- __declspec(dllexport)的意思与DEF导出函数的区别
- __declspec(dllexport)的意思与DEF导出函数的区别
- 数据库优化方法(三)
- 系统服务调整(ServicesSet-Optimization.CMD )_一般用户
- java.lang.ClassCastException: weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB
- 随机排序
- LRU算法 java实现
- boost python def 函数导出
- Linux 基础的常用命令
- main函数的参数与返回值
- 子数组之和
- android图片浏览器(二)——实现显示图片的标题
- ruby生成C++头文件引用关系图
- 【转】风雨20年:我所积累的20条编程经验
- ACL 访问控制列表
- 系统服务调整(ServicesSet-Normal.CMD )_恢复默认