From ed8cc7fbaff9e6ce7730f8230e68ae4d8a0f10db Mon Sep 17 00:00:00 2001 From: Ben Wilhelm Date: Thu, 24 Jun 2010 20:11:10 +0200 Subject: [PATCH] Teach adopt() to hold the adopted pointer in custom pointer type. --- luabind/adopt_policy.hpp | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/luabind/adopt_policy.hpp b/luabind/adopt_policy.hpp index 5e81b94..dfe5818 100644 --- a/luabind/adopt_policy.hpp +++ b/luabind/adopt_policy.hpp @@ -47,7 +47,7 @@ namespace luabind { namespace detail inline void adjust_backref_ownership(void*, mpl::false_) {} - template + template struct adopt_pointer : pointer_converter { typedef adopt_pointer type; @@ -83,8 +83,20 @@ namespace luabind { namespace detail void converter_postcall(lua_State*, T, int) {} }; - template<> - struct adopt_pointer + template + struct pointer_or_default + { + typedef Pointer type; + }; + + template + struct pointer_or_default + { + typedef std::auto_ptr type; + }; + + template + struct adopt_pointer { typedef adopt_pointer type; @@ -103,12 +115,14 @@ namespace luabind { namespace detail if (luabind::move_back_reference(L, ptr)) return; - make_instance(L, std::auto_ptr(ptr)); + typedef typename pointer_or_default::type + pointer_type; + + make_instance(L, pointer_type(ptr)); } }; - template -// struct adopt_policy : converter_policy_tag + template struct adopt_policy : conversion_policy { // BOOST_STATIC_CONSTANT(int, index = N); @@ -122,7 +136,11 @@ namespace luabind { namespace detail struct apply { typedef luabind::detail::is_nonconst_pointer is_nonconst_p; - typedef typename boost::mpl::if_, only_accepts_nonconst_pointers>::type type; + typedef typename boost::mpl::if_< + is_nonconst_p + , adopt_pointer + , only_accepts_nonconst_pointers + >::type type; }; }; @@ -136,6 +154,13 @@ namespace luabind { return detail::policy_cons, detail::null_type>(); } + + template + detail::policy_cons, detail::null_type> + adopt(LUABIND_PLACEHOLDER_ARG(N)) + { + return detail::policy_cons, detail::null_type>(); + } } #endif // LUABIND_ADOPT_POLICY_HPP_INCLUDE -- 2.11.4.GIT