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 REGISTRATIONS_DWA2002223_HPP
|
sl@0
|
6 |
# define REGISTRATIONS_DWA2002223_HPP
|
sl@0
|
7 |
|
sl@0
|
8 |
# include <boost/python/detail/prefix.hpp>
|
sl@0
|
9 |
|
sl@0
|
10 |
# include <boost/python/type_id.hpp>
|
sl@0
|
11 |
|
sl@0
|
12 |
# include <boost/python/converter/convertible_function.hpp>
|
sl@0
|
13 |
# include <boost/python/converter/constructor_function.hpp>
|
sl@0
|
14 |
# include <boost/python/converter/to_python_function_type.hpp>
|
sl@0
|
15 |
|
sl@0
|
16 |
# include <boost/detail/workaround.hpp>
|
sl@0
|
17 |
|
sl@0
|
18 |
namespace boost { namespace python { namespace converter {
|
sl@0
|
19 |
|
sl@0
|
20 |
struct lvalue_from_python_chain
|
sl@0
|
21 |
{
|
sl@0
|
22 |
convertible_function convert;
|
sl@0
|
23 |
lvalue_from_python_chain* next;
|
sl@0
|
24 |
};
|
sl@0
|
25 |
|
sl@0
|
26 |
struct rvalue_from_python_chain
|
sl@0
|
27 |
{
|
sl@0
|
28 |
convertible_function convertible;
|
sl@0
|
29 |
constructor_function construct;
|
sl@0
|
30 |
rvalue_from_python_chain* next;
|
sl@0
|
31 |
};
|
sl@0
|
32 |
|
sl@0
|
33 |
struct BOOST_PYTHON_DECL registration
|
sl@0
|
34 |
{
|
sl@0
|
35 |
public: // member functions
|
sl@0
|
36 |
explicit registration(type_info target, bool is_shared_ptr = false);
|
sl@0
|
37 |
|
sl@0
|
38 |
// Convert the appropriately-typed data to Python
|
sl@0
|
39 |
PyObject* to_python(void const volatile*) const;
|
sl@0
|
40 |
|
sl@0
|
41 |
// Return the class object, or raise an appropriate Python
|
sl@0
|
42 |
// exception if no class has been registered.
|
sl@0
|
43 |
PyTypeObject* get_class_object() const;
|
sl@0
|
44 |
|
sl@0
|
45 |
public: // data members. So sue me.
|
sl@0
|
46 |
const python::type_info target_type;
|
sl@0
|
47 |
|
sl@0
|
48 |
// The chain of eligible from_python converters when an lvalue is required
|
sl@0
|
49 |
lvalue_from_python_chain* lvalue_chain;
|
sl@0
|
50 |
|
sl@0
|
51 |
// The chain of eligible from_python converters when an rvalue is acceptable
|
sl@0
|
52 |
rvalue_from_python_chain* rvalue_chain;
|
sl@0
|
53 |
|
sl@0
|
54 |
// The class object associated with this type
|
sl@0
|
55 |
PyTypeObject* m_class_object;
|
sl@0
|
56 |
|
sl@0
|
57 |
// The unique to_python converter for the associated C++ type.
|
sl@0
|
58 |
to_python_function_t m_to_python;
|
sl@0
|
59 |
|
sl@0
|
60 |
// True iff this type is a shared_ptr. Needed for special rvalue
|
sl@0
|
61 |
// from_python handling.
|
sl@0
|
62 |
const bool is_shared_ptr;
|
sl@0
|
63 |
|
sl@0
|
64 |
# if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
|
sl@0
|
65 |
private:
|
sl@0
|
66 |
void operator=(registration); // This is not defined, and just keeps MWCW happy.
|
sl@0
|
67 |
# endif
|
sl@0
|
68 |
};
|
sl@0
|
69 |
|
sl@0
|
70 |
//
|
sl@0
|
71 |
// implementations
|
sl@0
|
72 |
//
|
sl@0
|
73 |
inline registration::registration(type_info target_type, bool is_shared_ptr)
|
sl@0
|
74 |
: target_type(target_type)
|
sl@0
|
75 |
, lvalue_chain(0)
|
sl@0
|
76 |
, rvalue_chain(0)
|
sl@0
|
77 |
, m_class_object(0)
|
sl@0
|
78 |
, m_to_python(0)
|
sl@0
|
79 |
, is_shared_ptr(is_shared_ptr)
|
sl@0
|
80 |
{}
|
sl@0
|
81 |
|
sl@0
|
82 |
inline bool operator<(registration const& lhs, registration const& rhs)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
return lhs.target_type < rhs.target_type;
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
}}} // namespace boost::python::converter
|
sl@0
|
88 |
|
sl@0
|
89 |
#endif // REGISTRATIONS_DWA2002223_HPP
|