]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/data_members.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/class.hpp>
6 #include <boost/python/module.hpp>
7 #include <boost/python/return_value_policy.hpp>
8 #include <boost/python/return_by_value.hpp>
9 #include "test_class.hpp"
11 #if defined(_AIX) && defined(__EDG_VERSION__) && __EDG_VERSION__ < 245
12 # include <iostream> // works around a KCC intermediate code generation bug
16 using namespace boost::python
;
18 typedef test_class
<> X
;
20 struct Y
: test_class
<1>
22 Y(int v
) : test_class
<1>(v
) {}
23 Y
& operator=(Y
const& rhs
) { x
= rhs
.x
; return *this; }
27 double get_fair_value(X
const& x
) { return x
.value(); }
32 VarBase(std::string name_
) : name(name_
) {}
34 std::string
const name
;
35 std::string
get_name1() const { return name
; }
41 Var(std::string name_
) : VarBase(name_
), value(), name2(name
.c_str()), y(6) {}
42 std::string
const& get_name2() const { return name
; }
54 // Compilability regression tests
55 namespace boost_python_test
59 trivial() : value(123) {}
65 static const Color3 black
;
68 const Color3
Color3::black
69 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
74 void compilability_test()
76 class_
<trivial
>("trivial")
77 .add_property("property", make_getter(&trivial::value
, return_value_policy
<return_by_value
>()))
78 .def_readonly("readonly", &trivial::value
)
81 class_
< Color3
>("Color3", init
< const Color3
& >())
82 .def_readonly("BLACK", &Color3::black
) // line 17
87 BOOST_PYTHON_MODULE(data_members_ext
)
89 using namespace boost_python_test
;
90 class_
<X
>("X", init
<int>())
91 .def("value", &X::value
)
93 .def_readonly("x", &X::x
)
94 .add_property("fair_value", get_fair_value
)
97 class_
<Y
>("Y", init
<int>())
98 .def("value", &Y::value
)
100 .def_readwrite("x", &Y::x
)
101 .def_readwrite("q", &Y::q
)
104 class_
<Var
>("Var", init
<std::string
>())
105 .def_readonly("name", &Var::name
)
106 .def_readonly("name2", &Var::name2
)
107 .def_readwrite("value", &Var::value
)
108 .def_readonly("y", &Var::y
)
110 // Test return_by_value for plain values and for
111 // pointers... return_by_value was implemented as a
112 // side-effect of implementing data member support, so it made
113 // sense to add the test here.
114 .def("get_name1", &Var::get_name1
, return_value_policy
<return_by_value
>())
115 .def("get_name2", &Var::get_name2
, return_value_policy
<return_by_value
>())
117 .add_property("name3", &Var::get_name1
)
119 // Test static data members
120 .def_readonly("ro1a", &Var::static1
)
121 .def_readonly("ro1b", Var::static1
)
122 .def_readwrite("rw1a", &Var::static1
)
123 .def_readwrite("rw1b", Var::static1
)
125 .def_readonly("ro2a", &Var::static2
)
126 .def_readonly("ro2b", Var::static2
)
127 .def_readwrite("rw2a", &Var::static2
)
128 .def_readwrite("rw2b", Var::static2
)
132 #include "module_tail.cpp"