Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:37

0001 // Copyright David Abrahams 2002.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 #ifndef REGISTRATIONS_DWA2002223_HPP
0006 # define REGISTRATIONS_DWA2002223_HPP
0007 
0008 # include <boost/python/detail/prefix.hpp>
0009 
0010 # include <boost/python/type_id.hpp>
0011 
0012 # include <boost/python/converter/convertible_function.hpp>
0013 # include <boost/python/converter/constructor_function.hpp>
0014 # include <boost/python/converter/to_python_function_type.hpp>
0015 
0016 # include <boost/detail/workaround.hpp>
0017 
0018 namespace boost { namespace python { namespace converter { 
0019 
0020 struct lvalue_from_python_chain
0021 {
0022     convertible_function convert;
0023     lvalue_from_python_chain* next;
0024 };
0025 
0026 struct rvalue_from_python_chain
0027 {
0028     convertible_function convertible;
0029     constructor_function construct;
0030     PyTypeObject const* (*expected_pytype)();
0031     rvalue_from_python_chain* next;
0032 };
0033 
0034 struct BOOST_PYTHON_DECL registration
0035 {
0036  public: // member functions
0037     explicit registration(type_info target, bool is_shared_ptr = false);
0038    ~registration();
0039     
0040     // Convert the appropriately-typed data to Python
0041     PyObject* to_python(void const volatile*) const;
0042 
0043     // Return the class object, or raise an appropriate Python
0044     // exception if no class has been registered.
0045     PyTypeObject* get_class_object() const;
0046 
0047     // Return common denominator of the python class objects, 
0048     // convertable to target. Inspects the m_class_object and the value_chains.
0049     PyTypeObject const* expected_from_python_type() const;
0050     PyTypeObject const* to_python_target_type() const;
0051 
0052  public: // data members. So sue me.
0053     const python::type_info target_type;
0054 
0055     // The chain of eligible from_python converters when an lvalue is required
0056     lvalue_from_python_chain* lvalue_chain;
0057 
0058     // The chain of eligible from_python converters when an rvalue is acceptable
0059     rvalue_from_python_chain* rvalue_chain;
0060     
0061     // The class object associated with this type
0062     PyTypeObject* m_class_object;
0063 
0064     // The unique to_python converter for the associated C++ type.
0065     to_python_function_t m_to_python;
0066     PyTypeObject const* (*m_to_python_target_type)();
0067 
0068 
0069     // True iff this type is a shared_ptr.  Needed for special rvalue
0070     // from_python handling.
0071     const bool is_shared_ptr;
0072 
0073 # if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
0074  private:
0075     void operator=(registration); // This is not defined, and just keeps MWCW happy.
0076 # endif 
0077 };
0078 
0079 //
0080 // implementations
0081 //
0082 inline registration::registration(type_info target_type, bool is_shared_ptr)
0083     : target_type(target_type)
0084       , lvalue_chain(0)
0085       , rvalue_chain(0)
0086       , m_class_object(0)
0087       , m_to_python(0)
0088       , m_to_python_target_type(0)
0089       , is_shared_ptr(is_shared_ptr)
0090 {}
0091 
0092 inline bool operator<(registration const& lhs, registration const& rhs)
0093 {
0094     return lhs.target_type < rhs.target_type;
0095 }
0096 
0097 }}} // namespace boost::python::converter
0098 
0099 #endif // REGISTRATIONS_DWA2002223_HPP