c++ python交互之boost.python 简集之Vector(map)混合使用
来源:互联网 发布:南京大学网络教育 编辑:程序博客网 时间:2024/06/03 18:30
C++代码如下:src.cpp
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef map<string,int> simap;
typedef vector<simap> mvector;
simap A()
{
simap m;
m["aaa"] = 1;
m["bbb"] = 2;
m["ccc"] = 3;
m["ddd"] = 4;
m["eee"] = 5;
m["fff"] = 6;
return m;
}
mvector B(simap s)
{
mvector m;
m.push_back(s);
return m;
}
int C(mvector m)
{
int q = m[0]["aaa"];
return q;
}
转换代码如下:
#src4py.cpp
#include <boost/python.hpp>
#include <boost/python/suite/indexing/map_indexing_suite.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include "src.cpp"
using namespace boost::python;
BOOST_PYTHON_MODULE(test)
{
class_<simap>("pySImap")
.def( map_indexing_suite<simap>() )
;
class_<mvector>("mvector")
.def( vector_indexing_suite< mvector > () )
;
def("a",A);
def("b",B);
def("c",C);
}
调用代码如下:
#test.py
import test
mapcontainer = test.pySImap()
mapcontainer = test.a()
d = test.b(mapcontainer)
q = test.c(d)
print d[0]['aaa']
print q
- c++ python交互之boost.python 简集之Vector(map)混合使用
- c++ python交互之boost.python 简集之 vector处理
- c++ python交互之boost.python 简集之Map处理
- c++ python交互之boost.python 简集之普通函数
- c++ python交互之boost.python 简集之序列化(pickle)
- c++ python交互之boost.python 简集之类(class , struct)
- c++ python交互之boost.python 简集之类成员变量设置
- C++ python 交互之 python.dict to c++ map
- C++、python混合编程之加载模块
- 使用Boost.Python构建混合系统
- 使用Boost.Python构建混合系统
- 使用boost.python进行混合开发
- 利用Boost.Python实现Python C/C++混合编程
- python 之 map/reduce/filter使用体会
- python之map映射
- python 之map get()
- python之map/reduce
- python学习之Map
- B2C电子商务网站的突围——再议什么是B2C网站
- poj 3264
- 禁止ie弹出alert窗口
- 禁止ie弹出alert窗口
- 学习计划
- c++ python交互之boost.python 简集之Vector(map)混合使用
- vim+cscope+ctags浏览源码
- DevExpress.XtraGrid.GridControl控件获取选中行某列的值
- filelist
- 命令行编译WPF--VS2010
- sicily 1006 Team Rankings
- 设置classpath的五种方法
- SQLServer2008 安装过程中遇到“性能计数器注册表配置单元一致性”检查失败(我遇到的问题)
- [ZZ]2011程序员薪资调查报告全文发布