Chris@16: // Copyright David Abrahams 2002. Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: #ifndef REGISTRATIONS_DWA2002223_HPP Chris@16: # define REGISTRATIONS_DWA2002223_HPP Chris@16: Chris@16: # include Chris@16: Chris@16: # include Chris@16: Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: Chris@16: # include Chris@16: Chris@16: namespace boost { namespace python { namespace converter { Chris@16: Chris@16: struct lvalue_from_python_chain Chris@16: { Chris@16: convertible_function convert; Chris@16: lvalue_from_python_chain* next; Chris@16: }; Chris@16: Chris@16: struct rvalue_from_python_chain Chris@16: { Chris@16: convertible_function convertible; Chris@16: constructor_function construct; Chris@16: PyTypeObject const* (*expected_pytype)(); Chris@16: rvalue_from_python_chain* next; Chris@16: }; Chris@16: Chris@16: struct BOOST_PYTHON_DECL registration Chris@16: { Chris@16: public: // member functions Chris@16: explicit registration(type_info target, bool is_shared_ptr = false); Chris@16: ~registration(); Chris@16: Chris@16: // Convert the appropriately-typed data to Python Chris@16: PyObject* to_python(void const volatile*) const; Chris@16: Chris@16: // Return the class object, or raise an appropriate Python Chris@16: // exception if no class has been registered. Chris@16: PyTypeObject* get_class_object() const; Chris@16: Chris@16: // Return common denominator of the python class objects, Chris@16: // convertable to target. Inspects the m_class_object and the value_chains. Chris@16: PyTypeObject const* expected_from_python_type() const; Chris@16: PyTypeObject const* to_python_target_type() const; Chris@16: Chris@16: public: // data members. So sue me. Chris@16: const python::type_info target_type; Chris@16: Chris@16: // The chain of eligible from_python converters when an lvalue is required Chris@16: lvalue_from_python_chain* lvalue_chain; Chris@16: Chris@16: // The chain of eligible from_python converters when an rvalue is acceptable Chris@16: rvalue_from_python_chain* rvalue_chain; Chris@16: Chris@16: // The class object associated with this type Chris@16: PyTypeObject* m_class_object; Chris@16: Chris@16: // The unique to_python converter for the associated C++ type. Chris@16: to_python_function_t m_to_python; Chris@16: PyTypeObject const* (*m_to_python_target_type)(); Chris@16: Chris@16: Chris@16: // True iff this type is a shared_ptr. Needed for special rvalue Chris@16: // from_python handling. Chris@16: const bool is_shared_ptr; Chris@16: Chris@16: # if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) Chris@16: private: Chris@16: void operator=(registration); // This is not defined, and just keeps MWCW happy. Chris@16: # endif Chris@16: }; Chris@16: Chris@16: // Chris@16: // implementations Chris@16: // Chris@16: inline registration::registration(type_info target_type, bool is_shared_ptr) Chris@16: : target_type(target_type) Chris@16: , lvalue_chain(0) Chris@16: , rvalue_chain(0) Chris@16: , m_class_object(0) Chris@16: , m_to_python(0) Chris@16: , m_to_python_target_type(0) Chris@16: , is_shared_ptr(is_shared_ptr) Chris@16: {} Chris@16: Chris@16: inline bool operator<(registration const& lhs, registration const& rhs) Chris@16: { Chris@16: return lhs.target_type < rhs.target_type; Chris@16: } Chris@16: Chris@16: }}} // namespace boost::python::converter Chris@16: Chris@16: #endif // REGISTRATIONS_DWA2002223_HPP