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/enum.hpp> |
---|
6 | #include <boost/python/def.hpp> |
---|
7 | #include <boost/python/module.hpp> |
---|
8 | #include <boost/python/class.hpp> |
---|
9 | #if BOOST_WORKAROUND(__MWERKS__, <= 0x2407) |
---|
10 | # include <boost/type_traits/is_enum.hpp> |
---|
11 | # include <boost/mpl/bool.hpp> |
---|
12 | #endif |
---|
13 | using namespace boost::python; |
---|
14 | |
---|
15 | enum color { red = 1, green = 2, blue = 4 }; |
---|
16 | |
---|
17 | #if BOOST_WORKAROUND(__MWERKS__, <= 0x2407) |
---|
18 | namespace boost // Pro7 has a hard time detecting enums |
---|
19 | { |
---|
20 | template <> struct is_enum<color> : boost::mpl::true_ {}; |
---|
21 | } |
---|
22 | #endif |
---|
23 | |
---|
24 | color identity_(color x) { return x; } |
---|
25 | |
---|
26 | struct colorized { |
---|
27 | colorized() : x(red) {} |
---|
28 | color x; |
---|
29 | }; |
---|
30 | |
---|
31 | BOOST_PYTHON_MODULE(enum_ext) |
---|
32 | { |
---|
33 | enum_<color>("color") |
---|
34 | .value("red", red) |
---|
35 | .value("green", green) |
---|
36 | .value("blue", blue) |
---|
37 | .export_values() |
---|
38 | ; |
---|
39 | |
---|
40 | def("identity", identity_); |
---|
41 | |
---|
42 | #if BOOST_WORKAROUND(__MWERKS__, <=0x2407) |
---|
43 | color colorized::*px = &colorized::x; |
---|
44 | class_<colorized>("colorized") |
---|
45 | .def_readwrite("x", px) |
---|
46 | ; |
---|
47 | #else |
---|
48 | class_<colorized>("colorized") |
---|
49 | .def_readwrite("x", &colorized::x) |
---|
50 | ; |
---|
51 | #endif |
---|
52 | } |
---|
53 | |
---|
54 | #include "module_tail.cpp" |
---|