source: NonGTP/Boost/boost/python/converter/registered.hpp @ 857

Revision 857, 2.3 KB checked in by igarcia, 18 years ago (diff)
Line 
1// Copyright David Abrahams 2002.
2// Distributed under the Boost Software License, Version 1.0. (See
3// accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5#ifndef REGISTERED_DWA2002710_HPP
6# define REGISTERED_DWA2002710_HPP
7# include <boost/python/type_id.hpp>
8# include <boost/python/converter/registry.hpp>
9# include <boost/python/converter/registrations.hpp>
10# include <boost/type_traits/transform_traits.hpp>
11# include <boost/type_traits/cv_traits.hpp>
12# include <boost/detail/workaround.hpp>
13
14namespace boost {
15
16// You'll see shared_ptr mentioned in this header because we need to
17// note which types are shared_ptrs in their registrations, to
18// implement special shared_ptr handling for rvalue conversions.
19template <class T> class shared_ptr;
20
21namespace python { namespace converter {
22
23struct registration;
24
25namespace detail
26{
27  template <class T>
28  struct registered_base
29  {
30      static registration const& converters;
31  };
32}
33
34template <class T>
35struct registered
36  : detail::registered_base<
37        typename add_reference<
38            typename add_cv<T>::type
39        >::type
40    >
41{
42};
43
44# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
45    && !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
46// collapses a few more types to the same static instance.  MSVC7.1
47// fails to strip cv-qualification from array types in typeid.  For
48// some reason we can't use this collapse there or array converters
49// will not be found.
50template <class T>
51struct registered<T&>
52  : registered<T> {};
53# endif
54
55//
56// implementations
57//
58namespace detail
59{
60  inline void
61  register_shared_ptr0(...)
62  {
63  }
64 
65  template <class T>
66  inline void
67  register_shared_ptr0(shared_ptr<T>*)
68  {
69      registry::lookup_shared_ptr(type_id<shared_ptr<T> >());
70  }
71 
72  template <class T>
73  inline void
74  register_shared_ptr1(T const volatile*)
75  {
76      detail::register_shared_ptr0((T*)0);
77  }
78 
79  template <class T>
80  registration const&
81  registry_lookup(T&(*)())
82  {
83      detail::register_shared_ptr1((T*)0);
84      return registry::lookup(type_id<T&>());
85  }
86
87  template <class T>
88  registration const& registered_base<T>::converters = detail::registry_lookup((T(*)())0);
89}
90
91}}} // namespace boost::python::converter
92
93#endif // REGISTERED_DWA2002710_HPP
Note: See TracBrowser for help on using the repository browser.