Operators should only be enabled for object and it's proxy classes, not
[luabind.git] / luabind / dependency_policy.hpp
blob7c1245ca1952279fe6a2096f97992439a271d852
1 // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
14 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
18 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
24 #ifndef LUABIND_DEPENDENCY_POLICY_HPP_INCLUDED
25 #define LUABIND_DEPENDENCY_POLICY_HPP_INCLUDED
27 #include <luabind/config.hpp>
28 #include <luabind/detail/policy.hpp>
30 namespace luabind { namespace detail
32 // makes A dependent on B, meaning B will outlive A.
33 // internally A stores a reference to B
34 template<int A, int B>
35 struct dependency_policy
37 static void postcall(lua_State* L, const index_map& indices)
39 int nurse_index = indices[A];
40 int patient = indices[B];
42 object_rep* nurse = static_cast<object_rep*>(lua_touserdata(L, nurse_index));
43 assert((nurse != 0) && "internal error, please report"); // internal error
45 nurse->add_dependency(L, patient);
51 #if defined (BOOST_MSVC) && (BOOST_MSVC <= 1200)
53 namespace luabind
55 // most absurd workaround of all time?
56 namespace detail
58 template<int N>
59 struct size_char_array
61 char storage[N + 2];
64 template<int N>
65 size_char_array<N> deduce_size(LUABIND_PLACEHOLDER_ARG(N));
67 template<class T>
68 struct get_index_workaround
70 static T t;
71 BOOST_STATIC_CONSTANT(int, value = sizeof(deduce_size(t)) - 2);
75 template<class A, class B>
76 detail::policy_cons<detail::dependency_policy<detail::get_index_workaround<A>::value
77 , detail::get_index_workaround<B>::value>, detail::null_type> dependency(A,B)
79 return detail::policy_cons<detail::dependency_policy<
80 detail::get_index_workaround<A>::value, detail::get_index_workaround<B>::value>
81 , detail::null_type>();
84 template<class A>
85 detail::policy_cons<detail::dependency_policy<0
86 , detail::get_index_workaround<A>::value>, detail::null_type>
87 return_internal_reference(A)
89 return detail::policy_cons<detail::dependency_policy<0
90 , detail::get_index_workaround<A>::value>, detail::null_type>();
94 #else
96 namespace luabind
98 template<int A, int B>
99 detail::policy_cons<detail::dependency_policy<A, B>, detail::null_type>
100 dependency(LUABIND_PLACEHOLDER_ARG(A), LUABIND_PLACEHOLDER_ARG(B))
102 return detail::policy_cons<detail::dependency_policy<A, B>, detail::null_type>();
105 template<int A>
106 detail::policy_cons<detail::dependency_policy<0, A>, detail::null_type>
107 return_internal_reference(LUABIND_PLACEHOLDER_ARG(A))
109 return detail::policy_cons<detail::dependency_policy<0, A>, detail::null_type>();
113 #endif
115 #endif // LUABIND_DEPENDENCY_POLICY_HPP_INCLUDED