Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

updated boost from 1_33_1 to 1_34_1

File size: 1.0 KB
Line 
1// Copyright David Abrahams 2004. 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.hpp>
6#include <boost/shared_ptr.hpp>
7
8using namespace boost;
9using namespace python;
10
11struct A
12{
13    virtual int f() { return 0; }
14};
15
16shared_ptr<A> New() { return shared_ptr<A>( new A() ); }
17
18int Call( const shared_ptr<A> & a )
19{
20    return a->f();
21}
22
23int Fail( shared_ptr<A> & a )
24{
25    return a->f();
26}
27
28struct A_Wrapper: A
29{
30    A_Wrapper(PyObject* self_): self(self_) {}
31    A_Wrapper(PyObject* self_, const A& a): self(self_), A(a) {}
32
33    int f() 
34    {
35        return call_method<int>(self, "f");
36    }
37   
38    int default_f() 
39    {
40        return A::f();
41    }
42   
43    PyObject* self;
44};
45
46BOOST_PYTHON_MODULE(register_ptr)
47{
48    class_<A, A_Wrapper>("A")
49        .def("f", &A::f, &A_Wrapper::default_f)
50    ;
51    register_ptr_to_python< shared_ptr<A> >();
52    def("New", &New);
53    def("Call", &Call);
54    def("Fail", &Fail);
55}
Note: See TracBrowser for help on using the repository browser.