long.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/def.hpp>
  7. #include <boost/python/long.hpp>
  8. #include <boost/python/class.hpp>
  9. #define BOOST_ENABLE_ASSERT_HANDLER
  10. #include <boost/assert.hpp>
  11. using namespace boost::python;
  12. object new_long()
  13. {
  14. return long_();
  15. }
  16. long_ longify(object x)
  17. {
  18. return long_(x);
  19. }
  20. object longify_string(char const* s)
  21. {
  22. return long_(s);
  23. }
  24. char const* is_long1(long_& x)
  25. {
  26. long_ y = x;
  27. x += 50;
  28. BOOST_ASSERT(x == y + 50);
  29. return "yes";
  30. }
  31. int is_long2(char const*)
  32. {
  33. return 0;
  34. }
  35. // tests for accepting objects (and derived classes) in constructors
  36. // from "Milind Patil" <milind_patil-at-hotmail.com>
  37. struct Y
  38. {
  39. Y(boost::python::long_) {}
  40. };
  41. BOOST_PYTHON_MODULE(long_ext)
  42. {
  43. def("new_long", new_long);
  44. def("longify", longify);
  45. def("longify_string", longify_string);
  46. def("is_long", is_long1);
  47. def("is_long", is_long2);
  48. class_< Y >("Y", init< boost::python::long_ >())
  49. ;
  50. }
  51. #include "module_tail.cpp"