首页 文章 精选 留言 我的

精选列表

搜索[PostgreSQL扩展],共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,了解更多。 关注我们 扫描上面二维码,更多精彩内容每天推荐!

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

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部分的功能。

用户登录
用户注册