eigenpy 3.12.0
Bindings between Numpy and Eigen using Boost.Python
Loading...
Searching...
No Matches
registration_class.hpp
1/*
2 * Copyright 2023, INRIA
3 */
4
5#ifndef __eigenpy_registration_class_hpp__
6#define __eigenpy_registration_class_hpp__
7
8#include <boost/python/class.hpp>
9
10#include "eigenpy/fwd.hpp"
11
12namespace eigenpy {
13
18template <class W>
20 public:
21 using self = registration_class;
22
24 registration_class(bp::object object) : m_object(object) {}
25
27 template <class Visitor>
28 self& def(Visitor const& visitor) {
29 visitor.visit(*this);
30 return *this;
31 }
32
33 template <class DerivedVisitor>
34 self& def(bp::def_visitor<DerivedVisitor> const& visitor) {
35 static_cast<DerivedVisitor const&>(visitor).visit(*this);
36 return *this;
37 }
38
40 template <class F>
41 self& def(char const* name, F f) {
42 def_impl(bp::detail::unwrap_wrapper((W*)0), name, f,
43 bp::detail::def_helper<char const*>(0), &f);
44 return *this;
45 }
46
48 template <class A1, class A2>
49 self& def(char const* name, A1 a1, A2 const& a2) {
50 def_maybe_overloads(name, a1, a2, &a2);
51 return *this;
52 }
53
56 template <class Fn, class A1, class A2>
57 self& def(char const* name, Fn fn, A1 const& a1, A2 const& a2) {
58 def_impl(bp::detail::unwrap_wrapper((W*)0), name, fn,
59 bp::detail::def_helper<A1, A2>(a1, a2), &fn);
60
61 return *this;
62 }
63
66 template <class Fn, class A1, class A2, class A3>
67 self& def(char const* name, Fn fn, A1 const& a1, A2 const& a2, A3 const& a3) {
68 def_impl(bp::detail::unwrap_wrapper((W*)0), name, fn,
69 bp::detail::def_helper<A1, A2, A3>(a1, a2, a3), &fn);
70
71 return *this;
72 }
73
74 private:
77 template <class T, class Fn, class Helper>
78 inline void def_impl(T*, char const* name, Fn fn, Helper const& helper, ...) {
79 bp::objects::add_to_namespace(
80 m_object, name,
81 make_function(fn, helper.policies(), helper.keywords(),
82 bp::detail::get_signature(fn, (T*)0)),
83 helper.doc());
84
85 def_default(name, fn, helper,
86 boost::mpl::bool_<Helper::has_default_implementation>());
87 }
88
91 template <class Fn, class Helper>
92 inline void def_default(char const* name, Fn, Helper const& helper,
93 boost::mpl::bool_<true>) {
94 bp::detail::error::virtual_function_default<
95 W, Fn>::must_be_derived_class_member(helper.default_implementation());
96
97 bp::objects::add_to_namespace(
98 m_object, name,
99 make_function(helper.default_implementation(), helper.policies(),
100 helper.keywords()));
101 }
102
105 template <class Fn, class Helper>
106 inline void def_default(char const*, Fn, Helper const&,
107 boost::mpl::bool_<false>) {}
108
111 template <class OverloadsT, class SigT>
112 void def_maybe_overloads(char const* name, SigT sig,
113 OverloadsT const& overloads,
114 bp::detail::overloads_base const*)
115
116 {
117 bp::detail::define_with_defaults(name, overloads, *this,
118 bp::detail::get_signature(sig));
119 }
120
123 template <class Fn, class A1>
124 void def_maybe_overloads(char const* name, Fn fn, A1 const& a1, ...) {
125 def_impl(bp::detail::unwrap_wrapper((W*)0), name, fn,
126 bp::detail::def_helper<A1>(a1), &fn);
127 }
128
129 private:
130 bp::object m_object;
131};
132
133} // namespace eigenpy
134
135#endif // ifndef __eigenpy_registration_class_hpp__
self & def(char const *name, Fn fn, A1 const &a1, A2 const &a2)
self & def(char const *name, A1 a1, A2 const &a2)
self & def(char const *name, Fn fn, A1 const &a1, A2 const &a2, A3 const &a3)
self & def(Visitor const &visitor)
registration_class(bp::object object)
object Hold the namespace of the class that will be modified
self & def(char const *name, F f)