|
8 | 8 |
|
9 | 9 | # include <boost/python/detail/prefix.hpp> |
10 | 10 |
|
| 11 | +# include <boost/noncopyable.hpp> |
| 12 | + |
11 | 13 | # include <boost/python/class_fwd.hpp> |
12 | 14 | # include <boost/python/object/class.hpp> |
13 | 15 |
|
14 | | -# include <boost/python/bases.hpp> |
15 | 16 | # include <boost/python/object.hpp> |
16 | 17 | # include <boost/python/type_id.hpp> |
17 | 18 | # include <boost/python/data_members.hpp> |
|
20 | 21 | # include <boost/python/init.hpp> |
21 | 22 | # include <boost/python/args_fwd.hpp> |
22 | 23 |
|
23 | | -# include <boost/python/object/select_holder.hpp> |
24 | | -# include <boost/python/object/class_wrapper.hpp> |
25 | | -# include <boost/python/object/make_instance.hpp> |
| 24 | +# include <boost/python/object/class_metadata.hpp> |
26 | 25 | # include <boost/python/object/pickle_support.hpp> |
27 | 26 | # include <boost/python/object/add_to_namespace.hpp> |
28 | | -# include <boost/python/object/class_converters.hpp> |
29 | 27 |
|
30 | 28 | # include <boost/python/detail/overloads_fwd.hpp> |
31 | 29 | # include <boost/python/detail/operator_id.hpp> |
32 | 30 | # include <boost/python/detail/def_helper.hpp> |
33 | 31 | # include <boost/python/detail/force_instantiate.hpp> |
34 | 32 |
|
35 | 33 | # include <boost/type_traits/is_same.hpp> |
36 | | -# include <boost/type_traits/is_convertible.hpp> |
37 | 34 | # include <boost/type_traits/is_member_function_pointer.hpp> |
38 | 35 | # include <boost/type_traits/is_polymorphic.hpp> |
39 | 36 |
|
40 | 37 | # include <boost/mpl/size.hpp> |
41 | 38 | # include <boost/mpl/for_each.hpp> |
42 | 39 | # include <boost/mpl/bool.hpp> |
43 | 40 | # include <boost/mpl/not.hpp> |
44 | | -# include <boost/mpl/or.hpp> |
45 | | -# include <boost/mpl/vector/vector10.hpp> |
46 | 41 |
|
47 | | -# include <boost/utility.hpp> |
48 | 42 | # include <boost/detail/workaround.hpp> |
49 | 43 |
|
50 | 44 | # if BOOST_WORKAROUND(__MWERKS__, <= 0x3004) \ |
@@ -87,52 +81,6 @@ namespace detail |
87 | 81 | type_info** p; |
88 | 82 | }; |
89 | 83 |
|
90 | | - template <class T, class Prev = detail::not_specified> |
91 | | - struct select_held_type; |
92 | | - |
93 | | - template <class T1, class T2, class T3> |
94 | | - struct has_noncopyable; |
95 | | - |
96 | | - // Register to_python converters for a class T. The first argument |
97 | | - // will be mpl::true_ unless noncopyable was specified as a |
98 | | - // class_<...> template parameter. The 2nd argument is a pointer to |
99 | | - // the type of holder that must be created. The 3rd argument is a |
100 | | - // reference to the Python type object to be created. |
101 | | - template <class T, class SelectHolder> |
102 | | - inline void register_class_to_python(mpl::true_, SelectHolder, T* = 0) |
103 | | - { |
104 | | - typedef typename SelectHolder::type holder; |
105 | | - force_instantiate(objects::class_cref_wrapper<T, objects::make_instance<T,holder> >()); |
106 | | - SelectHolder::register_(); |
107 | | - } |
108 | | - |
109 | | - template <class T, class SelectHolder> |
110 | | - inline void register_class_to_python(mpl::false_, SelectHolder, T* = 0) |
111 | | - { |
112 | | - SelectHolder::register_(); |
113 | | - } |
114 | | - |
115 | | - // |
116 | | - // register_wrapper_class -- register the relationship between a |
117 | | - // virtual function callback wrapper class and the class being |
118 | | - // wrapped. |
119 | | - // |
120 | | - template <class T> |
121 | | - inline void register_wrapper_class_impl(T*, T*, int) {} |
122 | | - |
123 | | - template <class Wrapper, class T> |
124 | | - inline void register_wrapper_class_impl(Wrapper*, T*, ...) |
125 | | - { |
126 | | - objects::register_class_from_python<Wrapper, mpl::vector1<T> >(); |
127 | | - objects::copy_class_object(type_id<T>(), type_id<Wrapper>()); |
128 | | - } |
129 | | - |
130 | | - template <class Held, class T> |
131 | | - inline void register_wrapper_class(Held* = 0, T* = 0) |
132 | | - { |
133 | | - register_wrapper_class_impl((Held*)0, (T*)0, 0); |
134 | | - } |
135 | | - |
136 | 84 | template <class T> |
137 | 85 | struct is_data_member_pointer |
138 | 86 | : mpl::and_< |
@@ -212,34 +160,18 @@ class class_ : public objects::class_base |
212 | 160 | { |
213 | 161 | public: // types |
214 | 162 | typedef objects::class_base base; |
215 | | - typedef T wrapped_type; |
216 | | - |
217 | 163 | typedef class_<T,X1,X2,X3> self; |
218 | | - BOOST_STATIC_CONSTANT(bool, is_copyable = (!detail::has_noncopyable<X1,X2,X3>::value)); |
219 | | - |
220 | | - // held_type - either T, a class derived from T or a smart pointer |
221 | | - // to a (class derived from) T. |
222 | | - typedef typename detail::select_held_type< |
223 | | - X1, typename detail::select_held_type< |
224 | | - X2, typename detail::select_held_type< |
225 | | - X3 |
226 | | - >::type>::type>::type held_type; |
227 | | - |
228 | | - typedef objects::select_holder<T,held_type> select_holder; |
| 164 | + typedef typename objects::class_metadata<T,X1,X2,X3> metadata; |
| 165 | + typedef T wrapped_type; |
229 | 166 |
|
230 | 167 | private: // types |
231 | 168 |
|
232 | | - typedef typename detail::select_bases<X1 |
233 | | - , typename detail::select_bases<X2 |
234 | | - , typename boost::python::detail::select_bases<X3>::type |
235 | | - >::type |
236 | | - >::type bases; |
237 | | - |
238 | | - |
239 | 169 | // A helper class which will contain an array of id objects to be |
240 | 170 | // passed to the base class constructor |
241 | 171 | struct id_vector |
242 | 172 | { |
| 173 | + typedef typename metadata::bases bases; |
| 174 | + |
243 | 175 | id_vector() |
244 | 176 | { |
245 | 177 | // Stick the derived class id into the first element of the array |
@@ -272,17 +204,15 @@ class class_ : public objects::class_base |
272 | 204 | inline class_(char const* name, init_base<DerivedT> const& i) |
273 | 205 | : base(name, id_vector::size, id_vector().ids) |
274 | 206 | { |
275 | | - this->register_holder(); |
276 | | - this->def(i); |
| 207 | + this->initialize(i); |
277 | 208 | } |
278 | 209 |
|
279 | 210 | // Construct with class name, docstring and init<> function |
280 | 211 | template <class DerivedT> |
281 | 212 | inline class_(char const* name, char const* doc, init_base<DerivedT> const& i) |
282 | 213 | : base(name, id_vector::size, id_vector().ids, doc) |
283 | 214 | { |
284 | | - this->register_holder(); |
285 | | - this->def(i); |
| 215 | + this->initialize(i); |
286 | 216 | } |
287 | 217 |
|
288 | 218 | public: // member functions |
@@ -510,8 +440,22 @@ class class_ : public objects::class_base |
510 | 440 | return this->add_static_property(name, python::make_getter(d), python::make_setter(d)); |
511 | 441 | } |
512 | 442 |
|
513 | | - inline void register_() const; |
514 | | - inline void register_holder(); |
| 443 | + template <class DefVisitor> |
| 444 | + inline void initialize(DefVisitor const& i) |
| 445 | + { |
| 446 | + metadata::register_(); // set up runtime metadata/conversions |
| 447 | + |
| 448 | + typedef typename metadata::holder holder; |
| 449 | + this->set_instance_size( objects::additional_instance_size<holder>::value ); |
| 450 | + |
| 451 | + this->def(i); |
| 452 | + } |
| 453 | + |
| 454 | + inline void initialize(no_init_t) |
| 455 | + { |
| 456 | + metadata::register_(); // set up runtime metadata/conversions |
| 457 | + this->def_no_init(); |
| 458 | + } |
515 | 459 |
|
516 | 460 | // |
517 | 461 | // These two overloads discriminate between def() as applied to a |
@@ -625,80 +569,26 @@ class class_ : public objects::class_base |
625 | 569 | // implementations |
626 | 570 | // |
627 | 571 |
|
628 | | -// register converters |
629 | | -template <class T, class X1, class X2, class X3> |
630 | | -inline void class_<T,X1,X2,X3>::register_() const |
631 | | -{ |
632 | | - objects::register_class_from_python<T,bases>(); |
633 | | - |
634 | | - typedef BOOST_DEDUCED_TYPENAME select_holder::held_type held_t; |
635 | | - detail::register_wrapper_class<held_t,T>(); |
636 | | - |
637 | | - detail::register_class_to_python<T>( |
638 | | - mpl::bool_<is_copyable>() |
639 | | - , select_holder() |
640 | | - ); |
641 | | -} |
642 | | - |
643 | | -template <class T, class X1, class X2, class X3> |
644 | | -inline void class_<T,X1,X2,X3>::register_holder() |
645 | | -{ |
646 | | - this->register_(); |
647 | | - typedef typename select_holder::type holder; |
648 | | - this->set_instance_size( |
649 | | - objects::additional_instance_size<holder>::value |
650 | | - ); |
651 | | -} |
652 | | - |
653 | 572 | template <class T, class X1, class X2, class X3> |
654 | 573 | inline class_<T,X1,X2,X3>::class_(char const* name, char const* doc) |
655 | 574 | : base(name, id_vector::size, id_vector().ids, doc) |
656 | 575 | { |
657 | | - this->register_holder(); |
658 | | - select_holder::assert_default_constructible(); |
659 | | - this->def(init<>()); |
| 576 | + this->initialize(init<>()); |
| 577 | +// select_holder::assert_default_constructible(); |
660 | 578 | } |
661 | 579 |
|
662 | 580 | template <class T, class X1, class X2, class X3> |
663 | 581 | inline class_<T,X1,X2,X3>::class_(char const* name, no_init_t) |
664 | 582 | : base(name, id_vector::size, id_vector().ids) |
665 | 583 | { |
666 | | - this->register_(); |
667 | | - this->def_no_init(); |
| 584 | + this->initialize(no_init); |
668 | 585 | } |
669 | 586 |
|
670 | 587 | template <class T, class X1, class X2, class X3> |
671 | 588 | inline class_<T,X1,X2,X3>::class_(char const* name, char const* doc, no_init_t) |
672 | 589 | : base(name, id_vector::size, id_vector().ids, doc) |
673 | 590 | { |
674 | | - this->register_(); |
675 | | - this->def_no_init(); |
676 | | -} |
677 | | - |
678 | | -namespace detail |
679 | | -{ |
680 | | - template <class T1, class T2, class T3> |
681 | | - struct has_noncopyable |
682 | | - : mpl::or_< |
683 | | - is_same<T1,noncopyable> |
684 | | - , is_same<T2,noncopyable> |
685 | | - , is_same<T3,noncopyable> |
686 | | - > |
687 | | - {}; |
688 | | - |
689 | | - |
690 | | - template <class T, class Prev> |
691 | | - struct select_held_type |
692 | | - : mpl::if_< |
693 | | - mpl::or_< |
694 | | - specifies_bases<T> |
695 | | - , is_same<T,noncopyable> |
696 | | - > |
697 | | - , Prev |
698 | | - , T |
699 | | - > |
700 | | - { |
701 | | - }; |
| 591 | + this->initialize(no_init); |
702 | 592 | } |
703 | 593 |
|
704 | 594 | }} // namespace boost::python |
|
0 commit comments