Warning, file /include/boost/python/lvalue_from_pytype.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005 #ifndef LVALUE_FROM_PYTYPE_DWA2002130_HPP
0006 # define LVALUE_FROM_PYTYPE_DWA2002130_HPP
0007
0008 # include <boost/python/detail/prefix.hpp>
0009 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
0010 # include <boost/python/converter/pytype_function.hpp>
0011 #endif
0012
0013 # include <boost/python/type_id.hpp>
0014 # include <boost/python/converter/registry.hpp>
0015 # include <boost/python/detail/void_ptr.hpp>
0016 # include <boost/python/detail/type_traits.hpp>
0017
0018 namespace boost { namespace python {
0019
0020 namespace detail
0021 {
0022
0023
0024 template <class T, class U>
0025 inline type_info extractor_type_id(T&(*)(U))
0026 {
0027 return type_id<T>();
0028 }
0029
0030
0031
0032
0033
0034 template <class Extractor, class U>
0035 struct normalized_extractor
0036 {
0037 static inline void* execute(PyObject* op)
0038 {
0039 typedef typename add_lvalue_reference<U>::type param;
0040 return &Extractor::execute(
0041 boost::python::detail::void_ptr_to_reference(
0042 op, (param(*)())0 )
0043 );
0044 }
0045 };
0046
0047
0048
0049
0050
0051
0052 template <class Extractor, class T, class U>
0053 inline normalized_extractor<Extractor,U>
0054 normalize(T(*)(U), Extractor* = 0)
0055 {
0056 return normalized_extractor<Extractor, U>();
0057 }
0058 }
0059
0060
0061
0062 template <class InstanceType, class MemberType, MemberType (InstanceType::*member)>
0063 struct extract_member
0064 {
0065 static MemberType& execute(InstanceType& c)
0066 {
0067 (void)Py_TYPE(&c);
0068 return c.*member;
0069 }
0070 };
0071
0072
0073
0074 template <class InstanceType>
0075 struct extract_identity
0076 {
0077 static InstanceType& execute(InstanceType& c)
0078 {
0079 (void)Py_TYPE(&c);
0080 return c;
0081 }
0082 };
0083
0084
0085
0086
0087 template <class Extractor, PyTypeObject const* python_type>
0088 struct lvalue_from_pytype
0089 {
0090 lvalue_from_pytype()
0091 {
0092 converter::registry::insert
0093 ( &extract
0094 , detail::extractor_type_id(&Extractor::execute)
0095 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
0096 , &get_pytype
0097 #endif
0098 );
0099 }
0100 private:
0101 static void* extract(PyObject* op)
0102 {
0103 return PyObject_TypeCheck(op, const_cast<PyTypeObject*>(python_type))
0104 ? const_cast<void*>(
0105 static_cast<void const volatile*>(
0106 detail::normalize<Extractor>(&Extractor::execute).execute(op)))
0107 : 0
0108 ;
0109 }
0110 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
0111 static PyTypeObject const*get_pytype() { return python_type; }
0112 #endif
0113 };
0114
0115 }}
0116
0117 #endif