Skip to content

Commit b844d8b

Browse files
committed
Refactoring and cleanups
[SVN r19770]
1 parent 0a3010b commit b844d8b

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

include/boost/python/class.hpp

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,16 @@ class class_ : public objects::class_base
211211
typedef class_<T,X1,X2,X3> self;
212212
BOOST_STATIC_CONSTANT(bool, is_copyable = (!detail::has_noncopyable<X1,X2,X3>::value));
213213

214+
// held_type - either T, a class derived from T or a smart pointer
215+
// to a (class derived from) T.
214216
typedef typename detail::select_held_type<
215217
X1, typename detail::select_held_type<
216218
X2, typename detail::select_held_type<
217219
X3
218220
>::type>::type>::type held_type;
219221

220-
typedef objects::select_holder<T,held_type> holder_selector;
221-
222+
typedef objects::select_holder<T,held_type> select_holder;
223+
222224
private: // types
223225

224226
typedef typename detail::select_bases<X1
@@ -264,19 +266,17 @@ class class_ : public objects::class_base
264266
inline class_(char const* name, init_base<DerivedT> const& i)
265267
: base(name, id_vector::size, id_vector().ids)
266268
{
267-
this->register_();
269+
this->register_holder();
268270
this->def(i);
269-
this->set_instance_size(holder_selector::additional_size());
270271
}
271272

272273
// Construct with class name, docstring and init<> function
273274
template <class DerivedT>
274275
inline class_(char const* name, char const* doc, init_base<DerivedT> const& i)
275276
: base(name, id_vector::size, id_vector().ids, doc)
276277
{
277-
this->register_();
278+
this->register_holder();
278279
this->def(i);
279-
this->set_instance_size(holder_selector::additional_size());
280280
}
281281

282282
public: // member functions
@@ -475,7 +475,8 @@ class class_ : public objects::class_base
475475
}
476476

477477
inline void register_() const;
478-
478+
inline void register_holder();
479+
479480
//
480481
// These two overloads discriminate between def() as applied to a
481482
// generic visitor and everything else.
@@ -584,24 +585,31 @@ inline void class_<T,X1,X2,X3>::register_() const
584585
{
585586
objects::register_class_from_python<T,bases>();
586587

587-
typedef BOOST_DEDUCED_TYPENAME holder_selector::type select_holder;
588588
typedef BOOST_DEDUCED_TYPENAME select_holder::held_type held_t;
589-
590589
detail::register_wrapper_class<held_t,T>();
591-
590+
592591
detail::register_class_to_python<T>(
593592
mpl::bool_<is_copyable>()
594-
, BOOST_DEDUCED_TYPENAME holder_selector::type()
593+
, select_holder()
594+
);
595+
}
596+
597+
template <class T, class X1, class X2, class X3>
598+
inline void class_<T,X1,X2,X3>::register_holder()
599+
{
600+
this->register_();
601+
typedef typename select_holder::type holder;
602+
this->set_instance_size(
603+
objects::additional_instance_size<holder>::value
595604
);
596605
}
597606

598607
template <class T, class X1, class X2, class X3>
599608
inline class_<T,X1,X2,X3>::class_(char const* name, char const* doc)
600609
: base(name, id_vector::size, id_vector().ids, doc)
601610
{
602-
this->register_();
603-
this->set_instance_size(holder_selector::additional_size());
604-
holder_selector::type::assert_default_constructible();
611+
this->register_holder();
612+
select_holder::assert_default_constructible();
605613
this->def(init<>());
606614
}
607615

@@ -633,18 +641,18 @@ namespace detail
633641
{};
634642

635643

636-
template <class T, class Prev>
637-
struct select_held_type
638-
: mpl::if_<
639-
mpl::or_<
640-
specifies_bases<T>
641-
, is_same<T,noncopyable>
642-
>
643-
, Prev
644-
, T
645-
>
646-
{
647-
};
644+
template <class T, class Prev>
645+
struct select_held_type
646+
: mpl::if_<
647+
mpl::or_<
648+
specifies_bases<T>
649+
, is_same<T,noncopyable>
650+
>
651+
, Prev
652+
, T
653+
>
654+
{
655+
};
648656
}
649657

650658
}} // namespace boost::python

0 commit comments

Comments
 (0)