|
| 1 | +#ifndef BOOST_PTR_HPP_INCLUDED |
| 2 | +# define BOOST_PTR_HPP_INCLUDED |
| 3 | +// Copyright David Abrahams 2002. Permission to copy, use, |
| 4 | +// modify, sell and distribute this software is granted provided this |
| 5 | +// copyright notice appears in all copies. This software is provided |
| 6 | +// "as is" without express or implied warranty, and with no claim as |
| 7 | +// to its suitability for any purpose. |
| 8 | +// |
| 9 | +// Based on boost/ref.hpp, thus: |
| 10 | +// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) |
| 11 | +// Copyright (C) 2001 Peter Dimov |
| 12 | + |
| 13 | +# if _MSC_VER+0 >= 1020 |
| 14 | +# pragma once |
| 15 | +# endif |
| 16 | + |
| 17 | +# include <boost/config.hpp> |
| 18 | + |
| 19 | +namespace boost { namespace python { |
| 20 | + |
| 21 | +template<class Ptr> class pointer_wrapper |
| 22 | +{ |
| 23 | + public: |
| 24 | + typedef Ptr type; |
| 25 | + |
| 26 | + explicit pointer_wrapper(Ptr x): p_(x) {} |
| 27 | + operator Ptr() const { return p_; } |
| 28 | + Ptr get() const { return p_; } |
| 29 | + private: |
| 30 | + Ptr p_; |
| 31 | +}; |
| 32 | + |
| 33 | +template<class T> |
| 34 | +inline pointer_wrapper<T> ptr(T t) |
| 35 | +{ |
| 36 | + return pointer_wrapper<T>(t); |
| 37 | +} |
| 38 | + |
| 39 | +# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
| 40 | +template<typename T> |
| 41 | +class is_pointer_wrapper |
| 42 | +{ |
| 43 | + public: |
| 44 | + BOOST_STATIC_CONSTANT(bool, value = false); |
| 45 | +}; |
| 46 | + |
| 47 | +template<typename T> |
| 48 | +class is_pointer_wrapper<pointer_wrapper<T> > |
| 49 | +{ |
| 50 | + public: |
| 51 | + BOOST_STATIC_CONSTANT(bool, value = true); |
| 52 | +}; |
| 53 | + |
| 54 | +template<typename T> |
| 55 | +class unwrap_pointer |
| 56 | +{ |
| 57 | + public: |
| 58 | + typedef T type; |
| 59 | +}; |
| 60 | + |
| 61 | +template<typename T> |
| 62 | +class unwrap_pointer<pointer_wrapper<T> > |
| 63 | +{ |
| 64 | + public: |
| 65 | + typedef T type; |
| 66 | +}; |
| 67 | +# else // no partial specialization |
| 68 | + |
| 69 | +}} // namespace boost::python |
| 70 | + |
| 71 | +#include <boost/type.hpp> |
| 72 | + |
| 73 | +namespace boost { namespace python { |
| 74 | + |
| 75 | +namespace detail |
| 76 | +{ |
| 77 | + typedef char (&yes_pointer_wrapper_t)[1]; |
| 78 | + typedef char (&no_pointer_wrapper_t)[2]; |
| 79 | + |
| 80 | + no_pointer_wrapper_t is_pointer_wrapper_test(...); |
| 81 | + |
| 82 | + template<typename T> |
| 83 | + yes_pointer_wrapper_t is_pointer_wrapper_test(type< pointer_wrapper<T> >); |
| 84 | + |
| 85 | + template<bool wrapped> |
| 86 | + struct pointer_unwrapper |
| 87 | + { |
| 88 | + template <class T> |
| 89 | + struct apply |
| 90 | + { |
| 91 | + typedef T type; |
| 92 | + }; |
| 93 | + }; |
| 94 | + |
| 95 | + template<> |
| 96 | + struct pointer_unwrapper<true> |
| 97 | + { |
| 98 | + template <class T> |
| 99 | + struct apply |
| 100 | + { |
| 101 | + typedef typename T::type type; |
| 102 | + }; |
| 103 | + }; |
| 104 | +} |
| 105 | + |
| 106 | +template<typename T> |
| 107 | +class is_pointer_wrapper |
| 108 | +{ |
| 109 | + public: |
| 110 | + BOOST_STATIC_CONSTANT( |
| 111 | + bool, value = ( |
| 112 | + sizeof(detail::is_pointer_wrapper_test(type<T>())) |
| 113 | + == sizeof(detail::yes_pointer_wrapper_t))); |
| 114 | +}; |
| 115 | + |
| 116 | +template <typename T> |
| 117 | +class unwrap_pointer |
| 118 | + : public detail::pointer_unwrapper< |
| 119 | + is_pointer_wrapper<T>::value |
| 120 | + >::template apply<T> |
| 121 | +{}; |
| 122 | + |
| 123 | +# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
| 124 | + |
| 125 | +}} // namespace boost::python |
| 126 | + |
| 127 | +#endif // #ifndef BOOST_PTR_HPP_INCLUDED |
0 commit comments