66#ifndef CLASS_DWA200216_HPP
77# define CLASS_DWA200216_HPP
88
9- # include < boost/python/module.hpp>
109# include < boost/python/reference.hpp>
1110# include < boost/python/object/class.hpp>
1211# include < boost/python/converter/type_id.hpp>
@@ -84,26 +83,26 @@ template <
8483 , class Bases = mpl::type_list<>::type
8584 , class HolderGenerator = objects::value_holder_generator
8685 >
87- class class_ : objects::class_base
86+ class class_ : private objects ::class_base
8887{
8988 typedef class_<T,Bases,HolderGenerator> self;
9089 public:
9190
92- // Construct with the module and automatically derive the class
93- // name
94- class_ (module & );
91+ // Automatically derive the class name - only works on some
92+ // compilers because type_info:: name is sometimes mangled (gcc)
93+ class_ ();
9594
96- // Construct with the module and class name. [ Would have used a
97- // default argument but gcc-2.95.2 choked on typeid(T).name() as a
98- // default parameter value]
99- class_ (module &, char const * name);
95+ // Construct with the class name. [ Would have used a default
96+ // argument but gcc-2.95.2 choked on typeid(T).name() as a default
97+ // parameter value]
98+ class_ (char const * name);
10099
101100
102101 // Wrap a member function or a non-member function which can take
103102 // a T, T cv&, or T cv* as its first parameter, or a callable
104103 // python object.
105104 template <class F >
106- self& def (F f, char const * name)
105+ self& def (char const * name, F f )
107106 {
108107 // Use function::add_to_namespace to achieve overloading if
109108 // appropriate.
@@ -117,7 +116,7 @@ class class_ : objects::class_base
117116 template <class Args >
118117 self& def_init (Args const & = Args())
119118 {
120- def (make_constructor<T,Args,HolderGenerator>(), " __init__ " );
119+ def (" __init__ " , make_constructor<T,Args,HolderGenerator>());
121120 return *this ;
122121 }
123122
@@ -128,6 +127,9 @@ class class_ : objects::class_base
128127 return *this ;
129128 }
130129
130+ // return the underlying object
131+ ref object () const ;
132+
131133 private: // types
132134 typedef objects::class_id class_id;
133135
@@ -160,9 +162,8 @@ class class_ : objects::class_base
160162// implementations
161163//
162164template <class T , class Bases , class HolderGenerator >
163- inline class_<T, Bases, HolderGenerator>::class_(
164- module & m)
165- : class_base(m, typeid (T).name(), id_vector::size, id_vector().ids)
165+ inline class_<T, Bases, HolderGenerator>::class_()
166+ : class_base(typeid (T).name(), id_vector::size, id_vector().ids)
166167{
167168 // Bring the class converters into existence. This static object
168169 // will survive until the shared library this module lives in is
@@ -171,16 +172,21 @@ inline class_<T, Bases, HolderGenerator>::class_(
171172}
172173
173174template <class T , class Bases , class HolderGenerator >
174- inline class_<T, Bases, HolderGenerator>::class_(
175- module & m, char const * name)
176- : class_base(m, name, id_vector::size, id_vector().ids)
175+ inline class_<T, Bases, HolderGenerator>::class_(char const * name)
176+ : class_base(name, id_vector::size, id_vector().ids)
177177{
178178 // Bring the class converters into existence. This static object
179179 // will survive until the shared library this module lives in is
180180 // unloaded (that doesn't happen until Python terminates).
181181 static objects::class_converters<T,Bases> converters (object ());
182182}
183183
184+ template <class T , class Bases , class HolderGenerator >
185+ inline ref class_<T, Bases, HolderGenerator>::object() const
186+ {
187+ return this ->class_base ::object ();
188+ }
189+
184190}} // namespace boost::python
185191
186192#endif // CLASS_DWA200216_HPP
0 commit comments