Update contrib.
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 EXTRACT_DWA200265_HPP
6 # define EXTRACT_DWA200265_HPP
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/python/converter/object_manager.hpp>
11 # include <boost/python/converter/from_python.hpp>
12 # include <boost/python/converter/rvalue_from_python_data.hpp>
13 # include <boost/python/converter/registered.hpp>
14 # include <boost/python/converter/registered_pointee.hpp>
16 # include <boost/python/object_core.hpp>
17 # include <boost/python/refcount.hpp>
19 # include <boost/python/detail/copy_ctor_mutates_rhs.hpp>
20 # include <boost/python/detail/void_ptr.hpp>
21 # include <boost/python/detail/void_return.hpp>
22 # include <boost/utility.hpp>
23 # include <boost/call_traits.hpp>
25 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) || BOOST_WORKAROUND(BOOST_INTEL_WIN, <= 900)
26 // workaround for VC++ 6.x or 7.0
27 # define BOOST_EXTRACT_WORKAROUND ()
29 # define BOOST_EXTRACT_WORKAROUND
32 namespace boost { namespace python {
42 struct extract_pointer
44 typedef Ptr result_type;
45 extract_pointer(PyObject*);
48 Ptr operator()() const;
56 struct extract_reference
58 typedef Ref result_type;
59 extract_reference(PyObject*);
62 Ref operator()() const;
70 struct extract_rvalue : private noncopyable
72 typedef typename mpl::if_<
73 python::detail::copy_ctor_mutates_rhs<T>
75 , typename call_traits<T>::param_type
78 extract_rvalue(PyObject*);
81 result_type operator()() const;
84 mutable rvalue_from_python_data<T> m_data;
88 struct extract_object_manager
90 typedef T result_type;
91 extract_object_manager(PyObject*);
94 result_type operator()() const;
100 struct select_extract
102 BOOST_STATIC_CONSTANT(
103 bool, obj_mgr = is_object_manager<T>::value);
105 BOOST_STATIC_CONSTANT(
106 bool, ptr = is_pointer<T>::value);
108 BOOST_STATIC_CONSTANT(
109 bool, ref = is_reference<T>::value);
111 typedef typename mpl::if_c<
113 , extract_object_manager<T>
114 , typename mpl::if_c<
117 , typename mpl::if_c<
119 , extract_reference<T>
129 : converter::select_extract<T>::type
132 typedef typename converter::select_extract<T>::type base;
134 typedef typename base::result_type result_type;
136 operator result_type() const
142 extract(api::object const&);
149 inline extract<T>::extract(PyObject* o)
155 inline extract<T>::extract(api::object const& o)
163 inline extract_rvalue<T>::extract_rvalue(PyObject* x)
166 (rvalue_from_python_stage1)(x, registered<T>::converters)
173 extract_rvalue<T>::check() const
175 return m_data.stage1.convertible;
179 inline typename extract_rvalue<T>::result_type
180 extract_rvalue<T>::operator()() const
183 // Only do the stage2 conversion once
184 m_data.stage1.convertible == m_data.storage.bytes
185 ? m_data.storage.bytes
186 : (rvalue_from_python_stage2)(m_source, m_data.stage1, registered<T>::converters)
191 inline extract_reference<Ref>::extract_reference(PyObject* obj)
194 (get_lvalue_from_python)(obj, registered<Ref>::converters)
200 inline bool extract_reference<Ref>::check() const
202 return m_result != 0;
206 inline Ref extract_reference<Ref>::operator()() const
209 (throw_no_reference_from_python)(m_source, registered<Ref>::converters);
211 return python::detail::void_ptr_to_reference(m_result, (Ref(*)())0);
215 inline extract_pointer<Ptr>::extract_pointer(PyObject* obj)
218 obj == Py_None ? 0 : (get_lvalue_from_python)(obj, registered_pointee<Ptr>::converters)
224 inline bool extract_pointer<Ptr>::check() const
226 return m_source == Py_None || m_result != 0;
230 inline Ptr extract_pointer<Ptr>::operator()() const
232 if (m_result == 0 && m_source != Py_None)
233 (throw_no_pointer_from_python)(m_source, registered_pointee<Ptr>::converters);
235 return Ptr(m_result);
239 inline extract_object_manager<T>::extract_object_manager(PyObject* obj)
245 inline bool extract_object_manager<T>::check() const
247 return object_manager_traits<T>::check(m_source);
251 inline T extract_object_manager<T>::operator()() const
254 object_manager_traits<T>::adopt(python::incref(m_source))
259 }} // namespace boost::python::converter
261 #endif // EXTRACT_DWA200265_HPP