]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/args.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / python / test / args.cpp
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 #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
18 # define make_tuple boost::python::make_tuple
19 #endif
20
21 tuple f(int x = 1, double y = 4.25, char const* z = "wow")
22 {
23 return make_tuple(x, y, z);
24 }
25
26 BOOST_PYTHON_FUNCTION_OVERLOADS(f_overloads, f, 0, 3)
27
28 typedef test_class<> Y;
29
30 struct X
31 {
32 X(int a0 = 0, int a1 = 1) : inner0(a0), inner1(a1) {}
33 tuple f(int x = 1, double y = 4.25, char const* z = "wow")
34 {
35 return make_tuple(x, y, z);
36 }
37
38 Y const& inner(bool n) const { return n ? inner1 : inner0; }
39
40 Y inner0;
41 Y inner1;
42 };
43
44 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_f_overloads, X::f, 0, 3)
45
46
47 tuple raw_func(tuple args, dict kw)
48 {
49 return make_tuple(args, kw);
50 }
51
52 BOOST_PYTHON_MODULE(args_ext)
53 {
54 def("f", f, (arg("x")=1, arg("y")=4.25, arg("z")="wow")
55 , "This is f's docstring"
56 );
57
58 def("raw", raw_function(raw_func));
59
60 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1200
61 // MSVC6 gives a fatal error LNK1179: invalid or corrupt file:
62 // duplicate comdat error if we try to re-use the exact type of f
63 // here, so substitute long for int.
64 tuple (*f)(long,double,char const*) = 0;
65 #endif
66 def("f1", f, f_overloads("f1's docstring", args("x", "y", "z")));
67 def("f2", f, f_overloads(args("x", "y", "z")));
68 def("f3", f, f_overloads(args("x", "y", "z"), "f3's docstring"));
69
70 class_<Y>("Y", init<int>(args("value"), "Y's docstring"))
71 .def("value", &Y::value)
72 .def("raw", raw_function(raw_func))
73 ;
74
75 class_<X>("X", "This is X's docstring", init<>(args("self")))
76 .def(init<int, optional<int> >(args("self", "a0", "a1")))
77 .def("f", &X::f
78 , "This is X.f's docstring"
79 , args("self","x", "y", "z"))
80
81 // Just to prove that all the different argument combinations work
82 .def("inner0", &X::inner, return_internal_reference<>(), args("self", "n"), "docstring")
83 .def("inner1", &X::inner, return_internal_reference<>(), "docstring", args("self", "n"))
84
85 .def("inner2", &X::inner, args("self", "n"), return_internal_reference<>(), "docstring")
86 .def("inner3", &X::inner, "docstring", return_internal_reference<>(), args("self", "n"))
87
88 .def("inner4", &X::inner, args("self", "n"), "docstring", return_internal_reference<>())
89 .def("inner5", &X::inner, "docstring", args("self", "n"), return_internal_reference<>())
90
91 .def("f1", &X::f, X_f_overloads(args("self", "x", "y", "z")))
92 .def("f2", &X::f, X_f_overloads(args("self", "x", "y", "z"), "f2's docstring"))
93 .def("f2", &X::f, X_f_overloads(args("x", "y", "z"), "f2's docstring"))
94 ;
95
96 def("inner", &X::inner, "docstring", args("self", "n"), return_internal_reference<>());
97 }
98
99 #include "module_tail.cpp"