Rev | Line | |
---|
[12] | 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/def.hpp> |
---|
| 8 | #include <boost/python/call_method.hpp> |
---|
| 9 | #include <boost/ref.hpp> |
---|
| 10 | #include <boost/utility.hpp> |
---|
| 11 | |
---|
| 12 | using namespace boost::python; |
---|
| 13 | |
---|
| 14 | struct X |
---|
| 15 | { |
---|
| 16 | explicit X(int x) : x(x), magic(7654321) { ++counter; } |
---|
| 17 | X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; } |
---|
| 18 | virtual ~X() { assert(magic == 7654321); magic = 6666666; x = 9999; --counter; } |
---|
| 19 | |
---|
| 20 | void set(int x) { assert(magic == 7654321); this->x = x; } |
---|
| 21 | int value() const { assert(magic == 7654321); return x; } |
---|
| 22 | static int count() { return counter; } |
---|
| 23 | private: |
---|
| 24 | void operator=(X const&); |
---|
| 25 | private: |
---|
| 26 | int x; |
---|
| 27 | long magic; |
---|
| 28 | static int counter; |
---|
| 29 | }; |
---|
| 30 | int X::counter; |
---|
| 31 | int getXmagic(){return 7654321;} |
---|
| 32 | |
---|
| 33 | BOOST_PYTHON_MODULE(staticmethod_ext) |
---|
| 34 | { |
---|
| 35 | class_<X>("X", init<int>()) |
---|
| 36 | .def("value", &X::value) |
---|
| 37 | .def("set", &X::set) |
---|
| 38 | .def("count", &X::count) |
---|
| 39 | .staticmethod("count") |
---|
| 40 | .def("magic", &getXmagic) |
---|
| 41 | .staticmethod("magic") |
---|
| 42 | ; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | #include "module_tail.cpp" |
---|
Note: See
TracBrowser
for help on using the repository browser.