os/ossrv/ossrv_pub/boost_apis/boost/python/ptr.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
#ifndef PTR_DWA20020601_HPP
sl@0
     2
# define PTR_DWA20020601_HPP
sl@0
     3
sl@0
     4
# include <boost/python/detail/prefix.hpp>
sl@0
     5
// Copyright David Abrahams 2002.
sl@0
     6
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
     7
// accompanying file LICENSE_1_0.txt or copy at
sl@0
     8
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     9
//
sl@0
    10
// Based on boost/ref.hpp, thus:
sl@0
    11
//  Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
sl@0
    12
//  Copyright (C) 2001 Peter Dimov
sl@0
    13
sl@0
    14
# if _MSC_VER+0 >= 1020
sl@0
    15
#  pragma once
sl@0
    16
# endif
sl@0
    17
sl@0
    18
# include <boost/config.hpp>
sl@0
    19
# include <boost/mpl/bool.hpp>
sl@0
    20
sl@0
    21
namespace boost { namespace python {
sl@0
    22
sl@0
    23
template<class Ptr> class pointer_wrapper
sl@0
    24
{ 
sl@0
    25
 public:
sl@0
    26
    typedef Ptr type;
sl@0
    27
    
sl@0
    28
    explicit pointer_wrapper(Ptr x): p_(x) {}
sl@0
    29
    operator Ptr() const { return p_; }
sl@0
    30
    Ptr get() const { return p_; }
sl@0
    31
 private:
sl@0
    32
    Ptr p_;
sl@0
    33
};
sl@0
    34
sl@0
    35
template<class T>
sl@0
    36
inline pointer_wrapper<T> ptr(T t)
sl@0
    37
{ 
sl@0
    38
    return pointer_wrapper<T>(t);
sl@0
    39
}
sl@0
    40
sl@0
    41
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
sl@0
    42
template<typename T>
sl@0
    43
class is_pointer_wrapper
sl@0
    44
    : public mpl::false_
sl@0
    45
{
sl@0
    46
};
sl@0
    47
sl@0
    48
template<typename T>
sl@0
    49
class is_pointer_wrapper<pointer_wrapper<T> >
sl@0
    50
    : public mpl::true_
sl@0
    51
{
sl@0
    52
};
sl@0
    53
sl@0
    54
template<typename T>
sl@0
    55
class unwrap_pointer
sl@0
    56
{
sl@0
    57
 public:
sl@0
    58
    typedef T type;
sl@0
    59
};
sl@0
    60
sl@0
    61
template<typename T>
sl@0
    62
class unwrap_pointer<pointer_wrapper<T> >
sl@0
    63
{
sl@0
    64
 public:
sl@0
    65
    typedef T type;
sl@0
    66
};
sl@0
    67
# else // no partial specialization
sl@0
    68
sl@0
    69
}} // namespace boost::python
sl@0
    70
sl@0
    71
#include <boost/type.hpp>
sl@0
    72
sl@0
    73
namespace boost { namespace python {
sl@0
    74
sl@0
    75
namespace detail
sl@0
    76
{
sl@0
    77
  typedef char (&yes_pointer_wrapper_t)[1];
sl@0
    78
  typedef char (&no_pointer_wrapper_t)[2];
sl@0
    79
      
sl@0
    80
  no_pointer_wrapper_t is_pointer_wrapper_test(...);
sl@0
    81
sl@0
    82
  template<typename T>
sl@0
    83
  yes_pointer_wrapper_t is_pointer_wrapper_test(boost::type< pointer_wrapper<T> >);
sl@0
    84
sl@0
    85
  template<bool wrapped>
sl@0
    86
  struct pointer_unwrapper
sl@0
    87
  {
sl@0
    88
      template <class T>
sl@0
    89
      struct apply
sl@0
    90
      {
sl@0
    91
          typedef T type;
sl@0
    92
      };
sl@0
    93
  };
sl@0
    94
sl@0
    95
  template<>
sl@0
    96
  struct pointer_unwrapper<true>
sl@0
    97
  {
sl@0
    98
      template <class T>
sl@0
    99
      struct apply
sl@0
   100
      {
sl@0
   101
          typedef typename T::type type;
sl@0
   102
      };
sl@0
   103
  };
sl@0
   104
}
sl@0
   105
sl@0
   106
template<typename T>
sl@0
   107
class is_pointer_wrapper
sl@0
   108
{
sl@0
   109
 public:
sl@0
   110
    BOOST_STATIC_CONSTANT(
sl@0
   111
        bool, value = (
sl@0
   112
        sizeof(detail::is_pointer_wrapper_test(boost::type<T>()))
sl@0
   113
            == sizeof(detail::yes_pointer_wrapper_t)));
sl@0
   114
    typedef mpl::bool_<value> type;
sl@0
   115
};
sl@0
   116
sl@0
   117
template <typename T>
sl@0
   118
class unwrap_pointer
sl@0
   119
    : public detail::pointer_unwrapper<
sl@0
   120
        is_pointer_wrapper<T>::value
sl@0
   121
      >::template apply<T>
sl@0
   122
{};
sl@0
   123
sl@0
   124
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
sl@0
   125
sl@0
   126
}} // namespace boost::python
sl@0
   127
sl@0
   128
#endif // #ifndef PTR_DWA20020601_HPP