forked from irods/irods_rule_engine_plugin_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw_constructor.hpp
67 lines (56 loc) · 1.57 KB
/
raw_constructor.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef RAW_CONSTRUCTOR_HPP
#define RAW_CONSTRUCTOR_HPP
#include <memory>
#include <functional>
#include <initializer_list>
#include <patchlevel.h>
#include <boost/version.hpp>
#pragma GCC diagnostic push
#if PY_VERSION_HEX < 0x030400A2
#pragma GCC diagnostic ignored "-Wregister"
#endif
#if PY_VERSION_HEX >= 0x03090000 && BOOST_VERSION < 107500
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#include "boost/python.hpp"
#include "boost/python/detail/api_placeholder.hpp"
#pragma GCC diagnostic pop
namespace boost { namespace python {
namespace detail {
template <class F>
struct raw_constructor_dispatcher
{
raw_constructor_dispatcher(F f)
: f(make_constructor(f)) {}
PyObject* operator()(PyObject* args, PyObject* keywords)
{
borrowed_reference_t* ra = borrowed_reference(args);
object a(ra);
return incref(
object(
f(
object(a[0])
, object(a.slice(1, len(a)))
, keywords ? dict(borrowed_reference(keywords)) : dict()
)
).ptr()
);
}
private:
object f;
};
} // namespace detail
template <class F>
object raw_constructor(F f, std::size_t min_args = 0)
{
return detail::make_raw_function(
objects::py_function(
detail::raw_constructor_dispatcher<F>(f)
, mpl::vector2<void, object>()
, min_args+1
, (std::numeric_limits<unsigned>::max)()
)
);
}
}} // namespace boost::python
#endif //RAW_CONSTRUCTOR_HPP