Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/args.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 3.1 KB
Line 
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
15using namespace boost::python;
16
17#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
18# define make_tuple boost::python::make_tuple
19#endif
20
21tuple f(int x = 1, double y = 4.25, char const* z = "wow")
22{
23    return make_tuple(x, y, z);
24}
25
26BOOST_PYTHON_FUNCTION_OVERLOADS(f_overloads, f, 0, 3)
27   
28typedef test_class<> Y;
29
30struct 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
44BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_f_overloads, X::f, 0, 3)
45
46
47tuple raw_func(tuple args, dict kw)
48{
49    return make_tuple(args, kw);
50}
51
52BOOST_PYTHON_MODULE(args_ext)
53{
54    def("f", f, args("x", "y", "z")
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")
76        .def(init<int, optional<int> >(args("a0", "a1")))
77        .def("f", &X::f
78             , "This is X.f's docstring"
79             , args("x", "y", "z"))
80
81        // Just to prove that all the different argument combinations work
82        .def("inner0", &X::inner, return_internal_reference<>(), args("n"), "docstring")
83        .def("inner1", &X::inner, return_internal_reference<>(), "docstring", args("n"))
84
85        .def("inner2", &X::inner, args("n"), return_internal_reference<>(), "docstring")
86        .def("inner3", &X::inner, "docstring", return_internal_reference<>(), args("n"))
87
88        .def("inner4", &X::inner, args("n"), "docstring", return_internal_reference<>())
89        .def("inner5", &X::inner, "docstring", args("n"), return_internal_reference<>())
90
91        .def("f1", &X::f, X_f_overloads(args("x", "y", "z")))
92        .def("f2", &X::f, X_f_overloads(args("x", "y", "z"), "f2's docstring"))
93        ;
94
95    def("inner", &X::inner, "docstring", args("self", "n"), return_internal_reference<>());
96}
97
98#include "module_tail.cpp"
Note: See TracBrowser for help on using the repository browser.