~tsarev/boostdc/cmake

« back to all changes in this revision

Viewing changes to boost/boost/python/converter/pytype_function.hpp

  • Committer: bigmuscle
  • Date: 2010-05-08 08:47:15 UTC
  • Revision ID: svn-v4:5fb55d53-692c-0410-a46a-e90ab66e00ee:trunk:497
removed old boost version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright David Abrahams 2002,  Nikolay Mladenov 2007.
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 WRAP_PYTYPE_NM20070606_HPP
6
 
# define WRAP_PYTYPE_NM20070606_HPP
7
 
 
8
 
# include <boost/python/detail/prefix.hpp>
9
 
# include <boost/python/converter/registered.hpp>
10
 
#  include <boost/python/detail/unwind_type.hpp>
11
 
 
12
 
 
13
 
namespace boost { namespace python {
14
 
 
15
 
namespace converter
16
 
{
17
 
template <PyTypeObject const* python_type>
18
 
struct wrap_pytype
19
 
{
20
 
    static PyTypeObject const* get_pytype()
21
 
    {
22
 
        return python_type;
23
 
    }
24
 
};
25
 
 
26
 
typedef PyTypeObject const* (*pytype_function)();
27
 
 
28
 
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
29
 
 
30
 
 
31
 
 
32
 
namespace detail
33
 
{
34
 
struct unwind_type_id_helper{
35
 
    typedef python::type_info result_type;
36
 
    template <class U>
37
 
    static result_type execute(U* ){
38
 
        return python::type_id<U>();
39
 
    }
40
 
};
41
 
 
42
 
template <class T>
43
 
inline python::type_info unwind_type_id_(boost::type<T>* = 0, mpl::false_ * =0)
44
 
{
45
 
    return boost::python::detail::unwind_type<unwind_type_id_helper, T> ();
46
 
}
47
 
 
48
 
inline python::type_info unwind_type_id_(boost::type<void>* = 0, mpl::true_* =0)
49
 
{
50
 
    return type_id<void>();
51
 
}
52
 
 
53
 
template <class T>
54
 
inline python::type_info unwind_type_id(boost::type<T>* p= 0)
55
 
{
56
 
    return unwind_type_id_(p, (mpl::bool_<boost::is_void<T>::value >*)0 );
57
 
}
58
 
}
59
 
 
60
 
 
61
 
template <class T>
62
 
struct expected_pytype_for_arg
63
 
{
64
 
    static PyTypeObject const *get_pytype()
65
 
    {
66
 
        const converter::registration *r=converter::registry::query(
67
 
            detail::unwind_type_id_((boost::type<T>*)0, (mpl::bool_<boost::is_void<T>::value >*)0 )
68
 
            );
69
 
        return r ? r->expected_from_python_type(): 0;
70
 
    }
71
 
};
72
 
 
73
 
 
74
 
template <class T>
75
 
struct registered_pytype
76
 
{
77
 
    static PyTypeObject const *get_pytype()
78
 
    {
79
 
        const converter::registration *r=converter::registry::query(
80
 
            detail::unwind_type_id_((boost::type<T>*) 0, (mpl::bool_<boost::is_void<T>::value >*)0 )
81
 
            );
82
 
        return r ? r->m_class_object: 0;
83
 
    }
84
 
};
85
 
 
86
 
 
87
 
template <class T>
88
 
struct registered_pytype_direct
89
 
{
90
 
    static PyTypeObject const* get_pytype()
91
 
    {
92
 
        return registered<T>::converters.m_class_object;
93
 
    }
94
 
};
95
 
 
96
 
template <class T>
97
 
struct expected_from_python_type : expected_pytype_for_arg<T>{};
98
 
 
99
 
template <class T>
100
 
struct expected_from_python_type_direct
101
 
{
102
 
    static PyTypeObject const* get_pytype()
103
 
    {
104
 
        return registered<T>::converters.expected_from_python_type();
105
 
    }
106
 
};
107
 
 
108
 
template <class T>
109
 
struct to_python_target_type
110
 
{
111
 
    static PyTypeObject const *get_pytype()
112
 
    {
113
 
        const converter::registration *r=converter::registry::query(
114
 
            detail::unwind_type_id_((boost::type<T>*)0, (mpl::bool_<boost::is_void<T>::value >*)0 )
115
 
            );
116
 
        return r ? r->to_python_target_type(): 0;
117
 
    }
118
 
};
119
 
 
120
 
template <class T>
121
 
struct to_python_target_type_direct
122
 
{
123
 
    static PyTypeObject const *get_pytype()
124
 
    {
125
 
        return registered<T>::converters.to_python_target_type();
126
 
    }
127
 
};
128
 
#endif
129
 
 
130
 
}}} // namespace boost::python
131
 
 
132
 
#endif // WRAP_PYTYPE_NM20070606_HPP