enum_ext.cpp 1.4 KB

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