Revision: 882
http://svn.sourceforge.net/pygccxml/?rev=882&view=rev
Author: roman_yakovenko
Date: 2007-01-28 11:11:58 -0800 (Sun, 28 Jan 2007)
Log Message:
-----------
allow construction of c-tuple from any sequence
Modified Paths:
--------------
pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/custom_rvalue.cpp
pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/test.py
pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/tuples.hpp
Modified: pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/custom_rvalue.cpp
===================================================================
--- pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/custom_rvalue.cpp 2007-01-28 13:14:56 UTC (rev 881)
+++ pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/custom_rvalue.cpp 2007-01-28 19:11:58 UTC (rev 882)
@@ -61,7 +61,7 @@
typedef boost::tuples::tuple< float, float, float> colour_tuple_type;
- typedef bpl::from_py_tuple< colour_tuple_type > converter_type;
+ typedef bpl::from_py_sequence< colour_tuple_type > converter_type;
static void* convertible(PyObject* obj){
return converter_type::convertible( obj );
@@ -74,7 +74,7 @@
void* memory_chunk = the_storage->storage.bytes;
float red(0.0), green(0.0), blue(0.0);
- boost::tuples::tie(red, green, blue) = converter_type::construct_c_tuple( obj );
+ boost::tuples::tie(red, green, blue) = converter_type::to_c_tuple( obj );
colour_t* colour = new (memory_chunk) colour_t(red, green, blue);
data->convertible = memory_chunk;
Modified: pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/test.py
===================================================================
--- pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/test.py 2007-01-28 13:14:56 UTC (rev 881)
+++ pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/test.py 2007-01-28 19:11:58 UTC (rev 882)
@@ -13,12 +13,16 @@
self.failUnlessRaises( TypeError, tuples.triplet_ret_ptr_110 )
self.failUnless( tuples.test_triplet_val_000( (0,0,0) ) )
self.failUnless( tuples.test_triplet_cref_010( (0,1,0) ) )
+ self.failUnless( tuples.test_triplet_val_000( [0,0,0] ) )
+ self.failUnless( tuples.test_triplet_cref_010( [0,1,0] ) )
self.failUnlessRaises( TypeError, tuples.test_triplet_ref_110, (1,1,0) )
self.failUnlessRaises( TypeError, tuples.test_triplet_ptr_101, (1,0,1) )
def test_from_sequence( self ):
self.failUnless( custom_rvalue.test_val_010( (0,1,0) ) )
self.failUnless( custom_rvalue.test_cref_000( (0,0,0) ) )
+ self.failUnless( custom_rvalue.test_val_010( [0,1,0] ) )
+ self.failUnless( custom_rvalue.test_cref_000( [0,0,0] ) )
self.failUnlessRaises( Exception, custom_rvalue.test_ref_111, (1,1,1) )
self.failUnlessRaises( Exception, custom_rvalue.test_ptr_101, (1,0,1) )
self.failUnlessRaises( Exception, custom_rvalue.test_cptr_110, (1,1,0) )
Modified: pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/tuples.hpp
===================================================================
--- pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/tuples.hpp 2007-01-28 13:14:56 UTC (rev 881)
+++ pyplusplus_dev/docs/troubleshooting_guide/automatic_conversion/tuples.hpp 2007-01-28 19:11:58 UTC (rev 882)
@@ -139,7 +139,7 @@
template< class TTuple>
-struct from_py_tuple{
+struct from_py_sequence{
typedef TTuple tuple_type;
@@ -148,16 +148,16 @@
static void*
convertible(PyObject* py_obj){
- if( !PyTuple_Check( py_obj ) ){
+ if( !PySequence_Check( py_obj ) ){
return 0;
}
- python::tuple py_tuple( handle<>( borrowed( py_obj ) ) );
- if( tuples::length< TTuple >::value != len( py_tuple ) ){
+ python::object py_sequence( handle<>( borrowed( py_obj ) ) );
+ if( tuples::length< TTuple >::value != len( py_sequence ) ){
return 0;
}
- if( convertible_impl( py_tuple, mpl::int_< 0 >(), length_type() ) ){
+ if( convertible_impl( py_sequence, mpl::int_< 0 >(), length_type() ) ){
return py_obj;
}
else{
@@ -173,17 +173,17 @@
TTuple* c_tuple = new (memory_chunk) TTuple();
data->convertible = memory_chunk;
- python::tuple py_tuple( handle<>( borrowed( py_obj ) ) );
- construct_impl( py_tuple, *c_tuple, mpl::int_< 0 >(), length_type() );
+ python::object py_sequence( handle<>( borrowed( py_obj ) ) );
+ construct_impl( py_sequence, *c_tuple, mpl::int_< 0 >(), length_type() );
}
- static TTuple construct_c_tuple( PyObject* py_obj ){
+ static TTuple to_c_tuple( PyObject* py_obj ){
if( !convertible( py_obj ) ){
throw std::runtime_error( "Unable to construct boost::tuples::tuple from Python object!" );
}
TTuple c_tuple;
- python::tuple py_tuple( handle<>( borrowed( py_obj ) ) );
- construct_impl( py_tuple, c_tuple, mpl::int_< 0 >(), length_type() );
+ python::object py_sequence( handle<>( borrowed( py_obj ) ) );
+ construct_impl( py_sequence, c_tuple, mpl::int_< 0 >(), length_type() );
return c_tuple;
}
@@ -191,41 +191,41 @@
template< int index, int length >
static bool
- convertible_impl( const python::tuple& py_tuple, mpl::int_< index >, mpl::int_< length > ){
+ convertible_impl( const python::object& py_sequence, mpl::int_< index >, mpl::int_< length > ){
typedef typename tuples::element< index, TTuple>::type element_type;
- object element = py_tuple[index];
+ object element = py_sequence[index];
extract<element_type> type_checker( element );
if( !type_checker.check() ){
return false;
}
else{
- return convertible_impl( py_tuple, details::increment_index<index>(), length_type() );
+ return convertible_impl( py_sequence, details::increment_index<index>(), length_type() );
}
}
template< int length >
static bool
- convertible_impl( const python::tuple& py_tuple, mpl::int_< length >, mpl::int_< length > ){
+ convertible_impl( const python::object& py_sequence, mpl::int_< length >, mpl::int_< length > ){
return true;
}
template< int index, int length >
static void
- construct_impl( const python::tuple& py_tuple, TTuple& c_tuple, mpl::int_< index >, mpl::int_< length > ){
+ construct_impl( const python::object& py_sequence, TTuple& c_tuple, mpl::int_< index >, mpl::int_< length > ){
typedef typename tuples::element< index, TTuple>::type element_type;
- object element = py_tuple[index];
+ object element = py_sequence[index];
c_tuple.template get< index >() = extract<element_type>( element );
- construct_impl( py_tuple, c_tuple, details::increment_index<index>(), length_type() );
+ construct_impl( py_sequence, c_tuple, details::increment_index<index>(), length_type() );
}
template< int length >
static void
- construct_impl( const python::tuple& py_tuple, TTuple& c_tuple, mpl::int_< length >, mpl::int_< length > )
+ construct_impl( const python::object& py_sequence, TTuple& c_tuple, mpl::int_< length >, mpl::int_< length > )
{}
};
@@ -235,8 +235,8 @@
to_python_converter< TTuple, to_py_tuple<TTuple> >();
- converter::registry::push_back( &from_py_tuple<TTuple>::convertible
- , &from_py_tuple<TTuple>::construct
+ converter::registry::push_back( &from_py_sequence<TTuple>::convertible
+ , &from_py_sequence<TTuple>::construct
, type_id<TTuple>() );
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|