os/ossrv/ossrv_pub/boost_apis/boost/python/converter/registered.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright David Abrahams 2002.
sl@0
     2
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
     3
// accompanying file LICENSE_1_0.txt or copy at
sl@0
     4
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     5
#ifndef REGISTERED_DWA2002710_HPP
sl@0
     6
# define REGISTERED_DWA2002710_HPP
sl@0
     7
# include <boost/python/type_id.hpp>
sl@0
     8
# include <boost/python/converter/registry.hpp>
sl@0
     9
# include <boost/python/converter/registrations.hpp>
sl@0
    10
# include <boost/type_traits/transform_traits.hpp>
sl@0
    11
# include <boost/type_traits/cv_traits.hpp>
sl@0
    12
# include <boost/type_traits/is_void.hpp>
sl@0
    13
# include <boost/detail/workaround.hpp>
sl@0
    14
# include <boost/python/type_id.hpp>
sl@0
    15
# include <boost/type.hpp>
sl@0
    16
sl@0
    17
namespace boost {
sl@0
    18
sl@0
    19
// You'll see shared_ptr mentioned in this header because we need to
sl@0
    20
// note which types are shared_ptrs in their registrations, to
sl@0
    21
// implement special shared_ptr handling for rvalue conversions.
sl@0
    22
template <class T> class shared_ptr;
sl@0
    23
sl@0
    24
namespace python { namespace converter { 
sl@0
    25
sl@0
    26
struct registration;
sl@0
    27
sl@0
    28
namespace detail
sl@0
    29
{
sl@0
    30
  template <class T>
sl@0
    31
  struct registered_base
sl@0
    32
  {
sl@0
    33
      static registration const& converters;
sl@0
    34
  };
sl@0
    35
}
sl@0
    36
sl@0
    37
template <class T>
sl@0
    38
struct registered
sl@0
    39
  : detail::registered_base<
sl@0
    40
        typename add_reference<
sl@0
    41
            typename add_cv<T>::type
sl@0
    42
        >::type
sl@0
    43
    >
sl@0
    44
{
sl@0
    45
};
sl@0
    46
sl@0
    47
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
sl@0
    48
    && !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
sl@0
    49
// collapses a few more types to the same static instance.  MSVC7.1
sl@0
    50
// fails to strip cv-qualification from array types in typeid.  For
sl@0
    51
// some reason we can't use this collapse there or array converters
sl@0
    52
// will not be found.
sl@0
    53
template <class T>
sl@0
    54
struct registered<T&>
sl@0
    55
  : registered<T> {};
sl@0
    56
# endif
sl@0
    57
sl@0
    58
//
sl@0
    59
// implementations
sl@0
    60
//
sl@0
    61
namespace detail
sl@0
    62
{
sl@0
    63
  inline void
sl@0
    64
  register_shared_ptr0(...)
sl@0
    65
  {
sl@0
    66
  }
sl@0
    67
  
sl@0
    68
  template <class T>
sl@0
    69
  inline void
sl@0
    70
  register_shared_ptr0(shared_ptr<T>*)
sl@0
    71
  {
sl@0
    72
      registry::lookup_shared_ptr(type_id<shared_ptr<T> >());
sl@0
    73
  }
sl@0
    74
  
sl@0
    75
  template <class T>
sl@0
    76
  inline void
sl@0
    77
  register_shared_ptr1(T const volatile*)
sl@0
    78
  {
sl@0
    79
      detail::register_shared_ptr0((T*)0);
sl@0
    80
  }
sl@0
    81
  
sl@0
    82
  template <class T>
sl@0
    83
  inline registration const& 
sl@0
    84
  registry_lookup2(T&(*)())
sl@0
    85
  {
sl@0
    86
      detail::register_shared_ptr1((T*)0);
sl@0
    87
      return registry::lookup(type_id<T&>());
sl@0
    88
  }
sl@0
    89
sl@0
    90
  template <class T>
sl@0
    91
  inline registration const& 
sl@0
    92
  registry_lookup1(type<T>)
sl@0
    93
  {
sl@0
    94
      return registry_lookup2((T(*)())0);
sl@0
    95
  }
sl@0
    96
sl@0
    97
  inline registration const& 
sl@0
    98
  registry_lookup1(type<const volatile void>)
sl@0
    99
  {
sl@0
   100
      detail::register_shared_ptr1((void*)0);
sl@0
   101
      return registry::lookup(type_id<void>());
sl@0
   102
  }
sl@0
   103
sl@0
   104
  template <class T>
sl@0
   105
  registration const& registered_base<T>::converters = detail::registry_lookup1(type<T>());
sl@0
   106
sl@0
   107
}
sl@0
   108
sl@0
   109
}}} // namespace boost::python::converter
sl@0
   110
sl@0
   111
#endif // REGISTERED_DWA2002710_HPP