首页 文章 精选 留言 我的

精选列表

搜索[php扩展],共10000篇文章
优秀的个人博客,低调大师

Python的C/C++扩展——boost_python编写Python模块

前面讲述了Python使用ctypes直接调用动态库和使用Python的C语言API封装C函数,本文概述方便封装C++类给Python使用的boost_python库。 安装boost python库: sudo aptitude install libboost-python-dev 示例 下面代码简单实现了一个普通函数maxab()和一个Student类: #include <iostream> #include <string> int maxab(int a, int b) { return a>b?a:b; } class Student { private: int age; std::string name; public: Student() {} Student(std::string const& _name, int _age) { name=_name; age=_age; } static void myrole() { std::cout << "I'm a student!" << std::endl; } void whoami() { std::cout << "I am " << name << std::endl; } bool operator==(Student const& s) const { return age == s.age; } bool operator!=(Student const& s) const { return age != s.age; } }; 使用boost.python库封装也很简单,如下代码所示: #include <Python.h> #include <boost/python.hpp> #include <boost/python/suite/indexing/vector_indexing_suite.hpp> #include <vector> #include "student.h" using namespace boost::python; BOOST_PYTHON_MODULE(student) { // This will enable user-defined docstrings and python signatures, // while disabling the C++ signatures scope().attr("__version__") = "1.0.0"; scope().attr("__doc__") = "a demo module to use boost_python."; docstring_options local_docstring_options(true, false, false); def( "maxab", &maxab, "return max of two numbers.\n" ); class_<Student>("Student", "a class of student") .def(init<>()) .def(init<std::string, int>()) // methods for Chinese word segmentation .def( "whoami", &Student::whoami, "method's doc string..." ) .def( "myrole", &Student::myrole, "method's doc string..." ) .staticmethod("myrole"); // 封装STL class_<std::vector<Student> >("StudentVec") .def(vector_indexing_suite<std::vector<Student> >()) ; } 上述代码还是include了Python.h文件,如果不include的话,会报错误: wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory 编译 编译以上代码有两种方式,一种是在命令行下面直接使用g++编译: g++ -I/usr/include/python2.7 -fPIC wrap_student.cpp -lboost_python -shared -o student.so 首先指定Python.h的路径,如果是Python 3的话就要修改为相应的路径,编译wrap_student.cpp要指定-fPIC参数,链接(-lboost_python)生成动态库(-shared)。 生成的student.so动态库就可以被python直接import使用了 In [1]: import student In [2]: student.maxab(2, 5)Out[2]: 5 In [3]: s = student.Student('Tom', 12) In [4]: s.whoami()I am Tom In [5]: s.myrole()I'm a student!另外一直方法是用python的setuptools编写setup.py脚本: #!/usr/bin/env python from setuptools import setup, Extension setup(name="student", ext_modules=[ Extension("student", ["wrap_student.cpp"], libraries = ["boost_python"]) ]) 然后执行命令编译: python setup.py build or sudo python setup.py install 文章版权归属于 猿人学

优秀的个人博客,低调大师

mica 中 test 扩展 mica-boot-test 单元测试插件

介绍 由于在mica-launcher组件中我们埋入了一些配置,该组件为了方便单元测试。 依赖坐标 Maven <dependency> <groupId>net.dreamlu</groupId> <artifactId>mica-boot-test</artifactId> <scope>test</scope> </dependency> Gradle testCompile "net.dreamlu:mica-boot-test" 使用方式 示例代码一 采用@RunWith(MicaSpringRunner.class)。 @SpringBootTest @MicaBootTest("appName") @RunWith(MicaSpringRunner.class) public class MicaExampleApplicationTests { @Test public void contextLoads() { } } 示例代码二 继承MicaBaseTest。 @SpringBootTest @MicaBootTest("appName") public class ApplicationTests extends MicaBaseTest { @Test public void contextLoads() { } } 说明:上面2种方式均可,@MicaBootTest注解属性有:服务名、profile和enableLoader。 开源推荐 Spring boot 微服务高效开发mica工具集:https://gitee.com/596392912/mica Avue一款基于vue可配置化的神奇框架:https://gitee.com/smallweigit/avue pig宇宙最强微服务(架构师必备):https://gitee.com/log4j/pig SpringBlade完整的线上解决方案(企业开发必备):https://gitee.com/smallc/SpringBlade IJPay 支付SDK让支付触手可及:https://gitee.com/javen205/IJPay 加入【如梦技术】Spring QQ群:479710041,了解更多。 关注我们 扫描上面二维码,更多精彩内容每天推荐!

优秀的个人博客,低调大师

Spring Cloud Gateway 数据库存储路由信息的扩展方案

动态路由背景 ​ 无论你在使用Zuul还是Spring Cloud Gateway 的时候,官方文档提供的方案总是基于配置文件配置的方式 例如: # zuul 的配置形式 routes: pig-auth: path: /auth/** serviceId: pig-auth stripPrefix: true # gateway 的配置形式 routes: - id: pigx-auth uri: lb://pigx-auth predicates: - Path=/auth/** filters: - ValidateCodeGatewayFilter 配置更改需要重启服务,不能满足实际生产过程中的动态刷新、实时变更的业

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册