nested.cpp 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/module.hpp>
  6. #include <boost/python/class.hpp>
  7. #include <boost/python/operators.hpp>
  8. #include <boost/python/scope.hpp>
  9. #include "test_class.hpp"
  10. #if __GNUC__ != 2
  11. # include <ostream>
  12. #else
  13. # include <ostream.h>
  14. #endif
  15. typedef test_class<> X;
  16. typedef test_class<1> Y;
  17. std::ostream& operator<<(std::ostream& s, X const& x)
  18. {
  19. return s << x.value();
  20. }
  21. std::ostream& operator<<(std::ostream& s, Y const& x)
  22. {
  23. return s << x.value();
  24. }
  25. BOOST_PYTHON_MODULE(nested_ext)
  26. {
  27. using namespace boost::python;
  28. // Establish X as the current scope.
  29. scope x_class
  30. = class_<X>("X", init<int>())
  31. .def(str(self))
  32. ;
  33. // Y will now be defined in the current scope
  34. class_<Y>("Y", init<int>())
  35. .def(str(self))
  36. ;
  37. }
  38. #include "module_tail.cpp"