1 | #include <boost/python.hpp>
|
---|
2 | #include <boost/shared_ptr.hpp>
|
---|
3 | #include <boost/make_shared.hpp>
|
---|
4 | #include <boost/weak_ptr.hpp>
|
---|
5 | #include <iostream>
|
---|
6 |
|
---|
7 | using namespace boost::python;
|
---|
8 | using namespace boost;
|
---|
9 | using namespace std;
|
---|
10 |
|
---|
11 | class A {
|
---|
12 | public:
|
---|
13 | A(int _v) : v(_v) {}
|
---|
14 | int v;
|
---|
15 | };
|
---|
16 |
|
---|
17 | weak_ptr< A > stored_a;
|
---|
18 |
|
---|
19 | // store a shared_ptr
|
---|
20 | void setWeakPtr(shared_ptr< A > a) {
|
---|
21 | stored_a = a;
|
---|
22 | }
|
---|
23 |
|
---|
24 | void outputPtr() {
|
---|
25 | cout << stored_a.lock()->v << endl;
|
---|
26 | }
|
---|
27 |
|
---|
28 | BOOST_PYTHON_MODULE(_weak_ptr)
|
---|
29 | {
|
---|
30 | class_< A, shared_ptr< A > >("A", init<int>());
|
---|
31 | def("setWeakPtr", &setWeakPtr);
|
---|
32 | def("outputPtr", &outputPtr);
|
---|
33 | }
|
---|