3838# include < boost/python/object/add_to_namespace.hpp>
3939# include < boost/python/object/class_converters.hpp>
4040
41- # include < boost/python/detail/string_literal.hpp>
4241# include < boost/python/detail/overloads_fwd.hpp>
4342# include < boost/python/detail/operator_id.hpp>
4443# include < boost/python/detail/member_function_cast.hpp>
5958
6059namespace boost { namespace python {
6160
62- enum no_init_t { no_init } ;
61+ template < class DerivedVisitor > struct def_visitor ;
6362
64- struct def_arg_base {};
65- template <class Derived >
66- struct def_arg : def_arg_base {}; // Generic visitor
63+ enum no_init_t { no_init };
6764
6865namespace detail
6966{
@@ -90,9 +87,6 @@ namespace detail
9087 template <class T1 , class T2 , class T3 >
9188 struct has_noncopyable ;
9289
93- template <detail::operator_id, class L , class R >
94- struct operator_ ;
95-
9690 // Register to_python converters for a class T. The first argument
9791 // will be mpl::true_ unless noncopyable was specified as a
9892 // class_<...> template parameter. The 2nd argument is a pointer to
@@ -249,7 +243,7 @@ class class_ : public objects::class_base
249243 : base(name, id_vector::size, id_vector().ids)
250244 {
251245 this ->register_ ();
252- define_init (* this , i. derived () );
246+ this -> def (i );
253247 this ->set_instance_size (holder_selector::additional_size ());
254248 }
255249
@@ -259,26 +253,18 @@ class class_ : public objects::class_base
259253 : base(name, id_vector::size, id_vector().ids, doc)
260254 {
261255 this ->register_ ();
262- define_init (* this , i. derived () );
256+ this -> def (i );
263257 this ->set_instance_size (holder_selector::additional_size ());
264258 }
265259
266260 public: // member functions
267261
268- // Define additional constructors
269- template <class DerivedT >
270- self& def (init_base<DerivedT> const & i)
271- {
272- define_init (*this , i.derived ());
273- return *this ;
274- }
275-
276262 // Generic visitation
277263 template <class Derived >
278- self& def (def_arg <Derived> const & visitor)
264+ self& def (def_visitor <Derived> const & visitor)
279265 {
280- static_cast <Derived const &>( visitor) .visit (*this );
281- return *this ;
266+ visitor.visit (*this );
267+ return *this ;
282268 }
283269
284270 // Wrap a member function or a non-member function which can take
@@ -324,13 +310,6 @@ class class_ : public objects::class_base
324310 return *this ;
325311 }
326312
327- template <detail::operator_id id, class L , class R >
328- self& def (detail::operator_<id,L,R> const & op)
329- {
330- typedef detail::operator_<id,L,R> op_t ;
331- return this ->def (op.name (), &op_t ::template apply<T>::execute);
332- }
333-
334313 //
335314 // Data member access
336315 //
@@ -476,42 +455,27 @@ class class_ : public objects::class_base
476455 inline void register_ () const ;
477456
478457 //
479- // These three overloads discriminate between def() as applied to
480- // things which are already wrapped into callable python::object
481- // instances, a generic visitor, and everything else.
458+ // These two overloads discriminate between def() as applied to a
459+ // generic visitor and everything else.
482460 //
483- template <class F , class A1 >
461+ template <class Helper , class LeafVisitor , class Visitor >
484462 inline void def_impl (
485463 char const * name
486- , F f
487- , detail::def_helper<A1> const & helper
488- , object const *)
464+ , LeafVisitor
465+ , Helper const & helper
466+ , def_visitor<Visitor> const * v
467+ )
489468 {
490- // It's too late to specify anything other than docstrings, if
491- // the callable object is already wrapped.
492- BOOST_STATIC_ASSERT (
493- (is_same<char const *,A1>::value
494- || detail::is_string_literal<A1>::value));
495-
496- objects::add_to_namespace (*this , name, f, helper.doc ());
469+ v->visit (*this , name, helper);
497470 }
498471
499- template <class Derived , class A1 >
500- inline void def_impl (
501- char const * name
502- , def_arg<Derived> const & visitor
503- , detail::def_helper<A1> const & helper
504- , def_arg_base const *)
505- {
506- static_cast <Derived const &>(visitor).visit (*this , name);
507- }
508-
509472 template <class Fn , class Helper >
510473 inline void def_impl (
511474 char const * name
512- , Fn fn
513- , Helper const & helper
514- , ...)
475+ , Fn fn
476+ , Helper const & helper
477+ , ...
478+ )
515479 {
516480 objects::add_to_namespace (
517481 *this , name,
@@ -578,9 +542,11 @@ class class_ : public objects::class_base
578542 , ...)
579543 {
580544 this ->def_impl (
581- name, fn
582- , detail::def_helper<A1>(a1)
583- , &fn);
545+ name
546+ , fn
547+ , detail::def_helper<A1>(a1)
548+ , &fn
549+ );
584550
585551 }
586552};
0 commit comments