[pygccxml-commit] SF.net SVN: pygccxml:[1467] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-12-15 20:53:53
|
Revision: 1467 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1467&view=rev Author: roman_yakovenko Date: 2008-12-15 20:53:49 +0000 (Mon, 15 Dec 2008) Log Message: ----------- adding ability to create "function transformation" for pure virtual functions Modified Paths: -------------- pyplusplus_dev/pyplusplus/function_transformers/controllers.py pyplusplus_dev/pyplusplus/function_transformers/function_transformation.py pyplusplus_dev/pyplusplus/function_transformers/templates.py pyplusplus_dev/pyplusplus/module_creator/creators_wizard.py pyplusplus_dev/unittests/autoconfig.py pyplusplus_dev/unittests/bool_by_ref_tester.py pyplusplus_dev/unittests/data/bool_by_ref_to_be_exported.hpp pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp Modified: pyplusplus_dev/pyplusplus/function_transformers/controllers.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/controllers.py 2008-12-13 21:24:18 UTC (rev 1466) +++ pyplusplus_dev/pyplusplus/function_transformers/controllers.py 2008-12-15 20:53:49 UTC (rev 1467) @@ -337,7 +337,26 @@ def default_controller( self ): return self.__default_cntrl +class pure_virtual_mem_fun_controller_t( virtual_mem_fun_controller_t ): + def __init__( self, function ): + virtual_mem_fun_controller_t.__init__(self, function) + + class override_fun_controller_t( virtual_mem_fun_controller_t.override_fun_controller_t ): + def __init__( self, function ): + virtual_mem_fun_controller_t.override_fun_controller_t.__init__(self, function) + + @property + def template( self ): + return templates.pure_virtual_mem_fun.override + class default_fun_controller_t( virtual_mem_fun_controller_t.default_fun_controller_t ): + def __init__( self, function ): + virtual_mem_fun_controller_t.default_fun_controller_t.__init__(self,function) + + @property + def template( self ): + return templates.pure_virtual_mem_fun.default + #TODO: FT for constructor #~ class constructor_controller_t( controller_base_t ): Modified: pyplusplus_dev/pyplusplus/function_transformers/function_transformation.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/function_transformation.py 2008-12-13 21:24:18 UTC (rev 1466) +++ pyplusplus_dev/pyplusplus/function_transformers/function_transformation.py 2008-12-15 20:53:49 UTC (rev 1467) @@ -18,6 +18,8 @@ if isinstance( function.parent, declarations.class_t ): if declarations.VIRTUALITY_TYPES.NOT_VIRTUAL == function.virtuality: self.__controller = controllers.mem_fun_controller_t( function ) + elif declarations.VIRTUALITY_TYPES.PURE_VIRTUAL == function.virtuality: + self.__controller = controllers.pure_virtual_mem_fun_controller_t( function ) else: self.__controller = controllers.virtual_mem_fun_controller_t( function ) else: Modified: pyplusplus_dev/pyplusplus/function_transformers/templates.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/templates.py 2008-12-13 21:24:18 UTC (rev 1466) +++ pyplusplus_dev/pyplusplus/function_transformers/templates.py 2008-12-15 20:53:49 UTC (rev 1467) @@ -55,6 +55,40 @@ , '}' ])) +class pure_virtual_mem_fun: + override = Template( os.linesep.join([ + 'virtual $return_type $function_name( $arg_declarations )$constness $throw{' + , ' namespace bpl = boost::python;' + , ' if( bpl::override $py_function_var = this->get_override( "$function_alias" ) ){' + , ' $declare_py_variables' + , ' $py_pre_call' + , ' ${save_py_result}bpl::call<bpl::object>( $py_function_var.ptr()$py_arg_expressions );' + , ' $py_post_call' + , ' $py_return' + , ' }' + , ' else{' + , ' PyErr_SetString(PyExc_NotImplementedError, "Attempted calling Pure Virtual function that is not implemented :$function_name");' + , ' boost::python::throw_error_already_set();' + , ' }' + , '}' + ])) + + default = Template( os.linesep.join([ + 'static $return_type $unique_function_name( $arg_declarations ){' + , ' $declare_variables' + , ' $pre_call' + , ' if( dynamic_cast< $wrapper_class $wrapped_inst_constness* >( boost::addressof( $wrapped_inst ) ) ){' + , ' PyErr_SetString(PyExc_NotImplementedError, "Attempted calling Pure Virtual function that is not implemented :$function_name");' + , ' boost::python::throw_error_already_set();' + , ' }' + , ' else{' + , ' $save_result$wrapped_inst.$function_name($arg_expressions);' + , ' }' + , ' $post_call' + , ' $return' + , '}' + ])) + #TODO: FT for constructor #~ class constructor: #~ #User cannot apply transformation on constructor of abstract class Modified: pyplusplus_dev/pyplusplus/module_creator/creators_wizard.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creators_wizard.py 2008-12-13 21:24:18 UTC (rev 1466) +++ pyplusplus_dev/pyplusplus/module_creator/creators_wizard.py 2008-12-15 20:53:49 UTC (rev 1467) @@ -30,8 +30,12 @@ else: maker_cls = code_creators.mem_fun_t elif decl.virtuality == VIRTUALITY_TYPES.PURE_VIRTUAL: - fwrapper_cls = code_creators.mem_fun_pv_wrapper_t - maker_cls = code_creators.mem_fun_pv_t + if decl.transformations: + maker_cls = code_creators.mem_fun_v_transformed_t + fwrapper_cls = code_creators.mem_fun_v_transformed_wrapper_t + else: + fwrapper_cls = code_creators.mem_fun_pv_wrapper_t + maker_cls = code_creators.mem_fun_pv_t else: if decl.transformations: fwrapper_cls = code_creators.mem_fun_v_transformed_wrapper_t Modified: pyplusplus_dev/unittests/autoconfig.py =================================================================== --- pyplusplus_dev/unittests/autoconfig.py 2008-12-13 21:24:18 UTC (rev 1466) +++ pyplusplus_dev/unittests/autoconfig.py 2008-12-15 20:53:49 UTC (rev 1467) @@ -30,8 +30,9 @@ @staticmethod def create_sconstruct(): code = [ - "env = Environment()" - , "env.SharedLibrary( target=r'%(target)s'" + "import sys" + , "env = Environment()" + , "t = env.SharedLibrary( target=r'%(target)s'" , " , source=[ %(sources)s ]" , " , LIBS=[ %s ]" % ','.join( [ 'r"%s"' % lib for lib in scons_config.libs ] ) , " , LIBPATH=[ %s ]" % ','.join( [ 'r"%s"' % path for path in scons_config.libpath ] ) @@ -39,8 +40,9 @@ , " , CCFLAGS=[ %s ]" % ','.join( [ 'r"%s"' % flag for flag in scons.ccflags ] ) , " , SHLIBPREFIX=''" , " , SHLIBSUFFIX='%s'" % scons.suffix #explicit better then implicit - , ")" - , "env.AddPostAction('%(target)s', 'mt.exe -nologo -manifest %(target)s.pyd.manifest -outputresource:%(target)s.pyd;2' )" ] + , ")" + , "if 'linux' not in sys.platform:" + , " env.AddPostAction(t, 'mt.exe -nologo -manifest %(target)s.pyd.manifest -outputresource:%(target)s.pyd;2' )" ] return os.linesep.join( code ) #I need this in order to allow Python to load just compiled modules Modified: pyplusplus_dev/unittests/bool_by_ref_tester.py =================================================================== --- pyplusplus_dev/unittests/bool_by_ref_tester.py 2008-12-13 21:24:18 UTC (rev 1466) +++ pyplusplus_dev/unittests/bool_by_ref_tester.py 2008-12-15 20:53:49 UTC (rev 1467) @@ -26,6 +26,8 @@ set_flag = mb.mem_fun( '::tests::listener::listen' ) set_flag.add_transformation( ft.inout(2) ) + set_flag = mb.mem_fun( '::tests::listener::listenPV' ) + set_flag.add_transformation( ft.inout(2) ) def run_tests(self, module): class list1 ( module.listener ): @@ -33,11 +35,16 @@ module.listener.__init__(self) def listen( self, id, name, skip): print "Python: listen called with", id, name, skip - return 11## Test always returns True... - + return skip + 1 ## Test always returns True... + def listenPV( self, id, name, skip): + print "Python: listenPV called with", id, name, skip + return skip + 1 ## Test always returns True... + c = list1() ret = module.callListener( c ) print ret + ret = module.callListenerPV ( c ) + print ret def create_suite(): suite = unittest.TestSuite() Modified: pyplusplus_dev/unittests/data/bool_by_ref_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/bool_by_ref_to_be_exported.hpp 2008-12-13 21:24:18 UTC (rev 1466) +++ pyplusplus_dev/unittests/data/bool_by_ref_to_be_exported.hpp 2008-12-15 20:53:49 UTC (rev 1467) @@ -7,15 +7,34 @@ public: virtual void listen(int id, const std::string& name, int& skip) { throw std::runtime_error ( std::string ("Virtual function listener::listen called!") ); - } + } + virtual void listenPV(int id, const std::string& name, int& skip) = 0; }; bool callListener ( listener* myListener) { int skip = 10; std::cout << "C++: Calling myListener->listen\n"; myListener->listen(100, "test", skip); - std::cout << "C++: Called OK " << skip <<"\n"; + if (skip == 10) + throw std::runtime_error( "PROBLEM in C++: Called Returned with same value " ); + else + std::cout << "C++: Called OK " << skip <<"\n"; + return skip; } + +bool callListenerPV ( listener* myListener) { + int skip = 10; + std::cout << "C++: Calling myListener->listen\n"; + myListener->listenPV(100, "test", skip); + if (skip == 10){ + throw std::runtime_error( "PROBLEM in C++: Called Returned with same value " ); + } + else + std::cout << "C++: Called OK " << skip <<"\n"; + return skip; } + + +} Modified: pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2008-12-13 21:24:18 UTC (rev 1466) +++ pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2008-12-15 20:53:49 UTC (rev 1467) @@ -249,7 +249,7 @@ virtual void render_queue_ended( int group_id , const std::string& invocation - , bool& repeat_this_invocation ){}; + , bool& repeat_this_invocation ) = 0; }; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |