-
Notifications
You must be signed in to change notification settings - Fork 2
/
python_epilogue.h
71 lines (59 loc) · 2.05 KB
/
python_epilogue.h
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
68
69
70
71
#ifndef CLASSDESC_PYTHONOBJECT_EPILOGUE_H
#define CLASSDESC_PYTHONOBJECT_EPILOGUE_H
namespace classdesc
{
template <class Derived, class Base>
typename enable_if<And<Not<is_same<Base,Derived>>,is_base_of<Base, Derived>>, void>::T
registerBase()
{
// NB this is an undocumented function
boost::python::objects::register_base_of<Derived>()((Base*)0);
}
template <class Derived, class Base>
typename enable_if<Or<is_same<Base,Derived>,Not<is_base_of<Base, Derived>>>, void>::T
registerBase()
{
}
template <class T, class Base>
typename enable_if<ClassdescEnabledPythonType<Base>,void>::T
python(python_t& p, const string& d)
{
classdesc_access::access_python<Base>().template type<T>(p,d);
if (is_same<T,Base>::value)
p.getClass<T>().completed=true;
else
// register base class to enable correct virtual function handling
registerBase<T,Base>();
}
template <class T, int rank>
void pythonDetail::ArrayGetRegisterClass<T,rank>::registerClass(python_t& p)
{
auto& c=p.getClass<ArrayGet<T,rank> >();
if (!c.completed)
{
c.def("__len__",&arrayMemLen<ArrayGet<T,rank>, T>).
def("__getitem__",&ArrayGet<T,rank>::get);
if (rank==1)
c.def("__setitem__",&ArrayGet<T,rank>::set);
}
ArrayGetRegisterClass<typename std::remove_extent<T>::type,rank-1>::registerClass(p);
}
template <class E>
void python_t::defineEnum() {
ExtractClassNameAndSetScope scope(*this,typeName<E>());
boost::python::enum_<E> e(scope.className.c_str());
for (auto& i: enum_keysData<E>::keysData)
e.value(i.name,E(i.value));
e.export_values();
}
template <class T> struct PythonTypableMember: public And<
Not<PythonExcludeType<typename remove_pointer<typename remove_reference<T>::type>::type>>,
is_complete<T>
> {};
}
namespace classdesc_access
{
// string handling is already built into boost.python
template <class T> struct access_python<std::basic_string<T>,void>: public classdesc::NullDescriptor<classdesc::python_t> {};
}
#endif