Update of /cvsroot/luabind/luabind/luabind/luabind
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24753
Modified Files:
Tag: beta7-devel2
adopt_policy.hpp back_reference.hpp back_reference_fwd.hpp
class.hpp
Added Files:
Tag: beta7-devel2
get_pointer.hpp
Log Message:
Rewrote back_reference code. Should now work with smart pointers.
Index: adopt_policy.hpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/luabind/adopt_policy.hpp,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -d -r1.10 -r1.10.2.1
--- adopt_policy.hpp 7 Aug 2004 13:37:10 -0000 1.10
+++ adopt_policy.hpp 23 Oct 2005 21:37:16 -0000 1.10.2.1
@@ -87,7 +87,7 @@
// if there is a back_reference, then the
// ownership will be removed from the
// back reference and put on the lua stack.
- if (back_reference<T>::move(L, ptr))
+ if (move_back_reference::move(L, ptr))
{
object_rep* obj = static_cast<object_rep*>(lua_touserdata(L, -1));
obj->set_flags(obj->flags() | object_rep::owner);
Index: class.hpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/luabind/class.hpp,v
retrieving revision 1.63.2.3
retrieving revision 1.63.2.4
diff -u -d -r1.63.2.3 -r1.63.2.4
--- class.hpp 19 Oct 2005 11:46:42 -0000 1.63.2.3
+++ class.hpp 23 Oct 2005 21:37:16 -0000 1.63.2.4
@@ -1141,8 +1141,6 @@
void init()
{
- set_back_reference((back_reference<T>*)0);
-
typedef typename detail::extract_parameter<
boost::mpl::list3<X1,X2,X3>
, boost::mpl::or_<
@@ -1312,16 +1310,6 @@
return *this;
}
- void set_back_reference(detail::default_back_reference*)
- {
- back_reference<T>::has_wrapper
- = !boost::is_same<WrappedType, detail::null_type>::value;
- }
-
- void set_back_reference(void*)
- {
- }
-
typedef void(*adopt_fun_t)(void*);
template<class W>
Index: back_reference_fwd.hpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/luabind/back_reference_fwd.hpp,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -d -r1.2 -r1.2.2.1
--- back_reference_fwd.hpp 7 Aug 2004 13:37:10 -0000 1.2
+++ back_reference_fwd.hpp 23 Oct 2005 21:37:16 -0000 1.2.2.1
@@ -20,14 +20,18 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
-#ifndef BACK_REFERENCE_FWD_040510_HPP
-#define BACK_REFERENCE_FWD_040510_HPP
+#ifndef LUABIND_BACK_REFERENCE_FWD_040510_HPP
+#define LUABIND_BACK_REFERENCE_FWD_040510_HPP
namespace luabind {
- template<class T> struct back_reference;
+template<class T>
+bool get_back_reference(lua_State* L, T const& x);
+
+template<class T>
+bool move_back_reference(lua_State* L, T const& x);
} // namespace luabind
-#endif // BACK_REFERENCE_FWD_040510_HPP
+#endif // LUABIND_BACK_REFERENCE_FWD_040510_HPP
Index: back_reference.hpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/luabind/back_reference.hpp,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -d -r1.2 -r1.2.2.1
--- back_reference.hpp 7 Aug 2004 13:37:10 -0000 1.2
+++ back_reference.hpp 23 Oct 2005 21:37:16 -0000 1.2.2.1
@@ -20,175 +20,93 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
-#ifndef BACK_REFERENCE_040510_HPP
-#define BACK_REFERENCE_040510_HPP
+#ifndef LUABIND_BACK_REFERENCE_040510_HPP
+#define LUABIND_BACK_REFERENCE_040510_HPP
#include <luabind/lua_include.hpp>
#include <luabind/wrapper_base.hpp>
+#include <luabind/detail/has_get_pointer.hpp>
+#include <luabind/get_pointer.hpp>
#include <boost/type_traits/is_polymorphic.hpp>
+#include <boost/type_traits/is_const.hpp>
#include <boost/mpl/if.hpp>
namespace luabind {
-#if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300)
- template<class T>
- T* get_pointer(T& ref)
- {
- return &ref;
- }
-
- namespace detail {
-#else
- namespace detail {
-
- struct no_overload_tag {};
-
- } // namespace detail
-
- detail::no_overload_tag get_pointer(...);
-
- namespace detail {
-
- typedef char(&yes_overload)[1];
- typedef char(&no_overload)[2];
-
- no_overload check_overload(no_overload_tag);
- template<class T>
- yes_overload check_overload(T const&);
-
-#endif
-
- template<class T>
- struct extract_wrap_base
- {
-# if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
- BOOST_STATIC_CONSTANT(bool,
- value = sizeof(check_overload(get_pointer(*(T*)0)))
- == sizeof(yes_overload)
- );
-
- static wrap_base const* extract(T const* ptr)
- {
- return extract_impl(ptr, boost::mpl::bool_<value>());
- }
-
- static wrap_base const* extract_impl(T const* ptr, boost::mpl::true_)
- {
- return dynamic_cast<wrap_base const*>(
- get_pointer(*ptr));
- }
-
- static wrap_base const* extract_impl(T const* ptr, boost::mpl::false_)
- {
- return dynamic_cast<wrap_base const*>(ptr);
- }
-
- static wrap_base* extract(T* ptr)
- {
- return extract_impl(ptr, boost::mpl::bool_<value>());
- }
-
- static wrap_base* extract_impl(T* ptr, boost::mpl::true_)
- {
- return dynamic_cast<wrap_base*>(
- get_pointer(*ptr));
- }
-
- static wrap_base* extract_impl(T* ptr, boost::mpl::false_)
- {
- return dynamic_cast<wrap_base*>(ptr);
- }
-# else
- static wrap_base const* extract(T const* ptr)
- {
- return dynamic_cast<wrap_base const*>(get_pointer(*ptr));
- }
-
- static wrap_base* extract(T* ptr)
- {
- return dynamic_cast<wrap_base*>(get_pointer(*ptr));
- }
-# endif
- };
-
- struct default_back_reference {};
-
- template<class T>
- struct back_reference_impl : default_back_reference
- {
- static bool extract(lua_State* L, T const* ptr)
- {
- if (!has_wrapper) return false;
-
- if (wrap_base const* p = extract_wrap_base<T>::extract(ptr))
- {
- wrap_access::ref(*p).get(L);
- return true;
- }
-
- return false;
- }
-
- static bool move(lua_State* L, T* ptr)
- {
- if (!has_wrapper) return false;
-
- if (wrap_base* p = extract_wrap_base<T>::extract(ptr))
- {
- assert(wrap_access::ref(*p).m_strong_ref.is_valid());
- wrap_access::ref(*p).get(L);
- wrap_access::ref(*p).m_strong_ref.reset();
- return true;
- }
-
- return false;
- }
+namespace detail
+{
+ namespace mpl = boost::mpl;
+
+ template<class T>
+ wrap_base const* get_back_reference_aux0(T const* p, mpl::true_)
+ {
+ return dynamic_cast<wrap_base const*>(p);
+ }
- static bool has_wrapper;
- };
+ template<class T>
+ wrap_base const* get_back_reference_aux0(T const* p, mpl::false_)
+ {
+ return 0;
+ }
- template<class T>
- bool back_reference_impl<T>::has_wrapper = false;
+ template<class T>
+ wrap_base const* get_back_reference_aux(T const* p)
+ {
+ return get_back_reference_aux0(p, boost::is_polymorphic<T>());
+ }
- template<class T>
- struct back_reference_do_nothing
- {
- static bool extract(lua_State*, T const*)
- {
- return false;
- }
+ template<class T>
+ wrap_base const* get_back_reference_aux(T const& x, mpl::true_)
+ {
+ return get_back_reference_aux(get_pointer(x));
+ }
- static bool move(lua_State*, T*)
- {
- return false;
- }
- };
+ template<class T>
+ wrap_base const* get_back_reference_aux(T const& x, mpl::false_)
+ {
+ return get_back_reference_aux(&x);
+ }
- } // namespace detail
+ template<class T>
+ wrap_base const* get_back_reference(T const& x)
+ {
+ return detail::get_back_reference_aux(
+ x
+ , has_get_pointer<T>()
+ );
+ }
+
+} // namespace detail
+template<class T>
+bool get_back_reference(lua_State* L, T const& x)
+{
#ifndef LUABIND_NO_RTTI
-
- template<class T>
- struct back_reference
- : boost::mpl::if_<
- boost::is_polymorphic<T>
- , detail::back_reference_impl<T>
- , detail::back_reference_do_nothing<T>
- >::type
+ if (wrap_base const* w = detail::get_back_reference(x))
{
- };
-
-#else
+ detail::wrap_access::ref(*w).get(L);
+ return true;
+ }
+#endif
+ return false;
+}
- template<class T>
- struct back_reference
- : detail::back_reference_do_nothing<T>
+template<class T>
+bool move_back_reference(lua_State* L, T const& x)
+{
+#ifndef LUABIND_NO_RTTI
+ if (wrap_base* w = const_cast<wrap_base*>(detail::get_back_reference(x)))
{
- };
-
+ assert(detail::wrap_access::ref(*w).m_strong_ref.is_valid());
+ detail::wrap_access::ref(*w).get(L);
+ detail::wrap_access::ref(*w).m_strong_ref.reset();
+ return true;
+ }
#endif
+ return false;
+}
} // namespace luabind
-#endif // BACK_REFERENCE_040510_HPP
+#endif // LUABIND_BACK_REFERENCE_040510_HPP
--- NEW FILE: get_pointer.hpp ---
// Copyright (c) 2005 Daniel Wallin
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef LUABIND_GET_POINTER_051023_HPP
# define LUABIND_GET_POINTER_051023_HPP
//
// This is essentially just boost/get_pointer.hpp, but we need these
// in the luabind namespace.
//
// Copyright Peter Dimov and David Abrahams 2002.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
namespace luabind {
template<class T>
T* get_pointer(T* p)
{
return p;
}
template<class T>
T* get_pointer(std::auto_ptr<T> const& p)
{
return p.get();
}
} // namespace luabind
#endif // LUABIND_GET_POINTER_051023_HPP
|