Update of /cvsroot/luabind/luabind/luabind/luabind
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29574/luabind
Modified Files:
Tag: daniel-refactoring
adopt_policy.hpp back_reference.hpp back_reference_fwd.hpp
class.hpp object.hpp value_wrapper.hpp
Added Files:
Tag: daniel-refactoring
get_pointer.hpp
Log Message:
merged_beta7-devel2_into_daniel-refactoring_051024
Index: object.hpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/luabind/object.hpp,v
retrieving revision 1.34.2.17
retrieving revision 1.34.2.17.2.1
diff -u -d -r1.34.2.17 -r1.34.2.17.2.1
--- object.hpp 30 Sep 2005 11:28:42 -0000 1.34.2.17
+++ object.hpp 24 Oct 2005 00:31:34 -0000 1.34.2.17.2.1
@@ -52,7 +52,7 @@
{
typedef typename boost::mpl::if_<
boost::is_reference_wrapper<T>
- , typename boost::unwrap_reference<T>::type&
+ , BOOST_DEDUCED_TYPENAME boost::unwrap_reference<T>::type&
, T
>::type unwrapped_type;
@@ -63,7 +63,9 @@
cv.apply(
interpreter
- , boost::implicit_cast<typename boost::unwrap_reference<T>::type&>(value)
+ , boost::implicit_cast<
+ BOOST_DEDUCED_TYPENAME boost::unwrap_reference<T>::type&
+ >(value)
);
}
@@ -410,10 +412,9 @@
handle m_key;
};
-#if defined(__GNUC__) || BOOST_WORKAROUND(BOOST_MSVC, == 1300)
- // Needed because of GCC's and VC7's strange ADL
+// Needed because of some strange ADL issues.
-# define LUABIND_OPERATOR_ADL_WKND(op) \
+#define LUABIND_OPERATOR_ADL_WKND(op) \
inline bool operator op( \
basic_iterator<basic_access> const& x \
, basic_iterator<basic_access> const& y) \
@@ -431,10 +432,8 @@
LUABIND_OPERATOR_ADL_WKND(==)
LUABIND_OPERATOR_ADL_WKND(!=)
-# undef LUABIND_OPERATOR_ADL_WKND
-
-#endif
-
+#undef LUABIND_OPERATOR_ADL_WKND
+
} // namespace detail
namespace adl
@@ -485,7 +484,6 @@
this_type& operator=(T const& value)
{
value_wrapper_traits<Next>::unwrap(m_interpreter, m_next);
-
detail::stack_pop pop(m_interpreter, 1);
lua_pushvalue(m_interpreter, m_key_index);
@@ -570,22 +568,19 @@
namespace adl
{
- // An object holds a reference to a Lua value residing
- // in the registry.
- class object : public object_interface<object>
+ class object_init
{
- struct safe_bool_type {};
- public:
- object()
+ protected:
+ object_init()
{}
-
- explicit object(from_stack const& stack_reference)
+
+ explicit object_init(from_stack const& stack_reference, boost::mpl::true_)
: m_handle(stack_reference.interpreter, stack_reference.index)
{
}
template<class ValueWrapper>
- explicit object(ValueWrapper const& value_wrapper)
+ explicit object_init(ValueWrapper const& value_wrapper, boost::mpl::false_)
{
lua_State* interpreter = value_wrapper_traits<ValueWrapper>::interpreter(
value_wrapper
@@ -597,6 +592,27 @@
handle(interpreter, -1).swap(m_handle);
}
+ handle m_handle;
+ };
+
+ // An object holds a reference to a Lua value residing
+ // in the registry.
+ class object : public object_interface<object>
+ {
+ struct safe_bool_type {};
+ public:
+ object()
+ {}
+
+ explicit object(handle const& other)
+ : m_handle(other)
+ {}
+
+ explicit object(from_stack const& stack_reference)
+ : m_handle(stack_reference.interpreter, stack_reference.index)
+ {
+ }
+
template<class T>
object(lua_State* interpreter, T const& value)
{
@@ -723,12 +739,14 @@
, class ValueWrapper
, class Policies
, class ErrorPolicy
+ , class ReturnType
>
- typename ErrorPolicy::type object_cast_aux(
+ ReturnType object_cast_aux(
ValueWrapper const& value_wrapper
, T*
, Policies*
, ErrorPolicy*
+ , ReturnType*
)
{
lua_State* interpreter = value_wrapper_traits<ValueWrapper>::interpreter(
@@ -767,8 +785,6 @@
template<class T>
struct throw_error_policy
{
- typedef T type;
-
static T handle_error(lua_State* interpreter, LUABIND_TYPE_INFO type_info)
{
#ifndef LUABIND_NO_EXCEPTIONS
@@ -787,11 +803,9 @@
template<class T>
struct nothrow_error_policy
{
- typedef boost::optional<T> type;
-
- static type handle_error(lua_State*, LUABIND_TYPE_INFO)
+ static boost::optional<T> handle_error(lua_State*, LUABIND_TYPE_INFO)
{
- return type();
+ return boost::optional<T>();
}
};
@@ -805,6 +819,7 @@
, (T*)0
, (detail::null_type*)0
, (detail::throw_error_policy<T>*)0
+ , (T*)0
);
}
@@ -816,6 +831,7 @@
, (T*)0
, (Policies*)0
, (detail::throw_error_policy<T>*)0
+ , (T*)0
);
}
@@ -827,6 +843,7 @@
, (T*)0
, (detail::null_type*)0
, (detail::nothrow_error_policy<T>*)0
+ , (boost::optional<T>*)0
);
}
@@ -838,18 +855,13 @@
, (T*)0
, (Policies*)0
, (detail::nothrow_error_policy<T>*)0
+ , (boost::optional<T>*)0
);
}
namespace detail
{
- template<class T>
- void convert_to_lua(lua_State*, const T&);
-
- template<int Index, class T, class Policies>
- void convert_to_lua_p(lua_State*, const T&, const Policies&);
-
template<int Index>
struct push_args_from_tuple
{
Index: class.hpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/luabind/class.hpp,v
retrieving revision 1.63.2.2.2.1
retrieving revision 1.63.2.2.2.2
diff -u -d -r1.63.2.2.2.1 -r1.63.2.2.2.2
--- class.hpp 2 Oct 2005 00:19:11 -0000 1.63.2.2.2.1
+++ class.hpp 24 Oct 2005 00:31:34 -0000 1.63.2.2.2.2
@@ -1055,8 +1055,6 @@
void init()
{
- set_back_reference((back_reference<T>*)0);
-
class_base::init(LUABIND_TYPEID(T)
, detail::internal_holder_type<typename meta::held_type>::apply()
, detail::pointee_typeid(
@@ -1110,7 +1108,7 @@
// these handle default implementation of virtual functions
template<class F, class Policies>
class_& virtual_def(char const* name, F const& fn
- , Policies const& policies, detail::null_type, boost::mpl::true_)
+ , Policies const&, detail::null_type, boost::mpl::true_)
{
// normal def() call
detail::overload_rep o(fn, static_cast<Policies*>(0));
@@ -1127,7 +1125,7 @@
template<class F, class Default, class Policies>
class_& virtual_def(char const* name, F const& fn
- , Default const& default_, Policies const& policies, boost::mpl::false_)
+ , Default const& default_, Policies const&, boost::mpl::false_)
{
// default_ is a default implementation
// policies is either null_type or a policy list
@@ -1154,7 +1152,7 @@
class_& def_constructor(
boost::mpl::true_ /* HasWrapper */
, Signature*
- , Policies const& policies)
+ , Policies const&)
{
detail::construct_rep::overload_t o;
@@ -1184,7 +1182,7 @@
class_& def_constructor(
boost::mpl::false_ /* !HasWrapper */
, Signature*
- , Policies const& policies)
+ , Policies const&)
{
detail::construct_rep::overload_t o;
@@ -1211,16 +1209,6 @@
return *this;
}
- void set_back_reference(detail::default_back_reference*)
- {
- back_reference<T>::has_wrapper
- = !boost::is_same<typename meta::wrapped_type, detail::null_type>::value;
- }
-
- void set_back_reference(void*)
- {
- }
-
typedef void(*adopt_fun_t)(void*);
template<class W>
Index: value_wrapper.hpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/luabind/Attic/value_wrapper.hpp,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.7.2.1
diff -u -d -r1.1.2.7 -r1.1.2.7.2.1
--- value_wrapper.hpp 30 Sep 2005 11:19:41 -0000 1.1.2.7
+++ value_wrapper.hpp 24 Oct 2005 00:31:34 -0000 1.1.2.7.2.1
@@ -127,33 +127,25 @@
#else
# include <luabind/detail/yes_no.hpp>
+# include <boost/type_traits/add_reference.hpp>
namespace luabind {
namespace detail
{
template<class T>
- typename is_value_wrapper<T>::type
- is_value_wrapper_arg_check(void(*)(T), ...);
-
- template<class T>
- typename is_value_wrapper<T>::type
- is_value_wrapper_arg_check(void(*)(T&), int);
-
- template<class T>
- typename is_value_wrapper<T>::type
- is_value_wrapper_arg_check(void(*)(T const&), long);
-
- boost::mpl::false_ is_value_wrapper_arg_check(...);
-
+ typename is_value_wrapper<T>::type is_value_wrapper_arg_check(T const*);
+
yes_t to_yesno(boost::mpl::true_);
no_t to_yesno(boost::mpl::false_);
-
+
template<class T>
struct is_value_wrapper_arg_aux
{
+ static typename boost::add_reference<T>::type x;
+
BOOST_STATIC_CONSTANT(bool, value =
- sizeof(to_yesno(is_value_wrapper_arg_check((void(*)(T))0, 0L)))
+ sizeof(to_yesno(is_value_wrapper_arg_check(&x)))
== sizeof(yes_t)
);
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.4.1
diff -u -d -r1.2 -r1.2.4.1
--- back_reference_fwd.hpp 7 Aug 2004 13:37:10 -0000 1.2
+++ back_reference_fwd.hpp 24 Oct 2005 00:31:34 -0000 1.2.4.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.4.1
diff -u -d -r1.2 -r1.2.4.1
--- back_reference.hpp 7 Aug 2004 13:37:10 -0000 1.2
+++ back_reference.hpp 24 Oct 2005 00:31:34 -0000 1.2.4.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
Index: adopt_policy.hpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/luabind/adopt_policy.hpp,v
retrieving revision 1.10
retrieving revision 1.10.4.1
diff -u -d -r1.10 -r1.10.4.1
--- adopt_policy.hpp 7 Aug 2004 13:37:10 -0000 1.10
+++ adopt_policy.hpp 24 Oct 2005 00:31:34 -0000 1.10.4.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);
--- 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
//
// We need these overloads in the luabind namespace.
//
# include <boost/get_pointer.hpp>
namespace luabind {
using boost::get_pointer;
} // namespace luabind
#endif // LUABIND_GET_POINTER_051023_HPP
|