@@ -249,46 +249,53 @@ typedef return_value_policy<copy_const_reference> copy_const_reference_policy;
249249typedef return_value_policy<return_by_value> return_by_value_policy;
250250
251251// ---------------------------------------------------------------------------------
252- // Provides post-construction initialization support of the Python instances .
252+ // Call policies that initializes the wrapper hierarchy .
253253// ---------------------------------------------------------------------------------
254- template <typename BasePolicies = default_call_policies>
255- struct initializer_call_policies : BasePolicies
254+ template <typename HeldType, typename BasePolicies = default_call_policies, int iSelf = - 1 >
255+ struct initialize_wrapper_policies : BasePolicies
256256{
257257 template <typename ArgumentPackage>
258258 static PyObject *postcall (const ArgumentPackage &args, PyObject *pResult)
259259 {
260- return incref (Py_None); // __init__ should always return None
260+ PyObject *pSelf = detail::get (boost::mpl::int_<iSelf>(), args);
261+ detail::initialize_wrapper (
262+ pSelf,
263+ get_pointer ((HeldType)extract<HeldType>(pSelf))
264+ );
265+
266+ return BasePolicies::postcall (args, pResult);
261267 }
262268};
263269
264- template <typename Constructor, typename Initializer>
265- struct constructor_initializer
270+ // ---------------------------------------------------------------------------------
271+ // Provides post-construction initialization support of the Python instances.
272+ // ---------------------------------------------------------------------------------
273+ template <typename BasePolicies = default_call_policies, int iSelf = -1 >
274+ struct post_constructor_policies : BasePolicies
266275{
267276public:
268- constructor_initializer (Constructor constructor, Initializer initializer):
269- m_constructor (constructor),
277+ post_constructor_policies (object initializer):
270278 m_initializer (initializer)
271279 {
272280 }
273281
274- object operator ()(boost::python::tuple args, dict kwargs)
282+ template <typename ArgumentPackage>
283+ PyObject *postcall (const ArgumentPackage &args, PyObject *pResult)
275284 {
276- m_constructor (*args, **kwargs);
277- return m_initializer (*(make_tuple (args[0 ]) + args), **kwargs);
285+ BasePolicies::postcall (args, pResult);
286+ m_initializer (
287+ *(make_tuple (
288+ object (handle<>(incref (detail::get (boost::mpl::int_<iSelf>(), args))))) +
289+ boost::python::tuple (handle<>(args.base ))
290+ )
291+ );
292+
293+ decref (pResult);
294+ return incref (Py_None); // __init__ should always return None
278295 }
279296
280297private:
281- object m_constructor;
282298 object m_initializer;
283299};
284300
285- template <typename Constructor, typename Initializer>
286- object make_constructor_initializer (Constructor constructor, Initializer initializer)
287- {
288- return raw_function (
289- constructor_initializer<Constructor, Initializer>(constructor, initializer),
290- 1 // self
291- );
292- };
293-
294301#endif // _WRAP_MACROS_H
0 commit comments