First commit
This commit is contained in:
10
CMakeLists.txt
Normal file
10
CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.27)
|
||||
project(bptest)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
|
||||
find_package(Boost REQUIRED python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR} REQUIRED)
|
||||
|
||||
add_library(bptest SHARED main.cpp)
|
||||
target_link_libraries(bptest PUBLIC Boost::python Python3::Python)
|
||||
# target_include_directories(bptest PUBLIC ${Python3_INCLUDE_DIRS})
|
||||
50
main.cpp
Normal file
50
main.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
class SomeClass {
|
||||
public:
|
||||
explicit SomeClass(std::string n) : name(std::move(n)), mNumber(0.0) {}
|
||||
|
||||
std::string name;
|
||||
|
||||
double getNumber() const;
|
||||
|
||||
void setNumber(double n) {
|
||||
if (n > 3.141592654)
|
||||
n = -1;
|
||||
mNumber = n;
|
||||
}
|
||||
|
||||
std::string testTime(int secs) {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(secs));
|
||||
return "asdzxc";
|
||||
}
|
||||
|
||||
private:
|
||||
double mNumber;
|
||||
};
|
||||
|
||||
double SomeClass::getNumber() const { return mNumber; }
|
||||
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <utility>
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
BOOST_PYTHON_MODULE (libbptest) {
|
||||
class_<SomeClass>("SomeClass", init<std::string>())
|
||||
.def_readwrite("name", &SomeClass::name)
|
||||
.add_property("number", &SomeClass::getNumber, &SomeClass::setNumber)
|
||||
.def("test_time", &SomeClass::testTime)
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello, World!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user