[pygccxml-commit] SF.net SVN: pygccxml: [825] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-12-31 11:27:04
|
Revision: 825 http://svn.sourceforge.net/pygccxml/?rev=825&view=rev Author: roman_yakovenko Date: 2006-12-31 03:27:03 -0800 (Sun, 31 Dec 2006) Log Message: ----------- updating docs Modified Paths: -------------- pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest pyplusplus_dev/pyplusplus/function_transformers/transformers.py Added Paths: ----------- pyplusplus_dev/docs/documentation/functions/transformation/built_in/modify_type.rest Modified: pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest 2006-12-31 09:34:53 UTC (rev 824) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/built_in.rest 2006-12-31 11:27:03 UTC (rev 825) @@ -16,6 +16,8 @@ * ``inout`` +* ``modify_type`` + * ``input_static_array`` * ``output_static_array`` Added: pyplusplus_dev/docs/documentation/functions/transformation/built_in/modify_type.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/built_in/modify_type.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/built_in/modify_type.rest 2006-12-31 11:27:03 UTC (rev 825) @@ -0,0 +1,78 @@ +=========================== +``modify_type`` transformer +=========================== + +.. contents:: Table of contents + +---------- +Definition +---------- + +"modify_type" transformer changes type of the function argument. + +"modify_type" transformer takes two arguments: + +1. name or index of the original function argument + +2. a callable, which takes as argument reference to type and returns new type + +New in version grater than 0.8.5. + +Known limits +------------ + +Implicit conversion should exist between new type and the old one. + +------- +Example +------- + +.. code-block:: C++ + + #include <string> + + inline void hello_world( std::string& hw ){ + hw = "hello world!"; + } + +Lets say that you need to expose ``hello_world`` function. As you know +``std::string`` is mapped to `Python`_ string, which is immutable type, so you +have to create small wrapper for the function. Next `Py++`_ code does it for you: + + .. code-block:: Python + + from pygccxml import declarations + from pyplusplus import module_builder + from pyplusplus import function_transformers as FT + + mb = module_builder.module_builder_t( ... ) + hw = mb.mem_fun( 'hello_world' ) + hw.add_transformation( FT.modify_type(0, declarations.remove_reference) ) + +What you see below is the relevant pieces of generated code: + + .. code-block:: C++ + + namespace bp = boost::python; + + static void hello_world_a3478182294a057b61508c30b1361318( ::std::string hw ){ + ::hello_world(hw); + } + + BOOST_PYTHON_MODULE(...){ + ... + bp::def( "hello_world", &hello_world_a3478182294a057b61508c30b1361318 ); + } + +.. _`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/pyplusplus/function_transformers/transformers.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2006-12-31 09:34:53 UTC (rev 824) +++ pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2006-12-31 11:27:03 UTC (rev 825) @@ -14,6 +14,7 @@ - L{inout_t} - L{input_array_t} - L{output_array_t} + - L{type_modifier_t} """ import os import string This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |