MCPcopy Create free account
hub / github.com/LuxCoreRender/LuxCore / TransferToPython

Function TransferToPython

include/luxcore/pyluxcore/pyluxcoreutils.h:32–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30// From https://stackoverflow.com/questions/35957073/boost-python-returning-tuple-containing-custom-types
31
32template <typename T> boost::python::object TransferToPython(T *t) {
33 // Transfer ownership to a smart pointer, allowing for proper cleanup
34 // incase Boost.Python throws.
35 std::unique_ptr<T> ptr(t);
36
37 // Use the manage_new_object generator to transfer ownership to Python.
38 typename boost::python::manage_new_object::apply<T *>::type converter;
39
40 // Transfer ownership to the Python handler and release ownership
41 // from C++.
42 boost::python::handle<> handle(converter(*ptr));
43 ptr.release();
44
45 return boost::python::object(handle);
46}
47
48template<typename T> void GetArray(const boost::python::object &obj, std::vector<T> &a,
49 const u_int width = 1, const u_int stride = 0) {

Callers 1

Calls 1

releaseMethod · 0.45

Tested by

no test coverage detected