2727# include < boost/python/object/pickle_support.hpp>
2828# include < boost/python/make_function.hpp>
2929# include < boost/python/object/add_to_namespace.hpp>
30+ # include < boost/python/detail/def_helper.hpp>
3031
3132namespace boost { namespace python {
3233
@@ -57,7 +58,7 @@ namespace detail
5758 template <class T , class Holder >
5859 static inline void register_copy_constructor (mpl::bool_t <false > const &, Holder*, object const &, T* = 0 )
5960 {
60- }
61+ }
6162}
6263
6364//
@@ -93,7 +94,7 @@ class class_ : public objects::class_base
9394 // Construct with the class name. [ Would have used a default
9495 // argument but gcc-2.95.2 choked on typeid(T).name() as a default
9596 // parameter value]
96- class_ (char const * name);
97+ class_ (char const * name, char const * doc = 0 );
9798
9899
99100 // Wrap a member function or a non-member function which can take
@@ -102,27 +103,25 @@ class class_ : public objects::class_base
102103 template <class F >
103104 self& def (char const * name, F f)
104105 {
105- this ->def_impl (name, f, 0 , &f);
106+ this ->def_impl (name, f, default_call_policies (), 0 , &f);
106107 return *this ;
107108 }
108109
109- template <class Fn , class CallPolicy >
110- self& def (char const * name, Fn fn, CallPolicy policy )
110+ template <class Fn , class CallPolicyOrDoc >
111+ self& def (char const * name, Fn fn, CallPolicyOrDoc const & policy_or_doc, char const * doc = 0 )
111112 {
112- return this -> def (name
113- , boost::python::make_function (
114- // This bit of nastiness casts F to a member function of T if possible.
115- detail::member_function_cast<T,Fn>:: stage1 (fn). stage2 ((T*) 0 ). stage3 ( fn)
116- , policy)
117- ) ;
113+ typedef detail::def_helper<CallPolicyOrDoc> helper;
114+
115+ this -> def_impl (
116+ name, fn, helper::get_policy (policy_or_doc), helper::get_doc (policy_or_doc, doc), & fn);
117+
118+ return * this ;
118119 }
119120
120121 template <detail::operator_id id, class L , class R >
121122 self& def (detail::operator_<id,L,R> const & op)
122123 {
123124 typedef detail::operator_<id,L,R> op_t ;
124- // Use function::add_to_namespace to achieve overloading if
125- // appropriate.
126125 return this ->def (op.name (), &op_t ::template apply<T>::execute);
127126 }
128127
@@ -139,15 +138,19 @@ class class_ : public objects::class_base
139138 );
140139 }
141140
142- template <class Args , class CallPolicy >
143- self& def_init (Args const &, CallPolicy policy )
141+ template <class Args , class CallPolicyOrDoc >
142+ self& def_init (Args const &, CallPolicyOrDoc const & policy_or_doc, char const * doc = 0 )
144143 {
145- return this ->def (" __init__" ,
144+ typedef detail::def_helper<CallPolicyOrDoc> helper;
145+
146+ return this ->def (
147+ " __init__" ,
146148 python::make_constructor<Args>(
147- policy
149+ helper::get_policy (policy_or_doc)
148150 // Using runtime type selection works around a CWPro7 bug.
149151 , objects::select_holder<T,held_type>((held_type*)0 ).get ()
150152 )
153+ , helper::get_doc (policy_or_doc, doc)
151154 );
152155 }
153156
@@ -201,22 +204,26 @@ class class_ : public objects::class_base
201204
202205 private: // helper functions
203206
204- template <class F >
205- inline void def_impl (char const * name, F const & f, char const * doc, ...)
207+ template <class Fn , class Policies >
208+ inline void def_impl (char const * name, Fn fn, Policies const & policies
209+ , char const * doc, ...)
206210 {
207211 objects::add_to_namespace (
208- *this , name, make_function (
212+ *this , name,
213+ make_function (
209214 // This bit of nastiness casts F to a member function of T if possible.
210- detail::member_function_cast<T,F>::stage1 (f).stage2 ((T*)0 ).stage3 (f))
215+ detail::member_function_cast<T,Fn>::stage1 (fn).stage2 ((T*)0 ).stage3 (fn)
216+ , policies)
211217 , doc);
212218 }
213219
214220 template <class F >
215- inline void def_impl (char const * name, F const & f, char const * doc, object const volatile *)
221+ inline void def_impl (char const * name, F f, default_call_policies const &
222+ , char const * doc, object const *)
216223 {
217224 objects::add_to_namespace (*this , name, f, doc);
218225 }
219-
226+
220227 private: // types
221228 typedef objects::class_id class_id;
222229
@@ -266,8 +273,8 @@ inline class_<T,X1,X2,X3>::class_()
266273}
267274
268275template <class T , class X1 , class X2 , class X3 >
269- inline class_<T,X1,X2,X3>::class_(char const * name)
270- : base(name, id_vector::size, id_vector().ids)
276+ inline class_<T,X1,X2,X3>::class_(char const * name, char const * doc )
277+ : base(name, id_vector::size, id_vector().ids, doc )
271278{
272279 // register converters
273280 objects::register_class_from_python<T,bases>();
0 commit comments