Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/keywords.cpp @ 45

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

updated boost from 1_33_1 to 1_34_1

File size: 2.2 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.hpp>
6#include <string>
7
8struct Foo
9{
10    Foo(
11        int a = 0
12        , double b = 0
13        , const std::string &n = std::string()
14        ) : 
15    a_(a)
16        , b_(b)
17        , n_(n)
18    {}
19
20    void set(int a=0, double b=0, const std::string &n=std::string()) 
21    {
22        a_ = a; 
23        b_ = b;
24        n_ = n;
25    }
26
27    int geta() const { return a_; }
28
29    double getb() const { return b_; }
30
31    std::string getn() const { return n_; }
32
33private:
34    int a_;
35    double b_;
36    std::string n_;
37};
38
39struct Bar
40{
41    Bar(
42        int a = 0
43        , double b = 0
44        , const std::string &n = std::string()
45        ) : 
46    a_(a)
47        , b_(b)
48        , n_(n)
49    {}
50
51    void set(int a=0, double b=0, const std::string &n=std::string()) 
52    {
53        a_ = a; 
54        b_ = b;
55        n_ = n;
56    }
57
58    void seta(int a)
59    {
60        a_ = a; 
61    }
62
63    int geta() const { return a_; }
64
65    double getb() const { return b_; }
66
67    std::string getn() const { return n_; }
68
69private:
70    int a_;
71    double b_;
72    std::string n_;
73};
74
75BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(bar_set, Bar::set, 0,3)
76
77using namespace boost::python;
78BOOST_PYTHON_MODULE(keywords)
79{
80#if BOOST_WORKAROUND(__GNUC__, == 2)
81    using boost::python::arg;
82#endif
83   
84    class_<Foo>(
85        "Foo"
86      , init<int, double, const std::string&>(
87          (  arg("a") = 0
88             , arg("b") = 0.0
89             , arg("n") = std::string()
90          )
91      ))
92
93      .def("set", &Foo::set, (arg("a") = 0, arg("b") = 0.0, arg("n") = std::string()) )
94       
95      .def("set2", &Foo::set, (arg("a"), "b", "n") )
96       
97      .def("a", &Foo::geta)
98      .def("b", &Foo::getb)
99      .def("n", &Foo::getn)
100      ;
101
102   class_<Bar>("Bar"
103               , init<optional<int, double, const std::string &> >()
104   )
105      .def("set", &Bar::set, bar_set())
106      .def("seta", &Bar::seta, arg("a"))
107       
108      .def("a", &Bar::geta)
109      .def("b", &Bar::getb)
110      .def("n", &Bar::getn)
111      ;
112
113}
114
115
116
117#include "module_tail.cpp"
Note: See TracBrowser for help on using the repository browser.