|
29 | 29 |
|
30 | 30 | # include <boost/python/detail/overloads_fwd.hpp> |
31 | 31 | # include <boost/python/detail/operator_id.hpp> |
32 | | -# include <boost/python/detail/member_function_cast.hpp> |
33 | 32 | # include <boost/python/detail/def_helper.hpp> |
34 | 33 | # include <boost/python/detail/force_instantiate.hpp> |
35 | 34 |
|
@@ -363,56 +362,28 @@ class class_ : public objects::class_base |
363 | 362 | template <class Get> |
364 | 363 | self& add_property(char const* name, Get fget) |
365 | 364 | { |
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)); |
373 | 366 | return *this; |
374 | 367 | } |
375 | 368 |
|
376 | 369 | template <class Get, class Set> |
377 | 370 | self& add_property(char const* name, Get fget, Set fset) |
378 | 371 | { |
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)); |
388 | 373 | return *this; |
389 | 374 | } |
390 | 375 |
|
391 | 376 | template <class Get> |
392 | 377 | self& add_static_property(char const* name, Get fget) |
393 | 378 | { |
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)); |
401 | 380 | return *this; |
402 | 381 | } |
403 | 382 |
|
404 | 383 | template <class Get, class Set> |
405 | 384 | self& add_static_property(char const* name, Get fget, Set fset) |
406 | 385 | { |
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)); |
416 | 387 | return *this; |
417 | 388 | } |
418 | 389 |
|
@@ -444,6 +415,30 @@ class class_ : public objects::class_base |
444 | 415 | } |
445 | 416 | private: // helper functions |
446 | 417 |
|
| 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 | + |
447 | 442 | template <class D, class B> |
448 | 443 | self& def_readonly_impl( |
449 | 444 | char const* name, D B::*pm_ BOOST_PYTHON_YES_DATA_MEMBER) |
@@ -501,12 +496,16 @@ class class_ : public objects::class_base |
501 | 496 | ) |
502 | 497 | { |
503 | 498 | 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 | + ); |
510 | 509 |
|
511 | 510 | this->def_default(name, fn, helper, mpl::bool_<Helper::has_default_implementation>()); |
512 | 511 | } |
|
0 commit comments