Update of /cvsroot/luabind/luabind/luabind/luabind
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13602/luabind/luabind
Modified Files:
Tag: luabind_rc_0_7
object.hpp
Log Message:
merged in changes to object.hpp from head and fixed the stream operator on object to be more restrictive in which types it accepts
Index: object.hpp
===================================================================
RCS file: /cvsroot/luabind/luabind/luabind/luabind/object.hpp,v
retrieving revision 1.36.2.2
retrieving revision 1.36.2.3
diff -u -d -r1.36.2.2 -r1.36.2.3
--- object.hpp 1 Jan 2006 16:55:56 -0000 1.36.2.2
+++ object.hpp 1 Jan 2006 19:41:53 -0000 1.36.2.3
@@ -42,6 +42,7 @@
#include <boost/python/detail/is_xxx.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
+#include <boost/utility/enable_if.hpp>
#include <iosfwd>
@@ -93,6 +94,54 @@
namespace adl
{
+ namespace mpl = boost::mpl;
+
+ template <class T>
+ class object_interface;
+
+ namespace is_object_interface_aux
+ {
+ typedef char (&yes)[1];
+ typedef char (&no)[2];
+
+ template <class T>
+ yes check(object_interface<T>*);
+ no check(void*);
+
+ template <class T>
+ struct impl
+ {
+ BOOST_STATIC_CONSTANT(bool, value =
+ sizeof(is_object_interface_aux::check((T*)0)) == sizeof(yes)
+ );
+
+ typedef mpl::bool_<value> type;
+ };
+
+ } // namespace detail
+
+ template <class T>
+ struct is_object_interface
+ : is_object_interface_aux::impl<T>::type
+ {};
+
+ template <class R, class T, class U>
+ struct enable_binary
+# ifndef BOOST_NO_SFINAE
+ : boost::enable_if<
+ mpl::or_<
+ is_object_interface<T>
+ , is_object_interface<U>
+ >
+ , R
+ >
+ {};
+# else
+ {
+ typedef R type;
+ };
+# endif
+
template<class T, class U>
int binary_interpreter(lua_State*& L, T const& lhs, U const& rhs
, boost::mpl::true_, boost::mpl::true_)
@@ -111,7 +160,7 @@
if (L == 0) return 1;
return 0;
}
-
+
template<class T, class U>
int binary_interpreter(lua_State*& L, T const& x, U const&
, boost::mpl::true_, boost::mpl::false_)
@@ -141,7 +190,8 @@
#define LUABIND_BINARY_OP_DEF(op, fn) \
template<class LHS, class RHS> \
- bool operator op(LHS const& lhs, RHS const& rhs) \
+ typename enable_binary<bool,LHS,RHS>::type \
+ operator op(LHS const& lhs, RHS const& rhs) \
{ \
lua_State* L = 0; \
switch (binary_interpreter(L, lhs, rhs)) \
@@ -166,38 +216,45 @@
LUABIND_BINARY_OP_DEF(<, lua_lessthan)
template<class ValueWrapper>
- std::ostream& operator<<(std::ostream& os, ValueWrapper const& v)
+ std::ostream& operator<<(std::ostream& os
+ , object_interface<ValueWrapper> const& v)
{
using namespace luabind;
- lua_State* interpreter = value_wrapper_traits<ValueWrapper>::interpreter(v);
- value_wrapper_traits<ValueWrapper>::unwrap(interpreter, v);
+ lua_State* interpreter = value_wrapper_traits<ValueWrapper>::interpreter(
+ static_cast<ValueWrapper const&>(v));
detail::stack_pop pop(interpreter, 1);
- return std::operator<<(os, std::string(lua_tostring(interpreter, -1)
- , lua_strlen(interpreter, -1)));
+ value_wrapper_traits<ValueWrapper>::unwrap(interpreter
+ , static_cast<ValueWrapper const&>(v));
+ return os << std::string(lua_tostring(interpreter, -1)
+ , lua_strlen(interpreter, -1));
}
#undef LUABIND_BINARY_OP_DEF
template<class LHS, class RHS>
- bool operator>(LHS const& lhs, RHS const& rhs)
+ typename enable_binary<bool,LHS,RHS>::type
+ operator>(LHS const& lhs, RHS const& rhs)
{
return !(lhs < rhs || lhs == rhs);
}
template<class LHS, class RHS>
- bool operator<=(LHS const& lhs, RHS const& rhs)
+ typename enable_binary<bool,LHS,RHS>::type
+ operator<=(LHS const& lhs, RHS const& rhs)
{
return lhs < rhs || lhs == rhs;
}
template<class LHS, class RHS>
- bool operator>=(LHS const& lhs, RHS const& rhs)
+ typename enable_binary<bool,LHS,RHS>::type
+ operator>=(LHS const& lhs, RHS const& rhs)
{
return !(lhs < rhs);
}
template<class LHS, class RHS>
- bool operator!=(LHS const& lhs, RHS const& rhs)
+ typename enable_binary<bool,LHS,RHS>::type
+ operator!=(LHS const& lhs, RHS const& rhs)
{
return !(lhs < rhs);
}
|