Directory: | ./ |
---|---|
File: | doc/python/doxygen-boost.hh |
Date: | 2025-04-01 09:23:31 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 18 | 18 | 100.0% |
Branches: | 5 | 9 | 55.6% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | #ifndef DOXYGEN_BOOST_DOC_HH | ||
2 | #define DOXYGEN_BOOST_DOC_HH | ||
3 | |||
4 | #ifndef DOXYGEN_DOC_HH | ||
5 | #error "You should have included doxygen.hh first." | ||
6 | #endif // DOXYGEN_DOC_HH | ||
7 | |||
8 | #include <boost/python.hpp> | ||
9 | |||
10 | namespace doxygen { | ||
11 | |||
12 | namespace visitor { | ||
13 | |||
14 | template <typename function_type, | ||
15 | typename policy_type = boost::python::default_call_policies> | ||
16 | struct member_func_impl : boost::python::def_visitor< | ||
17 | member_func_impl<function_type, policy_type> > { | ||
18 | 1065 | member_func_impl(const char* n, const function_type& f) | |
19 | 1065 | : name(n), function(f) {} | |
20 | |||
21 | 20 | member_func_impl(const char* n, const function_type& f, policy_type p) | |
22 | 20 | : name(n), function(f), policy(p) {} | |
23 | |||
24 | template <class classT> | ||
25 | 1085 | inline void visit(classT& c) const { | |
26 | // Either a boost::python::keyword<N> object or a void_ object | ||
27 |
1/2✓ Branch 2 taken 545 times.
✗ Branch 3 not taken.
|
1085 | call(c, member_func_args(function)); |
28 | 1085 | } | |
29 | |||
30 | template <class classT, std::size_t nkeywords> | ||
31 | inline void call( | ||
32 | classT& c, const boost::python::detail::keywords<nkeywords>& args) const { | ||
33 | c.def(name, function, member_func_doc(function), args, policy); | ||
34 | } | ||
35 | |||
36 | template <class classT> | ||
37 | 1085 | inline void call(classT& c, const void_&) const { | |
38 |
1/2✓ Branch 2 taken 545 times.
✗ Branch 3 not taken.
|
1085 | c.def(name, function, member_func_doc(function), policy); |
39 | 1085 | } | |
40 | |||
41 | const char* name; | ||
42 | const function_type& function; | ||
43 | policy_type policy; | ||
44 | }; | ||
45 | |||
46 | // TODO surprisingly, this does not work when defined here but it works when | ||
47 | // defined after the generated files are included. | ||
48 | template <typename function_type> | ||
49 | 1065 | inline member_func_impl<function_type> member_func( | |
50 | const char* name, const function_type& function) { | ||
51 | 1065 | return member_func_impl<function_type>(name, function); | |
52 | } | ||
53 | |||
54 | template <typename function_type, typename policy_type> | ||
55 | 20 | inline member_func_impl<function_type, policy_type> member_func( | |
56 | const char* name, const function_type& function, | ||
57 | const policy_type& policy) { | ||
58 | 20 | return member_func_impl<function_type, policy_type>(name, function, policy); | |
59 | } | ||
60 | |||
61 | #define DOXYGEN_DOC_DECLARE_INIT_VISITOR(z, nargs, unused) \ | ||
62 | template <typename Class BOOST_PP_COMMA_IF(nargs) \ | ||
63 | BOOST_PP_ENUM_PARAMS(nargs, class Arg)> \ | ||
64 | struct init_##nargs##_impl \ | ||
65 | : boost::python::def_visitor< \ | ||
66 | init_##nargs##_impl<Class BOOST_PP_COMMA_IF(nargs) \ | ||
67 | BOOST_PP_ENUM_PARAMS(nargs, Arg)> > { \ | ||
68 | typedef constructor_##nargs##_impl<Class BOOST_PP_COMMA_IF(nargs) \ | ||
69 | BOOST_PP_ENUM_PARAMS(nargs, Arg)> \ | ||
70 | constructor; \ | ||
71 | typedef boost::python::init<BOOST_PP_ENUM_PARAMS(nargs, Arg)> init_base; \ | ||
72 | \ | ||
73 | template <class classT> \ | ||
74 | inline void visit(classT& c) const { \ | ||
75 | call(c, constructor::args()); \ | ||
76 | } \ | ||
77 | \ | ||
78 | template <class classT> \ | ||
79 | void call(classT& c, \ | ||
80 | const boost::python::detail::keywords<nargs + 1>& args) const { \ | ||
81 | c.def(init_base(constructor::doc(), args)); \ | ||
82 | } \ | ||
83 | \ | ||
84 | template <class classT> \ | ||
85 | void call(classT& c, const void_&) const { \ | ||
86 | c.def(init_base(constructor::doc())); \ | ||
87 | } \ | ||
88 | }; \ | ||
89 | \ | ||
90 | template <typename Class BOOST_PP_COMMA_IF(nargs) \ | ||
91 | BOOST_PP_ENUM_PARAMS(nargs, class Arg)> \ | ||
92 | inline init_##nargs##_impl<Class BOOST_PP_COMMA_IF(nargs) \ | ||
93 | BOOST_PP_ENUM_PARAMS(nargs, Arg)> \ | ||
94 | init() { \ | ||
95 | return init_##nargs##_impl<Class BOOST_PP_COMMA_IF(nargs) \ | ||
96 | BOOST_PP_ENUM_PARAMS(nargs, Arg)>(); \ | ||
97 | } | ||
98 | |||
99 |
2/3✓ Branch 2 taken 405 times.
✓ Branch 3 taken 405 times.
✗ Branch 4 not taken.
|
2430 | BOOST_PP_REPEAT(DOXYGEN_DOC_MAX_NUMBER_OF_ARGUMENTS_IN_CONSTRUCTOR, |
100 | DOXYGEN_DOC_DECLARE_INIT_VISITOR, ~) | ||
101 | #undef DOXYGEN_DOC_DECLARE_INIT_VISITOR | ||
102 | |||
103 | } // namespace visitor | ||
104 | |||
105 | template <typename Func> | ||
106 | 185 | void def(const char* name, Func func) { | |
107 |
1/2✓ Branch 2 taken 95 times.
✗ Branch 3 not taken.
|
185 | boost::python::def(name, func, member_func_doc(func)); |
108 | 185 | } | |
109 | |||
110 | } // namespace doxygen | ||
111 | |||
112 | #endif // DOXYGEN_BOOST_DOC_HH | ||
113 |