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 6 #include <boost/python/class.hpp> 7 #include <boost/python/module.hpp> 8 #include <boost/python/def.hpp> 9 #include <boost/python/call_method.hpp> 10 #include <boost/ref.hpp> 11 #include <boost/utility.hpp> 12 #define BOOST_ENABLE_ASSERT_HANDLER 13 #include <boost/assert.hpp> 14 15 using namespace boost::python; 16 17 struct X 18 { XX19 explicit X(int x) : x(x), magic(7654321) { ++counter; } XX20 X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; } ~XX21 virtual ~X() { BOOST_ASSERT(magic == 7654321); magic = 6666666; x = 9999; --counter; } 22 setX23 void set(int _x) { BOOST_ASSERT(magic == 7654321); this->x = _x; } valueX24 int value() const { BOOST_ASSERT(magic == 7654321); return x; } countX25 static int count() { return counter; } 26 private: 27 void operator=(X const&); 28 private: 29 int x; 30 long magic; 31 static int counter; 32 }; 33 int X::counter; getXmagic()34int getXmagic(){return 7654321;} 35 BOOST_PYTHON_MODULE(staticmethod_ext)36BOOST_PYTHON_MODULE(staticmethod_ext) 37 { 38 class_<X>("X", init<int>()) 39 .def("value", &X::value) 40 .def("set", &X::set) 41 .def("count", &X::count) 42 .staticmethod("count") 43 .def("magic", &getXmagic) 44 .staticmethod("magic") 45 ; 46 } 47 48 #include "module_tail.cpp" 49