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 REGISTRATIONS_DWA2002223_HPP
6 # define REGISTRATIONS_DWA2002223_HPP
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/python/type_id.hpp>
12 # include <boost/python/converter/convertible_function.hpp>
13 # include <boost/python/converter/constructor_function.hpp>
14 # include <boost/python/converter/to_python_function_type.hpp>
16 # include <boost/detail/workaround.hpp>
18 namespace boost { namespace python { namespace converter {
20 struct lvalue_from_python_chain
22 convertible_function convert;
23 lvalue_from_python_chain* next;
26 struct rvalue_from_python_chain
28 convertible_function convertible;
29 constructor_function construct;
30 PyTypeObject const* (*expected_pytype)();
31 rvalue_from_python_chain* next;
34 struct BOOST_PYTHON_DECL registration
36 public: // member functions
37 explicit registration(type_info target, bool is_shared_ptr = false);
40 // Convert the appropriately-typed data to Python
41 PyObject* to_python(void const volatile*) const;
43 // Return the class object, or raise an appropriate Python
44 // exception if no class has been registered.
45 PyTypeObject* get_class_object() const;
47 // Return common denominator of the python class objects,
48 // convertable to target. Inspects the m_class_object and the value_chains.
49 PyTypeObject const* expected_from_python_type() const;
50 PyTypeObject const* to_python_target_type() const;
52 public: // data members. So sue me.
53 const python::type_info target_type;
55 // The chain of eligible from_python converters when an lvalue is required
56 lvalue_from_python_chain* lvalue_chain;
58 // The chain of eligible from_python converters when an rvalue is acceptable
59 rvalue_from_python_chain* rvalue_chain;
61 // The class object associated with this type
62 PyTypeObject* m_class_object;
64 // The unique to_python converter for the associated C++ type.
65 to_python_function_t m_to_python;
66 PyTypeObject const* (*m_to_python_target_type)();
69 // True iff this type is a shared_ptr. Needed for special rvalue
70 // from_python handling.
71 const bool is_shared_ptr;
73 # if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
75 void operator=(registration); // This is not defined, and just keeps MWCW happy.
82 inline registration::registration(type_info target_type, bool is_shared_ptr)
83 : target_type(target_type)
88 , m_to_python_target_type(0)
89 , is_shared_ptr(is_shared_ptr)
92 inline bool operator<(registration const& lhs, registration const& rhs)
94 return lhs.target_type < rhs.target_type;
97 }}} // namespace boost::python::converter
99 #endif // REGISTRATIONS_DWA2002223_HPP