source: NonGTP/Boost/boost/python/ptr.hpp @ 857

Revision 857, 2.6 KB checked in by igarcia, 19 years ago (diff)
Line 
1#ifndef PTR_DWA20020601_HPP
2# define PTR_DWA20020601_HPP
3
4# include <boost/python/detail/prefix.hpp>
5// Copyright David Abrahams 2002.
6// Distributed under the Boost Software License, Version 1.0. (See
7// accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9//
10// Based on boost/ref.hpp, thus:
11//  Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
12//  Copyright (C) 2001 Peter Dimov
13
14# if _MSC_VER+0 >= 1020
15#  pragma once
16# endif
17
18# include <boost/config.hpp>
19# include <boost/mpl/bool.hpp>
20
21namespace boost { namespace python {
22
23template<class Ptr> class pointer_wrapper
24{
25 public:
26    typedef Ptr type;
27   
28    explicit pointer_wrapper(Ptr x): p_(x) {}
29    operator Ptr() const { return p_; }
30    Ptr get() const { return p_; }
31 private:
32    Ptr p_;
33};
34
35template<class T>
36inline pointer_wrapper<T> ptr(T t)
37{
38    return pointer_wrapper<T>(t);
39}
40
41# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
42template<typename T>
43class is_pointer_wrapper
44    : public mpl::false_
45{
46};
47
48template<typename T>
49class is_pointer_wrapper<pointer_wrapper<T> >
50    : public mpl::true_
51{
52};
53
54template<typename T>
55class unwrap_pointer
56{
57 public:
58    typedef T type;
59};
60
61template<typename T>
62class 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
73namespace boost { namespace python {
74
75namespace 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(boost::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
106template<typename T>
107class is_pointer_wrapper
108{
109 public:
110    BOOST_STATIC_CONSTANT(
111        bool, value = (
112        sizeof(detail::is_pointer_wrapper_test(boost::type<T>()))
113            == sizeof(detail::yes_pointer_wrapper_t)));
114    typedef mpl::bool_<value> type;
115};
116
117template <typename T>
118class unwrap_pointer
119    : public detail::pointer_unwrapper<
120        is_pointer_wrapper<T>::value
121      >::template apply<T>
122{};
123
124# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
125
126}} // namespace boost::python
127
128#endif // #ifndef PTR_DWA20020601_HPP
Note: See TracBrowser for help on using the repository browser.