mirror of
https://github.com/boostorg/python.git
synced 2026-01-22 17:32:55 +00:00
More fixes
[SVN r13182]
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
# include <boost/python/object/value_holder_fwd.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/detail/wrap_function.hpp>
|
||||
# include <boost/python/detail/member_function_cast.hpp>
|
||||
# include <boost/mpl/type_list.hpp>
|
||||
# include <boost/python/object/class_converters.hpp>
|
||||
# include <boost/mpl/size.hpp>
|
||||
@@ -103,14 +104,24 @@ class class_ : private objects::class_base
|
||||
// Use function::add_to_namespace to achieve overloading if
|
||||
// appropriate.
|
||||
objects::function::add_to_namespace(
|
||||
this->object(), name, ref(detail::wrap_function(f)));
|
||||
this->object(), name,
|
||||
ref(detail::wrap_function(
|
||||
// This bit of nastiness casts F to a member function of T if possible.
|
||||
detail::member_function_cast<T,F>::stage1(f).stage2((T*)0).stage3(f)
|
||||
)));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Fn, class CallPolicy>
|
||||
self& def(char const* name, Fn fn, CallPolicy policy)
|
||||
{
|
||||
this->def(name, boost::python::make_function(fn, policy));
|
||||
this->def(name
|
||||
, boost::python::make_function(
|
||||
// This bit of nastiness casts F to a member function of T if possible.
|
||||
detail::member_function_cast<T,Fn>::stage1(fn).stage2((T*)0).stage3(fn)
|
||||
, policy)
|
||||
);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
37
include/boost/python/object/find_instance.hpp
Normal file
37
include/boost/python/object/find_instance.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef FIND_INSTANCE_DWA2002312_HPP
|
||||
# define FIND_INSTANCE_DWA2002312_HPP
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
// Given an undecorated type_id, find the instance data which
|
||||
// corresponds to it, or return 0 in case no such type is held.
|
||||
BOOST_PYTHON_DECL void* find_instance_impl(PyObject*, converter::undecorated_type_id_t);
|
||||
|
||||
// This produces a function with the right signature for use in from_python conversions
|
||||
template <class T>
|
||||
struct instance_finder
|
||||
{
|
||||
instance_finder()
|
||||
{
|
||||
converter::registry::insert(&execute, converter::undecorated_type_id<T>());
|
||||
}
|
||||
|
||||
static instance_finder const registration;
|
||||
private:
|
||||
static inline void* execute(PyObject* p)
|
||||
{
|
||||
return find_instance_impl(p, converter::undecorated_type_id<T>());
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
instance_finder<T> const instance_finder<T>::registration;
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // FIND_INSTANCE_DWA2002312_HPP
|
||||
@@ -9,6 +9,7 @@
|
||||
# include <boost/python/object/class.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/object/inheritance.hpp>
|
||||
# include <boost/python/object/find_instance.hpp>
|
||||
# include <boost/ref.hpp>
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
@@ -153,67 +154,88 @@ struct pointer_holder_back_reference : instance_holder
|
||||
|
||||
// Forward construction to the held object
|
||||
pointer_holder_back_reference(PyObject* p)
|
||||
: m_p(new Value(p)) {}
|
||||
: m_p(new BackReferenceType(p)) {
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <class A1>
|
||||
pointer_holder_back_reference(PyObject* p, A1 a1)
|
||||
: m_p(new Value(p
|
||||
: m_p(new BackReferenceType(p
|
||||
, (typename unwrap_reference<A1>::type&)(a1)
|
||||
))
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2>
|
||||
pointer_holder_back_reference(PyObject* p, A1 a1, A2 a2)
|
||||
: m_p(new Value(p
|
||||
: m_p(new BackReferenceType(p
|
||||
, (typename unwrap_reference<A1>::type&)(a1)
|
||||
, (typename unwrap_reference<A2>::type&)(a2)
|
||||
))
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3>
|
||||
pointer_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3)
|
||||
: m_p(new Value(p
|
||||
: m_p(new BackReferenceType(p
|
||||
, (typename unwrap_reference<A1>::type&)(a1)
|
||||
, (typename unwrap_reference<A2>::type&)(a2)
|
||||
, (typename unwrap_reference<A3>::type&)(a3)
|
||||
))
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4>
|
||||
pointer_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4)
|
||||
: m_p(new Value(p
|
||||
: m_p(new BackReferenceType(p
|
||||
, (typename unwrap_reference<A1>::type&)(a1)
|
||||
, (typename unwrap_reference<A2>::type&)(a2)
|
||||
, (typename unwrap_reference<A3>::type&)(a3)
|
||||
, (typename unwrap_reference<A4>::type&)(a4)
|
||||
))
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5>
|
||||
pointer_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
|
||||
: m_p(new Value(p
|
||||
: m_p(new BackReferenceType(p
|
||||
, (typename unwrap_reference<A1>::type&)(a1)
|
||||
, (typename unwrap_reference<A2>::type&)(a2)
|
||||
, (typename unwrap_reference<A3>::type&)(a3)
|
||||
, (typename unwrap_reference<A4>::type&)(a4)
|
||||
, (typename unwrap_reference<A5>::type&)(a5)
|
||||
)) {}
|
||||
)) {
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6>
|
||||
pointer_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
|
||||
: m_p(new Value(p
|
||||
: m_p(new BackReferenceType(p
|
||||
, (typename unwrap_reference<A1>::type&)(a1)
|
||||
, (typename unwrap_reference<A2>::type&)(a2)
|
||||
, (typename unwrap_reference<A3>::type&)(a3)
|
||||
, (typename unwrap_reference<A4>::type&)(a4)
|
||||
, (typename unwrap_reference<A5>::type&)(a5)
|
||||
, (typename unwrap_reference<A6>::type&)(a6)
|
||||
)) {}
|
||||
)) {
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
|
||||
pointer_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
|
||||
: m_p(new Value(p
|
||||
: m_p(new BackReferenceType(p
|
||||
, (typename unwrap_reference<A1>::type&)(a1)
|
||||
, (typename unwrap_reference<A2>::type&)(a2)
|
||||
, (typename unwrap_reference<A3>::type&)(a3)
|
||||
@@ -222,11 +244,14 @@ struct pointer_holder_back_reference : instance_holder
|
||||
, (typename unwrap_reference<A6>::type&)(a6)
|
||||
, (typename unwrap_reference<A7>::type&)(a7)
|
||||
))
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
|
||||
pointer_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
|
||||
: m_p(new Value(p
|
||||
: m_p(new BackReferenceType(p
|
||||
, (typename unwrap_reference<A1>::type&)(a1)
|
||||
, (typename unwrap_reference<A2>::type&)(a2)
|
||||
, (typename unwrap_reference<A3>::type&)(a3)
|
||||
@@ -236,11 +261,14 @@ struct pointer_holder_back_reference : instance_holder
|
||||
, (typename unwrap_reference<A7>::type&)(a7)
|
||||
, (typename unwrap_reference<A8>::type&)(a8)
|
||||
))
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
|
||||
pointer_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
|
||||
: m_p(new Value(p
|
||||
: m_p(new BackReferenceType(p
|
||||
, (typename unwrap_reference<A1>::type&)(a1)
|
||||
, (typename unwrap_reference<A2>::type&)(a2)
|
||||
, (typename unwrap_reference<A3>::type&)(a3)
|
||||
@@ -251,11 +279,14 @@ struct pointer_holder_back_reference : instance_holder
|
||||
, (typename unwrap_reference<A8>::type&)(a8)
|
||||
, (typename unwrap_reference<A9>::type&)(a9)
|
||||
))
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
|
||||
pointer_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10)
|
||||
: m_p(new Value(p
|
||||
: m_p(new BackReferenceType(p
|
||||
, (typename unwrap_reference<A1>::type&)(a1)
|
||||
, (typename unwrap_reference<A2>::type&)(a2)
|
||||
, (typename unwrap_reference<A3>::type&)(a3)
|
||||
@@ -267,7 +298,10 @@ struct pointer_holder_back_reference : instance_holder
|
||||
, (typename unwrap_reference<A9>::type&)(a9)
|
||||
, (typename unwrap_reference<A10>::type&)(a10)
|
||||
))
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(converter::undecorated_type_id_t);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
# include <boost/python/object/class.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/object/inheritance.hpp>
|
||||
# include <boost/python/object/find_instance.hpp>
|
||||
# include <boost/ref.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
@@ -146,14 +147,20 @@ struct value_holder_back_reference : instance_holder
|
||||
{
|
||||
// Forward construction to the held object
|
||||
value_holder_back_reference(PyObject* p)
|
||||
: m_held() {}
|
||||
: m_held() {
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1>
|
||||
value_holder_back_reference(PyObject* p, A1 a1)
|
||||
: m_held(p
|
||||
, (typename unwrap_reference<A1>::type&)(a1)
|
||||
)
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2>
|
||||
value_holder_back_reference(PyObject* p, A1 a1, A2 a2)
|
||||
@@ -161,7 +168,10 @@ struct value_holder_back_reference : instance_holder
|
||||
, (typename unwrap_reference<A1>::type&)(a1)
|
||||
, (typename unwrap_reference<A2>::type&)(a2)
|
||||
)
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3>
|
||||
value_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3)
|
||||
@@ -170,7 +180,10 @@ struct value_holder_back_reference : instance_holder
|
||||
, (typename unwrap_reference<A2>::type&)(a2)
|
||||
, (typename unwrap_reference<A3>::type&)(a3)
|
||||
)
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4>
|
||||
value_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4)
|
||||
@@ -180,7 +193,10 @@ struct value_holder_back_reference : instance_holder
|
||||
, (typename unwrap_reference<A3>::type&)(a3)
|
||||
, (typename unwrap_reference<A4>::type&)(a4)
|
||||
)
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5>
|
||||
value_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
|
||||
@@ -190,7 +206,10 @@ struct value_holder_back_reference : instance_holder
|
||||
, (typename unwrap_reference<A3>::type&)(a3)
|
||||
, (typename unwrap_reference<A4>::type&)(a4)
|
||||
, (typename unwrap_reference<A5>::type&)(a5)
|
||||
) {}
|
||||
) {
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6>
|
||||
value_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
|
||||
@@ -201,7 +220,10 @@ struct value_holder_back_reference : instance_holder
|
||||
, (typename unwrap_reference<A4>::type&)(a4)
|
||||
, (typename unwrap_reference<A5>::type&)(a5)
|
||||
, (typename unwrap_reference<A6>::type&)(a6)
|
||||
) {}
|
||||
) {
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
|
||||
value_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
|
||||
@@ -214,7 +236,10 @@ struct value_holder_back_reference : instance_holder
|
||||
, (typename unwrap_reference<A6>::type&)(a6)
|
||||
, (typename unwrap_reference<A7>::type&)(a7)
|
||||
)
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
|
||||
value_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
|
||||
@@ -228,7 +253,10 @@ struct value_holder_back_reference : instance_holder
|
||||
, (typename unwrap_reference<A7>::type&)(a7)
|
||||
, (typename unwrap_reference<A8>::type&)(a8)
|
||||
)
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
|
||||
value_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
|
||||
@@ -243,7 +271,10 @@ struct value_holder_back_reference : instance_holder
|
||||
, (typename unwrap_reference<A8>::type&)(a8)
|
||||
, (typename unwrap_reference<A9>::type&)(a9)
|
||||
)
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
|
||||
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
|
||||
value_holder_back_reference(PyObject* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10)
|
||||
@@ -259,7 +290,9 @@ struct value_holder_back_reference : instance_holder
|
||||
, (typename unwrap_reference<A9>::type&)(a9)
|
||||
, (typename unwrap_reference<A10>::type&)(a10)
|
||||
)
|
||||
{}
|
||||
{
|
||||
(void)instance_finder<BackReferenceType>::registration;
|
||||
}
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(converter::undecorated_type_id_t);
|
||||
|
||||
@@ -55,6 +55,7 @@ bpl-test try : newtest.py m1.cpp m2.cpp ;
|
||||
bpl-test builtin_converters : test_builtin_converters.py test_builtin_converters.cpp ;
|
||||
bpl-test test_pointer_adoption ;
|
||||
bpl-test callbacks ;
|
||||
bpl-test virtual_functions ;
|
||||
|
||||
# --- unit tests of library components ---
|
||||
unit-test indirect_traits_test
|
||||
|
||||
Reference in New Issue
Block a user