Chris@16: #ifndef BORROWED_PTR_DWA20020601_HPP Chris@16: # define BORROWED_PTR_DWA20020601_HPP Chris@16: // Copyright David Abrahams 2002. Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: Chris@16: namespace boost { namespace python { namespace detail { Chris@16: Chris@16: template class borrowed Chris@16: { Chris@16: typedef T type; Chris@16: }; Chris@16: Chris@16: # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION Chris@16: template Chris@16: struct is_borrowed_ptr Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value = false); Chris@16: }; Chris@16: Chris@16: # if !defined(__MWERKS__) || __MWERKS__ > 0x3000 Chris@16: template Chris@16: struct is_borrowed_ptr*> Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value = true); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_borrowed_ptr const*> Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value = true); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_borrowed_ptr volatile*> Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value = true); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_borrowed_ptr const volatile*> Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value = true); Chris@16: }; Chris@16: # else Chris@16: template Chris@16: struct is_borrowed Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value = false); Chris@16: }; Chris@16: template Chris@16: struct is_borrowed > Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value = true); Chris@16: }; Chris@16: template Chris@16: struct is_borrowed_ptr Chris@16: : is_borrowed::type> Chris@16: { Chris@16: }; Chris@16: # endif Chris@16: Chris@16: # else // no partial specialization Chris@16: Chris@16: typedef char (&yes_borrowed_ptr_t)[1]; Chris@16: typedef char (&no_borrowed_ptr_t)[2]; Chris@16: Chris@16: no_borrowed_ptr_t is_borrowed_ptr_test(...); Chris@16: Chris@16: template Chris@16: typename mpl::if_c< Chris@16: is_pointer::value Chris@16: , T Chris@16: , int Chris@16: >::type Chris@16: is_borrowed_ptr_test1(boost::type); Chris@16: Chris@16: template Chris@16: yes_borrowed_ptr_t is_borrowed_ptr_test(borrowed const volatile*); Chris@16: Chris@16: template Chris@16: class is_borrowed_ptr Chris@16: { Chris@16: public: Chris@16: BOOST_STATIC_CONSTANT( Chris@16: bool, value = ( Chris@16: sizeof(detail::is_borrowed_ptr_test(is_borrowed_ptr_test1(boost::type()))) Chris@16: == sizeof(detail::yes_borrowed_ptr_t))); Chris@16: }; Chris@16: Chris@16: # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION Chris@16: Chris@16: } Chris@16: Chris@16: template Chris@16: inline T* get_managed_object(detail::borrowed const volatile* p, tag_t) Chris@16: { Chris@16: return (T*)p; Chris@16: } Chris@16: Chris@16: }} // namespace boost::python::detail Chris@16: Chris@16: #endif // #ifndef BORROWED_PTR_DWA20020601_HPP