cltree.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright David Abrahams 2005. 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. #include <boost/python/module.hpp>
  5. #include <boost/python/def.hpp>
  6. #include <boost/python/class.hpp>
  7. #include <boost/utility.hpp>
  8. /* Non-modifiable definitions */
  9. class basic {
  10. public:
  11. basic() { name = "cltree.basic"; }
  12. std::string repr() { return name+"()"; }
  13. protected:
  14. std::string name;
  15. };
  16. class constant: public basic {
  17. public:
  18. constant() { name = "cltree.constant"; }
  19. };
  20. class symbol: public basic {
  21. public:
  22. symbol() { name = "cltree.symbol"; }
  23. };
  24. class variable: public basic {
  25. public:
  26. variable() { name = "cltree.variable"; }
  27. };
  28. /* EOF: Non-modifiable definitions */
  29. class symbol_wrapper: public symbol {
  30. public:
  31. symbol_wrapper(PyObject* /*self*/): symbol() {
  32. name = "cltree.wrapped_symbol";
  33. }
  34. };
  35. class variable_wrapper: public variable {
  36. public:
  37. variable_wrapper(PyObject* /*self*/): variable() {
  38. name = "cltree.wrapped_variable";
  39. }
  40. // This constructor is introduced only because cannot use
  41. // boost::noncopyable, see below.
  42. variable_wrapper(PyObject* /*self*/,variable v): variable(v) {}
  43. };
  44. BOOST_PYTHON_MODULE(cltree)
  45. {
  46. boost::python::class_<basic>("basic")
  47. .def("__repr__",&basic::repr)
  48. ;
  49. boost::python::class_<constant, boost::python::bases<basic>, boost::noncopyable>("constant")
  50. ;
  51. boost::python::class_<symbol, symbol_wrapper, boost::noncopyable>("symbol")
  52. ;
  53. boost::python::class_<variable, boost::python::bases<basic>, variable_wrapper>("variable")
  54. ;
  55. }
  56. #include "module_tail.cpp"