Revision: 703
http://svn.sourceforge.net/pygccxml/?rev=703&view=rev
Author: roman_yakovenko
Date: 2006-11-09 13:20:11 -0800 (Thu, 09 Nov 2006)
Log Message:
-----------
adding few classes and functions for array <=> list copy
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/code_repository/convenience.py
Modified: pyplusplus_dev/pyplusplus/code_repository/convenience.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_repository/convenience.py 2006-11-09 11:40:41 UTC (rev 702)
+++ pyplusplus_dev/pyplusplus/code_repository/convenience.py 2006-11-09 21:20:11 UTC (rev 703)
@@ -78,6 +78,63 @@
}
}
+template< class Iterator, class Inserter >
+void copy_container( Iterator begin, Iterator end, Inserter inserter ){
+ for( Iterator index = begin; index != end; ++index )
+ inserter( *index );
+}
+
+template< class Inserter >
+void copy_sequence( boost::python::object const& seq, Inserter inserter ){
+ index_type length = boost::python::len( seq );
+ for( index_type index = 0; index < length; ++index ){
+ inserter( seq[index] );
+ }
+}
+
+struct list_inserter{
+ list_inserter( boost::python::list& py_list )
+ : m_py_list( py_list )
+ {}
+
+ template< class T >
+ void operator()( T const & value ){
+ m_py_list.append( value );
+ }
+private:
+ boost::python::list& m_py_list;
+};
+
+template < class T >
+struct array_inserter_t{
+ array_inserter_t( T* array, index_type size )
+ : m_array( array )
+ , m_curr_pos( 0 )
+ , m_size( size )
+ {}
+
+ void operator()( boost::python::object const & item ){
+ if( m_size <= m_curr_pos ){
+ std::stringstream err;
+ err << "Index out of range. Array size is" << m_size << ", "
+ << "current position is" << m_curr_pos << ".";
+ raise_error( PyExc_ValueError, err.str().c_str() );
+ }
+ m_array[ m_curr_pos ] = boost::python::extract< T >( item );
+ m_curr_pos += 1;
+ }
+
+private:
+ T* m_array;
+ index_type m_curr_pos;
+ const index_type m_size;
+};
+
+template< class T>
+array_inserter_t<T> array_inserter( T* array, index_type size ){
+ return array_inserter_t<T>( array, size );
+}
+
} /*pyplusplus*/ } /*convenience*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|