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