2929# include < boost/python/object/add_to_namespace.hpp>
3030# include < boost/python/detail/def_helper.hpp>
3131# include < boost/python/detail/force_instantiate.hpp>
32+ # include < boost/python/detail/defaults_def.hpp>
33+ # include < boost/python/signature.hpp>
3234
33- namespace boost { namespace python {
35+ namespace boost { namespace python {
3436
3537namespace detail
3638{
3739 struct write_type_id ;
38-
40+
3941 template <class T , class Prev = detail::not_specified>
4042 struct select_held_type ;
41-
43+
4244 template <class T1 , class T2 , class T3 >
4345 struct has_noncopyable ;
4446
@@ -83,21 +85,21 @@ class class_ : public objects::class_base
8385
8486 typedef class_<T,X1 ,X2 ,X3 > self;
8587 BOOST_STATIC_CONSTANT (bool , is_copyable = (!detail::has_noncopyable<X1 ,X2 ,X3 >::value));
86-
88+
8789 typedef typename detail::select_held_type<
8890 X1 , typename detail::select_held_type<
8991 X2 , typename detail::select_held_type<
9092 X3
9193 >::type>::type>::type held_type;
92-
94+
9395 typedef objects::class_id class_id;
94-
96+
9597 typedef typename detail::select_bases<X1
9698 , typename detail::select_bases<X2
9799 , typename boost::python::detail::select_bases<X3 >::type
98100 >::type
99101 >::type bases;
100-
102+
101103 // A helper class which will contain an array of id objects to be
102104 // passed to the base class constructor
103105 struct id_vector
@@ -107,12 +109,12 @@ class class_ : public objects::class_base
107109 {
108110 // Stick the derived class id into the first element of the array
109111 ids[0 ] = type_id<T>();
110-
112+
111113 // Write the rest of the elements into succeeding positions.
112114 class_id* p = ids + 1 ;
113115 mpl::for_each<bases, void , detail::write_type_id>::execute (&p);
114116 }
115-
117+
116118 BOOST_STATIC_CONSTANT (
117119 std::size_t , size = mpl::size<bases>::value + 1 );
118120 class_id ids[size];
@@ -124,13 +126,13 @@ class class_ : public objects::class_base
124126 // compilers because type_info::name is sometimes mangled (gcc)
125127 class_ (); // With default-constructor init function
126128 class_ (no_init_t ); // With no init function
127-
129+
128130 // Construct with the class name, with or without docstring, and default init() function
129131 class_ (char const * name, char const * doc = 0 );
130132
131133 // Construct with class name, no docstring, and no init() function
132134 class_ (char const * name, no_init_t );
133-
135+
134136 // Construct with class name, docstring, and no init() function
135137 class_ (char const * name, char const * doc, no_init_t );
136138
@@ -141,16 +143,16 @@ class class_ : public objects::class_base
141143 this ->register_ ();
142144 this ->def_init (InitArgs ());
143145 }
144-
145-
146+
147+
146148 template <class InitArgs >
147149 inline class_ (char const * name, char const * doc, detail::args_base<InitArgs> const &, char const * initdoc = 0 )
148150 : base(name, id_vector::size, id_vector().ids, doc)
149151 {
150152 this ->register_ ();
151153 this ->def_init (InitArgs (), initdoc);
152154 }
153-
155+
154156 // Wrap a member function or a non-member function which can take
155157 // a T, T cv&, or T cv* as its first parameter, or a callable
156158 // python object.
@@ -161,14 +163,10 @@ class class_ : public objects::class_base
161163 return *this ;
162164 }
163165
164- template <class Fn , class CallPolicyOrDoc >
165- self& def (char const * name, Fn fn, CallPolicyOrDoc const & policy_or_doc , char const * doc = 0 )
166+ template <class Arg1T , class Arg2T >
167+ self& def (char const * name, Arg1T arg1, Arg2T const & arg2 , char const * doc = 0 )
166168 {
167- typedef detail::def_helper<CallPolicyOrDoc> helper;
168-
169- this ->def_impl (
170- name, fn, helper::get_policy (policy_or_doc), helper::get_doc (policy_or_doc, doc), &fn);
171-
169+ dispatch_def (name, arg1, arg2, doc, &arg2);
172170 return *this ;
173171 }
174172
@@ -178,7 +176,7 @@ class class_ : public objects::class_base
178176 typedef detail::operator_<id,L,R> op_t ;
179177 return this ->def (op.name (), &op_t ::template apply<T>::execute);
180178 }
181-
179+
182180 // Define the constructor with the given Args, which should be an
183181 // MPL sequence of types.
184182 template <class Args >
@@ -196,7 +194,7 @@ class class_ : public objects::class_base
196194 self& def_init (Args const &, CallPolicyOrDoc const & policy_or_doc, char const * doc = 0 )
197195 {
198196 typedef detail::def_helper<CallPolicyOrDoc> helper;
199-
197+
200198 return this ->def (
201199 " __init__" ,
202200 python::make_constructor<Args>(
@@ -265,7 +263,7 @@ class class_ : public objects::class_base
265263 objects::add_to_namespace (
266264 *this , name,
267265 make_function (
268- // This bit of nastiness casts F to a member function of T if possible.
266+ // This bit of nastiness casts F to a member function of T if possible.
269267 detail::member_function_cast<T,Fn>::stage1 (fn).stage2 ((T*)0 ).stage3 (fn)
270268 , policies)
271269 , doc);
@@ -279,6 +277,34 @@ class class_ : public objects::class_base
279277 }
280278
281279 inline void register_ () const ;
280+
281+ template <class Fn , class CallPolicyOrDoc >
282+ void dispatch_def (
283+ char const * name,
284+ Fn fn,
285+ CallPolicyOrDoc const & policy_or_doc,
286+ char const * doc,
287+ void const *)
288+ {
289+ typedef detail::def_helper<CallPolicyOrDoc> helper;
290+
291+ this ->def_impl (
292+ name, fn, helper::get_policy (policy_or_doc), helper::get_doc (policy_or_doc, doc), &fn);
293+
294+ }
295+
296+ template <typename StubsT, typename SigT>
297+ void dispatch_def (
298+ char const * name,
299+ SigT sig,
300+ StubsT const & stubs,
301+ char const * doc,
302+ detail::func_stubs_base const *)
303+ {
304+ // convert sig to a type_list (see detail::get_signature in signature.hpp)
305+ // before calling detail::define_with_defaults.
306+ detail::define_with_defaults (name, stubs, *this , detail::get_signature (sig), doc);
307+ }
282308};
283309
284310
@@ -290,7 +316,7 @@ template <class T, class X1, class X2, class X3>
290316inline void class_<T,X1 ,X2 ,X3 >::register_() const
291317{
292318 objects::register_class_from_python<T,bases>();
293-
319+
294320 detail::register_copy_constructor<T>(
295321 mpl::bool_t <is_copyable>()
296322 , objects::select_holder<T,held_type>((held_type*)0 ).get ()
0 commit comments