36#ifndef NEKTAR_LIBRARY_LIBUTILITIES_PYTHON_NEKPYCONFIG_HPP
37#define NEKTAR_LIBRARY_LIBUTILITIES_PYTHON_NEKPYCONFIG_HPP
39#include <boost/version.hpp>
46#if BOOST_VERSION < 106300
54#include <boost/python.hpp>
55#include <boost/python/numpy.hpp>
58namespace np = boost::python::numpy;
62#include <boost/numpy.hpp>
63#include <boost/python.hpp>
66namespace np = boost::numpy;
70#define SIZENAME(s) SIZE_##s
71#define NEKPY_WRAP_ENUM(ENUMNAME, MAPNAME) \
73 py::enum_<ENUMNAME> tmp(#ENUMNAME); \
74 for (int a = 0; a < (int)SIZENAME(ENUMNAME); ++a) \
76 tmp.value(MAPNAME[a], (ENUMNAME)a); \
78 tmp.export_values(); \
80#define NEKPY_WRAP_ENUM_STRING(ENUMNAME, MAPNAME) \
82 py::enum_<ENUMNAME> tmp(#ENUMNAME); \
83 for (int a = 0; a < (int)SIZENAME(ENUMNAME); ++a) \
85 tmp.value(MAPNAME[a].c_str(), (ENUMNAME)a); \
87 tmp.export_values(); \
89#if PY_MAJOR_VERSION == 2
90#define NEKPY_WRAP_ENUM_STRING_DOCS(ENUMNAME, MAPNAME, DOCSTRING) \
92 py::enum_<ENUMNAME> tmp(#ENUMNAME); \
93 for (int a = 0; a < (int)SIZENAME(ENUMNAME); ++a) \
95 tmp.value(MAPNAME[a].c_str(), (ENUMNAME)a); \
97 tmp.export_values(); \
98 PyTypeObject *pto = reinterpret_cast<PyTypeObject *>(tmp.ptr()); \
99 PyDict_SetItemString(pto->tp_dict, "__doc__", \
100 PyString_FromString(DOCSTRING)); \
103#define NEKPY_WRAP_ENUM_STRING_DOCS(ENUMNAME, MAPNAME, DOCSTRING) \
105 py::enum_<ENUMNAME> tmp(#ENUMNAME); \
106 for (int a = 0; a < (int)SIZENAME(ENUMNAME); ++a) \
108 tmp.value(MAPNAME[a].c_str(), (ENUMNAME)a); \
110 tmp.export_values(); \
111 PyTypeObject *pto = reinterpret_cast<PyTypeObject *>(tmp.ptr()); \
112 PyDict_SetItemString(pto->tp_dict, "__doc__", \
113 PyUnicode_FromString(DOCSTRING)); \
117#if BOOST_VERSION >= 106300
141template <
class T>
struct shared_ptr_from_python<T,
std::shared_ptr>
146 converter::registry::insert(
147 &convertible, &construct, type_id<std::shared_ptr<T>>()
148#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
150 &converter::expected_from_python_type_direct<T>::get_pytype
156 static void *convertible(PyObject *
p)
162 return converter::get_lvalue_from_python(
p, registered<T>::converters);
165 static void construct(PyObject *source,
166 rvalue_from_python_stage1_data *data)
168 void *
const storage =
169 ((converter::rvalue_from_python_storage<std::shared_ptr<T>> *)data)
171 if (data->convertible == source)
173 new (storage) std::shared_ptr<T>();
177 reference_arg_from_python<std::shared_ptr<T> &> sp(source);
178 if (sp.convertible())
180 new (storage) std::shared_ptr<T>(sp());
184 std::shared_ptr<void> hold_convertible_ref_count(
186 shared_ptr_deleter(handle<>(borrowed(source))));
188 std::shared_ptr<T>(hold_convertible_ref_count,
189 static_cast<T *
>(data->convertible));
192 data->convertible = storage;
222 for (i = 0; i <
m_argc; ++i)
224 std::string tmp = py::extract<std::string>(py_argv[i]);
225 bufSize += tmp.size() + 1;
228 m_buf.resize(bufSize);
231 std::string tmp = py::extract<std::string>(py_argv[i]);
233 p[tmp.size()] =
'\0';
288 py::objects::class_value_wrapper<
290 py::objects::make_ptr_instance<
291 T, py::objects::pointer_holder<std::shared_ptr<T>, T>>>();
Helper structure to construct C++ command line argc and argv variables from a Python list.
int GetArgc()
Returns the constructed argc.
int m_argc
Number of arguments argc.
std::vector< char > m_buf
Buffer for storage of the argument strings.
char ** m_argv
Pointers for strings argv.
~CppCommandLine()
Destructor.
CppCommandLine(py::list &py_argv)
Constructor.
char ** GetArgv()
Returns the constructed argv.
A helper class that for factory-based classes allows std::shared_ptr<T> as something that boost::pyth...