[pygccxml-commit] SF.net SVN: pygccxml: [893] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2007-02-01 06:54:08
|
Revision: 893 http://svn.sourceforge.net/pygccxml/?rev=893&view=rev Author: roman_yakovenko Date: 2007-01-31 22:54:04 -0800 (Wed, 31 Jan 2007) Log Message: ----------- improving "input_c_buffer" memory allocation adding documentation Modified Paths: -------------- pyplusplus_dev/docs/history/history.rest pyplusplus_dev/pyplusplus/function_transformers/transformers.py Added Paths: ----------- pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_c_buffer.rest Added: pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_c_buffer.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_c_buffer.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/input_c_buffer.rest 2007-02-01 06:54:04 UTC (rev 893) @@ -0,0 +1,82 @@ +================================== +``input_c_buffer`` transformer +================================== + +.. contents:: Table of contents + +---------- +Definition +---------- + +"input_c_buffer" transformer works on C buffers. It handles the translation +between a `Python`_ sequence object and the buffer. + +"input_c_buffer" transformer takes as first argument name or index of the +"buffer" argument. The argument should have "array" or "pointer" type. +The second argument should be name or index of another original function argument, +which represents array size. + +------- +Example +------- + +.. code-block:: C++ + + struct file_t{ + void write( char* buffer, int size ) const; + }; + +In order to expose ``write`` member function we need to create small wrapper: +Next `Py++`_ code does it for you: + + .. code-block:: Python + + from pyplusplus import module_builder + from pyplusplus import function_transformers as FT + + mb = module_builder.module_builder_t( ... ) + f = mb.class_( 'file_t' ) + f.mem_fun( 'write' ).add_transformation( FT.input_c_buffer( 'buffer', 'size' ) ) + +What you see below is the relevant pieces of generated code: + + .. code-block:: C++ + + #include "__convenience.pypp.hpp" //Py++ header file, which contains few convenience function + + #include <vector> + + #include <iterator> + + namespace bp = boost::python; + + static void write_8883fea8925bad9911e6c5a4015ed106( ::file_t const & inst, boost::python::object buffer ){ + int size2 = boost::python::len(buffer); + std::vector< char > native_buffer; + native_buffer.reserve( size2 ); + pyplus_conv::ensure_uniform_sequence< char >( buffer ); + pyplus_conv::copy_sequence( buffer, std::back_inserter( native_buffer), boost::type< char >() ); + inst.write(&native_buffer[0], size2); + } + + BOOST_PYTHON_MODULE(...){ + ... + bp::class_< file_t >( "file_t" ) + .def( + "write" + , (void (*)( ::file_t const &,boost::python::object ))( &write_8883fea8925bad9911e6c5a4015ed106 ) + , ( bp::arg("inst"), bp::arg("buffer") ) ); + } + +.. _`Py++` : ./../pyplusplus.html +.. _`Boost.Python`: http://www.boost.org/libs/python/doc/index.html +.. _`Python`: http://www.python.org +.. _`GCC-XML`: http://www.gccxml.org + +.. + Local Variables: + mode: indented-text + indent-tabs-mode: nil + sentence-end-double-space: t + fill-column: 70 + End: Modified: pyplusplus_dev/docs/history/history.rest =================================================================== --- pyplusplus_dev/docs/history/history.rest 2007-02-01 05:50:00 UTC (rev 892) +++ pyplusplus_dev/docs/history/history.rest 2007-02-01 06:54:04 UTC (rev 893) @@ -43,16 +43,28 @@ * Declaration of virtual functions that have an exception specification with an empty throw was fixed. Now the exception specification is generated properly. Many thanks to Martin Preisler for reporting the bug. - + +.. line-separator + 2. Added exposing of copy constructors and "operator=". "operator=" is exposed under "assign" name. - + +.. line-separator + 3. Added new call policy - `as_tuple`_ -.. _`as_tuple` : ../documentation/functions/call_policies.html +.. _`as_tuple` : ../documentation/functions/call_policies.html#as-tuple 4. Added initial support for multi-module development. +.. line-separator + +5. `input_c_buffer`_ - new functions transformation, which allows to pass a Python + sequence to function, instead of pair of arguments: pointer to buffer and size. + +.. _`input_c_buffer` : ../documentation/functions/transformation/built_in/input_c_buffer.html + + ------------- Version 0.8.5 ------------- Modified: pyplusplus_dev/pyplusplus/function_transformers/transformers.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2007-02-01 05:50:00 UTC (rev 892) +++ pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2007-02-01 06:54:04 UTC (rev 893) @@ -455,7 +455,9 @@ buffer_var = controller.declare_variable( declarations.dummy_type_t( "std::vector< %s >" % self.buffer_item_type.decl_string ) , "native_" + self.buffer_arg.name ) - + + controller.add_pre_call_code( '%s.reserve( %s );' % ( buffer_var, size_var ) ) + copy_pylist2arr = _seq2vector.substitute( type=self.buffer_item_type , pylist=w_buffer_arg.name , native_array=buffer_var ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |