borrowed_ptr.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef BORROWED_PTR_DWA20020601_HPP
  2. # define BORROWED_PTR_DWA20020601_HPP
  3. // Copyright David Abrahams 2002.
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. # include <boost/config.hpp>
  8. # include <boost/type.hpp>
  9. # include <boost/mpl/if.hpp>
  10. # include <boost/python/detail/type_traits.hpp>
  11. # include <boost/python/tag.hpp>
  12. namespace boost { namespace python { namespace detail {
  13. template<class T> class borrowed
  14. {
  15. typedef T type;
  16. };
  17. template<typename T>
  18. struct is_borrowed_ptr
  19. {
  20. BOOST_STATIC_CONSTANT(bool, value = false);
  21. };
  22. # if !defined(__MWERKS__) || __MWERKS__ > 0x3000
  23. template<typename T>
  24. struct is_borrowed_ptr<borrowed<T>*>
  25. {
  26. BOOST_STATIC_CONSTANT(bool, value = true);
  27. };
  28. template<typename T>
  29. struct is_borrowed_ptr<borrowed<T> const*>
  30. {
  31. BOOST_STATIC_CONSTANT(bool, value = true);
  32. };
  33. template<typename T>
  34. struct is_borrowed_ptr<borrowed<T> volatile*>
  35. {
  36. BOOST_STATIC_CONSTANT(bool, value = true);
  37. };
  38. template<typename T>
  39. struct is_borrowed_ptr<borrowed<T> const volatile*>
  40. {
  41. BOOST_STATIC_CONSTANT(bool, value = true);
  42. };
  43. # else
  44. template<typename T>
  45. struct is_borrowed
  46. {
  47. BOOST_STATIC_CONSTANT(bool, value = false);
  48. };
  49. template<typename T>
  50. struct is_borrowed<borrowed<T> >
  51. {
  52. BOOST_STATIC_CONSTANT(bool, value = true);
  53. };
  54. template<typename T>
  55. struct is_borrowed_ptr<T*>
  56. : is_borrowed<typename remove_cv<T>::type>
  57. {
  58. };
  59. # endif
  60. }
  61. template <class T>
  62. inline T* get_managed_object(detail::borrowed<T> const volatile* p, tag_t)
  63. {
  64. return (T*)p;
  65. }
  66. }} // namespace boost::python::detail
  67. #endif // #ifndef BORROWED_PTR_DWA20020601_HPP