]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright David Abrahams 2005. Distributed under the Boost |
2 | // Software License, Version 1.0. (See accompanying | |
3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
4 | ||
5 | #include <boost/python/register_ptr_to_python.hpp> | |
6 | #include <boost/python/def.hpp> | |
7 | #include <boost/python/class.hpp> | |
8 | #include <boost/python/wrapper.hpp> | |
9 | #include <boost/python/module.hpp> | |
10 | #include <boost/python/implicit.hpp> | |
11 | ||
12 | #include <memory> | |
13 | ||
14 | struct data | |
15 | { | |
16 | virtual ~data() {}; // silence compiler warnings | |
17 | virtual int id() const | |
18 | { | |
19 | return 42; | |
20 | } | |
21 | }; | |
22 | ||
23 | std::auto_ptr<data> create_data() | |
24 | { | |
25 | return std::auto_ptr<data>( new data ); | |
26 | } | |
27 | ||
28 | void do_nothing( std::auto_ptr<data>& ){} | |
29 | ||
30 | ||
31 | namespace bp = boost::python; | |
32 | ||
33 | struct data_wrapper : data, bp::wrapper< data > | |
34 | { | |
35 | data_wrapper(data const & arg ) | |
36 | : data( arg ) | |
37 | , bp::wrapper< data >() | |
38 | {} | |
39 | ||
40 | data_wrapper() | |
41 | : data() | |
42 | , bp::wrapper< data >() | |
43 | {} | |
44 | ||
45 | virtual int id() const | |
46 | { | |
47 | if( bp::override id = this->get_override( "id" ) ) | |
48 | return bp::call<int>(id.ptr()); // id(); | |
49 | else | |
50 | return data::id( ); | |
51 | } | |
52 | ||
53 | virtual int default_id( ) const | |
54 | { | |
55 | return this->data::id( ); | |
56 | } | |
57 | ||
58 | }; | |
59 | ||
60 | BOOST_PYTHON_MODULE(wrapper_held_type_ext) | |
61 | { | |
62 | bp::class_< data_wrapper, std::auto_ptr< data > >( "data" ) | |
63 | .def( "id", &data::id, &::data_wrapper::default_id ); | |
64 | ||
65 | bp::def( "do_nothing", &do_nothing ); | |
66 | bp::def( "create_data", &create_data ); | |
67 | } | |
68 | ||
69 | #include "module_tail.cpp" |