|
| 1 | +#include <boost/python/module.hpp> |
| 2 | +#include <boost/python/class.hpp> |
| 3 | +#include <boost/utility.hpp> |
| 4 | + |
| 5 | +/* Non-modifiable definitions */ |
| 6 | + |
| 7 | +class basic { |
| 8 | +public: |
| 9 | + basic() { name = "cltree.basic"; } |
| 10 | + std::string repr() { return name+"()"; } |
| 11 | +protected: |
| 12 | + std::string name; |
| 13 | +}; |
| 14 | + |
| 15 | +class constant: public basic { |
| 16 | +public: |
| 17 | + constant() { name = "cltree.constant"; } |
| 18 | +}; |
| 19 | + |
| 20 | +class symbol: public basic { |
| 21 | +public: |
| 22 | + symbol() { name = "cltree.symbol"; } |
| 23 | +}; |
| 24 | + |
| 25 | +class variable: public basic { |
| 26 | +public: |
| 27 | + variable() { name = "cltree.variable"; } |
| 28 | +}; |
| 29 | + |
| 30 | +/* EOF: Non-modifiable definitions */ |
| 31 | + |
| 32 | +class symbol_wrapper: public symbol { |
| 33 | +public: |
| 34 | + symbol_wrapper(PyObject* self): symbol() { |
| 35 | + name = "cltree.wrapped_symbol"; |
| 36 | + } |
| 37 | +}; |
| 38 | + |
| 39 | +class variable_wrapper: public variable { |
| 40 | +public: |
| 41 | + variable_wrapper(PyObject* self): variable() { |
| 42 | + name = "cltree.wrapped_variable"; |
| 43 | + } |
| 44 | + |
| 45 | + // This constructor is introduced only because cannot use |
| 46 | + // boost::noncopyable, see below. |
| 47 | + variable_wrapper(PyObject* self,variable v): variable(v) {} |
| 48 | + |
| 49 | +}; |
| 50 | + |
| 51 | +BOOST_PYTHON_MODULE_INIT(cltree) { |
| 52 | + |
| 53 | + boost::python::module m("cltree"); |
| 54 | + m |
| 55 | + .add( |
| 56 | + boost::python::class_<basic>("basic") |
| 57 | + .def_init(boost::python::args<>()) |
| 58 | + .def("__repr__",&basic::repr) |
| 59 | + ) |
| 60 | + ; |
| 61 | + |
| 62 | + m |
| 63 | + .add(boost::python::class_<constant |
| 64 | + ,boost::python::bases<basic> |
| 65 | + ,boost::noncopyable |
| 66 | + >("constant") |
| 67 | + .def_init(boost::python::args<>()) |
| 68 | + ) |
| 69 | + |
| 70 | + .add(boost::python::class_<symbol |
| 71 | + ,symbol_wrapper |
| 72 | + ,boost::noncopyable |
| 73 | + >("symbol") |
| 74 | + .def_init(boost::python::args<>()) |
| 75 | + ) |
| 76 | + |
| 77 | + .add(boost::python::class_<variable |
| 78 | + ,boost::python::bases<basic> |
| 79 | + ,variable_wrapper |
| 80 | + //,boost::noncopyable // leads to compiler failure?! |
| 81 | + >("variable") |
| 82 | + .def_init(boost::python::args<>()) |
| 83 | + ) |
| 84 | + ; |
| 85 | +} |
0 commit comments