Remove old unused files accidentally left around.
[luabind.git] / luabind / shared_ptr_converter.hpp
blobafdc841cb1a8c184ee74362ce5195199ab4f3859
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/get_main_thread.hpp>
9 # include <luabind/handle.hpp>
10 # include <luabind/detail/policy.hpp>
11 # include <boost/shared_ptr.hpp>
13 namespace luabind {
15 namespace detail
18 struct shared_ptr_deleter
20 shared_ptr_deleter(lua_State* L, int index)
21 : life_support(get_main_thread(L), index)
24 void operator()(void const*)
26 handle().swap(life_support);
29 handle life_support;
32 } // namespace detail
34 template <class T>
35 struct default_converter<boost::shared_ptr<T> >
36 : default_converter<T*>
38 typedef boost::mpl::false_ is_native;
40 template <class U>
41 int match(lua_State* L, U, int index)
43 return default_converter<T*>::match(
44 L, LUABIND_DECORATE_TYPE(T*), index);
47 template <class U>
48 boost::shared_ptr<T> apply(lua_State* L, U, int index)
50 T* raw_ptr = default_converter<T*>::apply(
51 L, LUABIND_DECORATE_TYPE(T*), index);
52 if (!raw_ptr)
53 return boost::shared_ptr<T>();
54 return boost::shared_ptr<T>(
55 raw_ptr, detail::shared_ptr_deleter(L, index));
58 void apply(lua_State* L, boost::shared_ptr<T> const& p)
60 if (detail::shared_ptr_deleter* d =
61 boost::get_deleter<detail::shared_ptr_deleter>(p))
63 d->life_support.push(L);
65 else
67 detail::value_converter().apply(L, p);
71 template <class U>
72 void converter_postcall(lua_State*, U const&, int)
76 template <class T>
77 struct default_converter<boost::shared_ptr<T> const&>
78 : default_converter<boost::shared_ptr<T> >
79 {};
81 } // namespace luabind
83 #endif // LUABIND_SHARED_PTR_CONVERTER_090211_HPP