otaylor / rpms / boost

Forked from rpms/boost 5 years ago
Clone
f948923
Index: /trunk/boost/python/object_core.hpp
f948923
===================================================================
f948923
--- /trunk/boost/python/object_core.hpp (revision 45918)
f948923
+++ /trunk/boost/python/object_core.hpp (revision 47846)
f948923
@@ -42,4 +42,10 @@
f948923
 
f948923
 namespace boost { namespace python { 
f948923
+
f948923
+namespace detail
f948923
+{
f948923
+  class kwds_proxy; 
f948923
+  class args_proxy; 
f948923
+} 
f948923
 
f948923
 namespace converter
f948923
@@ -103,4 +109,9 @@
f948923
 # define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PYTHON_MAX_ARITY, <boost/python/object_call.hpp>))
f948923
 # include BOOST_PP_ITERATE()
f948923
+    
f948923
+      detail::args_proxy operator* () const; 
f948923
+      object operator()(detail::args_proxy const &args) const; 
f948923
+      object operator()(detail::args_proxy const &args, 
f948923
+                        detail::kwds_proxy const &kwds) const; 
f948923
 
f948923
       // truth value testing
f948923
@@ -417,4 +428,60 @@
f948923
 //
f948923
 
f948923
+namespace detail 
f948923
+{
f948923
+
f948923
+class call_proxy 
f948923
+{ 
f948923
+public: 
f948923
+  call_proxy(object target) : m_target(target) {} 
f948923
+  operator object() const { return m_target;} 
f948923
+ 
f948923
+ private: 
f948923
+    object m_target; 
f948923
+}; 
f948923
+ 
f948923
+class kwds_proxy : public call_proxy 
f948923
+{ 
f948923
+public: 
f948923
+  kwds_proxy(object o = object()) : call_proxy(o) {} 
f948923
+}; 
f948923
+class args_proxy : public call_proxy 
f948923
+{ 
f948923
+public: 
f948923
+  args_proxy(object o) : call_proxy(o) {} 
f948923
+  kwds_proxy operator* () const { return kwds_proxy(*this);} 
f948923
+}; 
f948923
+} 
f948923
+ 
f948923
+template <typename U> 
f948923
+detail::args_proxy api::object_operators<U>::operator* () const 
f948923
+{ 
f948923
+  object_cref2 x = *static_cast<U const*>(this); 
f948923
+  return detail::args_proxy(x); 
f948923
+} 
f948923
+ 
f948923
+template <typename U> 
f948923
+object api::object_operators<U>::operator()(detail::args_proxy const &args) const 
f948923
+{ 
f948923
+  U const& self = *static_cast<U const*>(this); 
f948923
+  PyObject *result = PyObject_Call(get_managed_object(self, tag), 
f948923
+                                   args.operator object().ptr(), 
f948923
+                                   0); 
f948923
+  return object(detail::new_reference(result)); 
f948923
+ 
f948923
+} 
f948923
+ 
f948923
+template <typename U> 
f948923
+object api::object_operators<U>::operator()(detail::args_proxy const &args, 
f948923
+                                            detail::kwds_proxy const &kwds) const 
f948923
+{ 
f948923
+  U const& self = *static_cast<U const*>(this); 
f948923
+  PyObject *result = PyObject_Call(get_managed_object(self, tag), 
f948923
+                                   args.operator object().ptr(), 
f948923
+                                   kwds.operator object().ptr()); 
f948923
+  return object(detail::new_reference(result)); 
f948923
+ 
f948923
+}  
f948923
+
f948923
 inline object::object()
f948923
     : object_base(python::incref(Py_None))
f948923
Index: /trunk/libs/python/test/object.cpp
f948923
===================================================================
f948923
--- /trunk/libs/python/test/object.cpp (revision 45918)
f948923
+++ /trunk/libs/python/test/object.cpp (revision 47846)
f948923
@@ -187,4 +187,9 @@
f948923
     return s.slice(2,-1).slice(1,-1)  == "lo, wor";
f948923
 }
f948923
+
f948923
+object test_call(object c, object args, object kwds) 
f948923
+{ 
f948923
+    return c(*args, **kwds); 
f948923
+} 
f948923
 
f948923
 bool check_binary_operators()
f948923
@@ -378,4 +383,5 @@
f948923
     def("test_not_item", test_not_item);
f948923
 
f948923
+    def("test_call", test_call);
f948923
     def("check_binary_operators", check_binary_operators);
f948923
     def("check_inplace", check_inplace);
f948923
Index: /trunk/libs/python/test/object.py
f948923
===================================================================
f948923
--- /trunk/libs/python/test/object.py (revision 45918)
f948923
+++ /trunk/libs/python/test/object.py (revision 47846)
f948923
@@ -135,5 +135,10 @@
f948923
         Operators
f948923
 
f948923
-        
f948923
+>>> def print_args(*args, **kwds): 
f948923
+...     print args, kwds 
f948923
+>>> test_call(print_args, (0, 1, 2, 3), {'a':'A'}) 
f948923
+(0, 1, 2, 3) {'a': 'A'}
f948923
+
f948923
+
f948923
 >>> assert check_binary_operators()
f948923
 
f948923
Index: /trunk/libs/python/doc/v2/object.html
f948923
===================================================================
f948923
--- /trunk/libs/python/doc/v2/object.html (revision 45918)
f948923
+++ /trunk/libs/python/doc/v2/object.html (revision 47846)
f948923
@@ -656,4 +656,9 @@
f948923
       object operator()(A0 const&, A1 const&,...An const&) const;
f948923
 
f948923
+      detail::args_proxy operator* () const; 
f948923
+      object operator()(detail::args_proxy const &args) const; 
f948923
+      object operator()(detail::args_proxy const &args, 
f948923
+                        detail::kwds_proxy const &kwds) const; 
f948923
+
f948923
       // truth value testing
f948923
       //
f948923
@@ -705,4 +710,23 @@
f948923
       a2,...aN)
f948923
     
f948923
+
f948923
+
f948923
+object operator()(detail::args_proxy const &args) const; 
f948923
+
f948923
+
f948923
+  
Effects:
f948923
+  call object with arguments given by the tuple <varname>args</varname>
f948923
+
f948923
+
f948923
+object operator()(detail::args_proxy const &args, 
f948923
+                  detail::kwds_proxy const &kwds) const; 
f948923
+
f948923
+
f948923
+  
Effects:
f948923
+  call object with arguments given by the tuple <varname>args</varname>, and named
f948923
+  arguments given by the dictionary <varname>kwds</varname>
f948923
+
f948923
+
f948923
+
f948923
 
f948923
 operator bool_type() const;