1 | // Copyright David Abrahams 2002. |
---|
2 | // Distributed under the Boost Software License, Version 1.0. (See |
---|
3 | // accompanying file LICENSE_1_0.txt or copy at |
---|
4 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
5 | #include <boost/python/module.hpp> |
---|
6 | #include "test_class.hpp" |
---|
7 | #include <boost/python/def.hpp> |
---|
8 | #include <boost/python/args.hpp> |
---|
9 | #include <boost/python/tuple.hpp> |
---|
10 | #include <boost/python/class.hpp> |
---|
11 | #include <boost/python/overloads.hpp> |
---|
12 | #include <boost/python/raw_function.hpp> |
---|
13 | #include <boost/python/return_internal_reference.hpp> |
---|
14 | |
---|
15 | using namespace boost::python; |
---|
16 | |
---|
17 | tuple f(int x = 1, double y = 4.25, char const* z = "wow") |
---|
18 | { |
---|
19 | return make_tuple(x, y, z); |
---|
20 | } |
---|
21 | |
---|
22 | BOOST_PYTHON_FUNCTION_OVERLOADS(f_overloads, f, 0, 3) |
---|
23 | |
---|
24 | typedef test_class<> Y; |
---|
25 | |
---|
26 | struct X |
---|
27 | { |
---|
28 | X(int a0 = 0, int a1 = 1) : inner0(a0), inner1(a1) {} |
---|
29 | tuple f(int x = 1, double y = 4.25, char const* z = "wow") |
---|
30 | { |
---|
31 | return make_tuple(x, y, z); |
---|
32 | } |
---|
33 | |
---|
34 | Y const& inner(bool n) const { return n ? inner1 : inner0; } |
---|
35 | |
---|
36 | Y inner0; |
---|
37 | Y inner1; |
---|
38 | }; |
---|
39 | |
---|
40 | BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_f_overloads, X::f, 0, 3) |
---|
41 | |
---|
42 | |
---|
43 | tuple raw_func(tuple args, dict kw) |
---|
44 | { |
---|
45 | return make_tuple(args, kw); |
---|
46 | } |
---|
47 | |
---|
48 | BOOST_PYTHON_MODULE(args_ext) |
---|
49 | { |
---|
50 | def("f", f, args("x", "y", "z") |
---|
51 | , "This is f's docstring" |
---|
52 | ); |
---|
53 | |
---|
54 | def("raw", raw_function(raw_func)); |
---|
55 | |
---|
56 | #if defined(BOOST_MSVC) && BOOST_MSVC <= 1200 |
---|
57 | // MSVC6 gives a fatal error LNK1179: invalid or corrupt file: |
---|
58 | // duplicate comdat error if we try to re-use the exact type of f |
---|
59 | // here, so substitute long for int. |
---|
60 | tuple (*f)(long,double,char const*) = 0; |
---|
61 | #endif |
---|
62 | def("f1", f, f_overloads("f1's docstring", args("x", "y", "z"))); |
---|
63 | def("f2", f, f_overloads(args("x", "y", "z"))); |
---|
64 | def("f3", f, f_overloads(args("x", "y", "z"), "f3's docstring")); |
---|
65 | |
---|
66 | class_<Y>("Y", init<int>(args("value"), "Y's docstring")) |
---|
67 | .def("value", &Y::value) |
---|
68 | .def("raw", raw_function(raw_func)) |
---|
69 | ; |
---|
70 | |
---|
71 | class_<X>("X", "This is X's docstring") |
---|
72 | .def(init<int, optional<int> >(args("a0", "a1"))) |
---|
73 | .def("f", &X::f |
---|
74 | , "This is X.f's docstring" |
---|
75 | , args("x", "y", "z")) |
---|
76 | |
---|
77 | // Just to prove that all the different argument combinations work |
---|
78 | .def("inner0", &X::inner, return_internal_reference<>(), args("n"), "docstring") |
---|
79 | .def("inner1", &X::inner, return_internal_reference<>(), "docstring", args("n")) |
---|
80 | |
---|
81 | .def("inner2", &X::inner, args("n"), return_internal_reference<>(), "docstring") |
---|
82 | .def("inner3", &X::inner, "docstring", return_internal_reference<>(), args("n")) |
---|
83 | |
---|
84 | .def("inner4", &X::inner, args("n"), "docstring", return_internal_reference<>()) |
---|
85 | .def("inner5", &X::inner, "docstring", args("n"), return_internal_reference<>()) |
---|
86 | |
---|
87 | .def("f1", &X::f, X_f_overloads(args("x", "y", "z"))) |
---|
88 | ; |
---|
89 | |
---|
90 | def("inner", &X::inner, "docstring", args("self", "n"), return_internal_reference<>()); |
---|
91 | } |
---|
92 | |
---|
93 | #include "module_tail.cpp" |
---|