Skip to content

Commit 615adc5

Browse files
committed
Make slice work on vc6
Revamp/simplify class registration [SVN r23823]
1 parent 2bdb728 commit 615adc5

18 files changed

+391
-498
lines changed

include/boost/python/class.hpp

Lines changed: 29 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
# include <boost/python/detail/prefix.hpp>
1010

11+
# include <boost/noncopyable.hpp>
12+
1113
# include <boost/python/class_fwd.hpp>
1214
# include <boost/python/object/class.hpp>
1315

14-
# include <boost/python/bases.hpp>
1516
# include <boost/python/object.hpp>
1617
# include <boost/python/type_id.hpp>
1718
# include <boost/python/data_members.hpp>
@@ -20,31 +21,24 @@
2021
# include <boost/python/init.hpp>
2122
# include <boost/python/args_fwd.hpp>
2223

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>
2625
# include <boost/python/object/pickle_support.hpp>
2726
# include <boost/python/object/add_to_namespace.hpp>
28-
# include <boost/python/object/class_converters.hpp>
2927

3028
# include <boost/python/detail/overloads_fwd.hpp>
3129
# include <boost/python/detail/operator_id.hpp>
3230
# include <boost/python/detail/def_helper.hpp>
3331
# include <boost/python/detail/force_instantiate.hpp>
3432

3533
# include <boost/type_traits/is_same.hpp>
36-
# include <boost/type_traits/is_convertible.hpp>
3734
# include <boost/type_traits/is_member_function_pointer.hpp>
3835
# include <boost/type_traits/is_polymorphic.hpp>
3936

4037
# include <boost/mpl/size.hpp>
4138
# include <boost/mpl/for_each.hpp>
4239
# include <boost/mpl/bool.hpp>
4340
# include <boost/mpl/not.hpp>
44-
# include <boost/mpl/or.hpp>
45-
# include <boost/mpl/vector/vector10.hpp>
4641

47-
# include <boost/utility.hpp>
4842
# include <boost/detail/workaround.hpp>
4943

5044
# if BOOST_WORKAROUND(__MWERKS__, <= 0x3004) \
@@ -87,52 +81,6 @@ namespace detail
8781
type_info** p;
8882
};
8983

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-
13684
template <class T>
13785
struct is_data_member_pointer
13886
: mpl::and_<
@@ -212,34 +160,18 @@ class class_ : public objects::class_base
212160
{
213161
public: // types
214162
typedef objects::class_base base;
215-
typedef T wrapped_type;
216-
217163
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;
229166

230167
private: // types
231168

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-
239169
// A helper class which will contain an array of id objects to be
240170
// passed to the base class constructor
241171
struct id_vector
242172
{
173+
typedef typename metadata::bases bases;
174+
243175
id_vector()
244176
{
245177
// Stick the derived class id into the first element of the array
@@ -272,17 +204,15 @@ class class_ : public objects::class_base
272204
inline class_(char const* name, init_base<DerivedT> const& i)
273205
: base(name, id_vector::size, id_vector().ids)
274206
{
275-
this->register_holder();
276-
this->def(i);
207+
this->initialize(i);
277208
}
278209

279210
// Construct with class name, docstring and init<> function
280211
template <class DerivedT>
281212
inline class_(char const* name, char const* doc, init_base<DerivedT> const& i)
282213
: base(name, id_vector::size, id_vector().ids, doc)
283214
{
284-
this->register_holder();
285-
this->def(i);
215+
this->initialize(i);
286216
}
287217

288218
public: // member functions
@@ -510,8 +440,22 @@ class class_ : public objects::class_base
510440
return this->add_static_property(name, python::make_getter(d), python::make_setter(d));
511441
}
512442

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+
}
515459

516460
//
517461
// These two overloads discriminate between def() as applied to a
@@ -625,80 +569,26 @@ class class_ : public objects::class_base
625569
// implementations
626570
//
627571

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-
653572
template <class T, class X1, class X2, class X3>
654573
inline class_<T,X1,X2,X3>::class_(char const* name, char const* doc)
655574
: base(name, id_vector::size, id_vector().ids, doc)
656575
{
657-
this->register_holder();
658-
select_holder::assert_default_constructible();
659-
this->def(init<>());
576+
this->initialize(init<>());
577+
// select_holder::assert_default_constructible();
660578
}
661579

662580
template <class T, class X1, class X2, class X3>
663581
inline class_<T,X1,X2,X3>::class_(char const* name, no_init_t)
664582
: base(name, id_vector::size, id_vector().ids)
665583
{
666-
this->register_();
667-
this->def_no_init();
584+
this->initialize(no_init);
668585
}
669586

670587
template <class T, class X1, class X2, class X3>
671588
inline class_<T,X1,X2,X3>::class_(char const* name, char const* doc, no_init_t)
672589
: base(name, id_vector::size, id_vector().ids, doc)
673590
{
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);
702592
}
703593

704594
}} // namespace boost::python

include/boost/python/converter/shared_ptr_from_python.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
# include <boost/python/handle.hpp>
1010
# include <boost/python/converter/shared_ptr_deleter.hpp>
11+
# include <boost/python/converter/from_python.hpp>
12+
# include <boost/python/converter/rvalue_from_python_data.hpp>
13+
# include <boost/python/converter/registered.hpp>
14+
# include <boost/shared_ptr.hpp>
1115

1216
namespace boost { namespace python { namespace converter {
1317

include/boost/python/init.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,17 +328,15 @@ namespace detail
328328
, detail::keyword_range const& keywords_
329329
)
330330
{
331-
typedef typename ClassT::select_holder selector_t;
332-
333331
cl.def(
334-
"__init__",
335-
detail::make_keyword_range_constructor<Signature,NArgs>(
336-
policies
337-
, keywords_
338-
, selector_t::get()
339-
)
340-
, doc
341-
);
332+
"__init__"
333+
, detail::make_keyword_range_constructor<Signature,NArgs>(
334+
policies
335+
, keywords_
336+
, (typename ClassT::metadata::holder*)0
337+
)
338+
, doc
339+
);
342340
}
343341

344342
///////////////////////////////////////////////////////////////////////////////

include/boost/python/object/class.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ struct BOOST_PYTHON_DECL class_base : python::api::object
5858
void make_method_static(const char *method_name);
5959
};
6060

61-
BOOST_PYTHON_DECL void copy_class_object(type_info const& src, type_info const& dst);
62-
6361
}}} // namespace boost::python::objects
6462

6563
#endif // CLASS_DWA20011214_HPP

0 commit comments

Comments
 (0)