object_protocol.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #ifndef OBJECT_PROTOCOL_DWA2002615_HPP
  6. # define OBJECT_PROTOCOL_DWA2002615_HPP
  7. # include <boost/python/detail/prefix.hpp>
  8. # include <boost/python/object_protocol_core.hpp>
  9. # include <boost/python/object_core.hpp>
  10. # include <boost/detail/workaround.hpp>
  11. namespace boost { namespace python { namespace api {
  12. # if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
  13. // attempt to use SFINAE to prevent functions accepting T const& from
  14. // coming up as ambiguous with the one taking a char const* when a
  15. // string literal is passed
  16. # define BOOST_PYTHON_NO_ARRAY_ARG(T) , T (*)() = 0
  17. # else
  18. # define BOOST_PYTHON_NO_ARRAY_ARG(T)
  19. # endif
  20. template <class Target, class Key>
  21. object getattr(Target const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key))
  22. {
  23. return getattr(object(target), object(key));
  24. }
  25. template <class Target, class Key, class Default>
  26. object getattr(Target const& target, Key const& key, Default const& default_ BOOST_PYTHON_NO_ARRAY_ARG(Key))
  27. {
  28. return getattr(object(target), object(key), object(default_));
  29. }
  30. template <class Key, class Value>
  31. void setattr(object const& target, Key const& key, Value const& value BOOST_PYTHON_NO_ARRAY_ARG(Key))
  32. {
  33. setattr(target, object(key), object(value));
  34. }
  35. template <class Key>
  36. void delattr(object const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key))
  37. {
  38. delattr(target, object(key));
  39. }
  40. template <class Target, class Key>
  41. object getitem(Target const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key))
  42. {
  43. return getitem(object(target), object(key));
  44. }
  45. template <class Key, class Value>
  46. void setitem(object const& target, Key const& key, Value const& value BOOST_PYTHON_NO_ARRAY_ARG(Key))
  47. {
  48. setitem(target, object(key), object(value));
  49. }
  50. template <class Key>
  51. void delitem(object const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key))
  52. {
  53. delitem(target, object(key));
  54. }
  55. template <class Target, class Begin, class End>
  56. object getslice(Target const& target, Begin const& begin, End const& end)
  57. {
  58. return getslice(object(target), object(begin), object(end));
  59. }
  60. template <class Begin, class End, class Value>
  61. void setslice(object const& target, Begin const& begin, End const& end, Value const& value)
  62. {
  63. setslice(target, object(begin), object(end), object(value));
  64. }
  65. template <class Begin, class End>
  66. void delslice(object const& target, Begin const& begin, End const& end)
  67. {
  68. delslice(target, object(begin), object(end));
  69. }
  70. }}} // namespace boost::python::api
  71. #endif // OBJECT_PROTOCOL_DWA2002615_HPP