• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #include <boost/python/module.hpp>
6 #include <boost/python/def.hpp>
7 #include <boost/python/class.hpp>
8 #include <boost/utility.hpp>
9 
10 /*  Non-modifiable definitions */
11 
12 class basic {
13 public:
basic()14   basic() { name = "cltree.basic"; }
repr()15   std::string repr() { return name+"()"; }
16 protected:
17   std::string name;
18 };
19 
20 class constant: public basic {
21 public:
constant()22   constant() { name = "cltree.constant"; }
23 };
24 
25 class symbol: public basic {
26 public:
symbol()27   symbol() { name = "cltree.symbol"; }
28 };
29 
30 class variable: public basic {
31 public:
variable()32   variable() { name = "cltree.variable"; }
33 };
34 
35 /*  EOF: Non-modifiable definitions */
36 
37 class symbol_wrapper: public symbol {
38 public:
symbol_wrapper(PyObject *)39   symbol_wrapper(PyObject* /*self*/): symbol() {
40     name = "cltree.wrapped_symbol";
41   }
42 };
43 
44 class variable_wrapper: public variable {
45 public:
variable_wrapper(PyObject *)46   variable_wrapper(PyObject* /*self*/): variable() {
47     name = "cltree.wrapped_variable";
48   }
49 
50   // This constructor is introduced only because cannot use
51   // boost::noncopyable, see below.
variable_wrapper(PyObject *,variable v)52   variable_wrapper(PyObject* /*self*/,variable v): variable(v) {}
53 
54 };
55 
BOOST_PYTHON_MODULE(cltree)56 BOOST_PYTHON_MODULE(cltree)
57 {
58     boost::python::class_<basic>("basic")
59         .def("__repr__",&basic::repr)
60         ;
61 
62     boost::python::class_<constant, boost::python::bases<basic>, boost::noncopyable>("constant")
63         ;
64 
65 
66     boost::python::class_<symbol, symbol_wrapper, boost::noncopyable>("symbol")
67         ;
68 
69     boost::python::class_<variable, boost::python::bases<basic>, variable_wrapper>("variable")
70         ;
71 }
72 
73 #include "module_tail.cpp"
74 
75