Skip to content

Commit b3910f4

Browse files
committed
Support for wrapping function objects and classes which use virtual
inheritance. Completely killed off member_function_cast! [SVN r19945]
1 parent 4a7b8fe commit b3910f4

10 files changed

Lines changed: 339 additions & 374 deletions

include/boost/python/class.hpp

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
# include <boost/python/detail/overloads_fwd.hpp>
3131
# include <boost/python/detail/operator_id.hpp>
32-
# include <boost/python/detail/member_function_cast.hpp>
3332
# include <boost/python/detail/def_helper.hpp>
3433
# include <boost/python/detail/force_instantiate.hpp>
3534

@@ -363,56 +362,28 @@ class class_ : public objects::class_base
363362
template <class Get>
364363
self& add_property(char const* name, Get fget)
365364
{
366-
base::add_property(
367-
name
368-
, object(
369-
detail::member_function_cast<T,Get>::stage1(fget).stage2((T*)0).stage3(fget)
370-
)
371-
);
372-
365+
base::add_property(name, make_fn(fget));
373366
return *this;
374367
}
375368

376369
template <class Get, class Set>
377370
self& add_property(char const* name, Get fget, Set fset)
378371
{
379-
base::add_property(
380-
name
381-
, object(
382-
detail::member_function_cast<T,Get>::stage1(fget).stage2((T*)0).stage3(fget)
383-
)
384-
, object(
385-
detail::member_function_cast<T,Set>::stage1(fset).stage2((T*)0).stage3(fset)
386-
)
387-
);
372+
base::add_property(name, make_fn(fget), make_fn(fset));
388373
return *this;
389374
}
390375

391376
template <class Get>
392377
self& add_static_property(char const* name, Get fget)
393378
{
394-
base::add_static_property(
395-
name
396-
, object(
397-
detail::member_function_cast<T,Get>::stage1(fget).stage2((T*)0).stage3(fget)
398-
)
399-
);
400-
379+
base::add_static_property(name, object(fget));
401380
return *this;
402381
}
403382

404383
template <class Get, class Set>
405384
self& add_static_property(char const* name, Get fget, Set fset)
406385
{
407-
base::add_static_property(
408-
name
409-
, object(
410-
detail::member_function_cast<T,Get>::stage1(fget).stage2((T*)0).stage3(fget)
411-
)
412-
, object(
413-
detail::member_function_cast<T,Set>::stage1(fset).stage2((T*)0).stage3(fset)
414-
)
415-
);
386+
base::add_static_property(name, object(fget), object(fset));
416387
return *this;
417388
}
418389

@@ -444,6 +415,30 @@ class class_ : public objects::class_base
444415
}
445416
private: // helper functions
446417

418+
419+
// Builds a method for this class around the given [member]
420+
// function pointer or object, appropriately adjusting the type of
421+
// the first signature argument so that if f is a member of a
422+
// (possibly not wrapped) base class of T, an lvalue argument of
423+
// type T will be required.
424+
//
425+
// {
426+
template <class F>
427+
object make_fn(F const& f)
428+
{
429+
return make_function(f, default_call_policies(), detail::get_signature(f, (T*)0));
430+
}
431+
432+
object
433+
# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
434+
const&
435+
# endif
436+
make_fn(object const& x)
437+
{
438+
return x;
439+
}
440+
// }
441+
447442
template <class D, class B>
448443
self& def_readonly_impl(
449444
char const* name, D B::*pm_ BOOST_PYTHON_YES_DATA_MEMBER)
@@ -501,12 +496,16 @@ class class_ : public objects::class_base
501496
)
502497
{
503498
objects::add_to_namespace(
504-
*this, name,
505-
make_function(
506-
// This bit of nastiness casts F to a member function of T if possible.
507-
detail::member_function_cast<T,Fn>::stage1(fn).stage2((T*)0).stage3(fn)
508-
, helper.policies(), helper.keywords())
509-
, helper.doc());
499+
*this
500+
, name
501+
, make_function(
502+
fn
503+
, helper.policies()
504+
, helper.keywords()
505+
, detail::get_signature(fn, (T*)0)
506+
)
507+
, helper.doc()
508+
);
510509

511510
this->def_default(name, fn, helper, mpl::bool_<Helper::has_default_implementation>());
512511
}

0 commit comments

Comments
 (0)