Suppress MSVC "assignment operator could not be generated" warning.
[luabind.git] / luabind / shared_ptr_converter.hpp
blobd35d805dd87cc1a9cd0ba32a6ca6a4d4b8bd52a9
1 // Copyright Daniel Wallin 2009. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef LUABIND_SHARED_PTR_CONVERTER_090211_HPP
6 # define LUABIND_SHARED_PTR_CONVERTER_090211_HPP
8 # include <luabind/handle.hpp>
9 # include <luabind/detail/policy.hpp>
10 # include <boost/shared_ptr.hpp>
12 namespace luabind {
14 namespace detail
17 struct shared_ptr_deleter
19 shared_ptr_deleter(lua_State* L, int index)
20 : life_support(L, index)
23 void operator()(void const*)
25 handle().swap(life_support);
28 handle life_support;
31 } // namespace detail
33 template <class T>
34 struct default_converter<boost::shared_ptr<T> >
35 : default_converter<T*>
37 typedef boost::mpl::false_ is_native;
39 template <class U>
40 int match(lua_State* L, U, int index)
42 return default_converter<T*>::match(
43 L, LUABIND_DECORATE_TYPE(T*), index);
46 template <class U>
47 boost::shared_ptr<T> apply(lua_State* L, U, int index)
49 T* raw_ptr = default_converter<T*>::apply(
50 L, LUABIND_DECORATE_TYPE(T*), index);
51 if (!raw_ptr)
52 return boost::shared_ptr<T>();
53 return boost::shared_ptr<T>(
54 raw_ptr, detail::shared_ptr_deleter(L, index));
57 void apply(lua_State* L, boost::shared_ptr<T> const& p)
59 if (detail::shared_ptr_deleter* d =
60 boost::get_deleter<detail::shared_ptr_deleter>(p))
62 d->life_support.push(L);
64 else
66 detail::value_converter().apply(L, p);
70 template <class U>
71 void converter_postcall(lua_State*, U const&, int)
75 template <class T>
76 struct default_converter<boost::shared_ptr<T> const&>
77 : default_converter<boost::shared_ptr<T> >
78 {};
80 } // namespace luabind
82 #endif // LUABIND_SHARED_PTR_CONVERTER_090211_HPP