[pygccxml-commit] SF.net SVN: pygccxml:[1756] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2009-08-24 19:55:22
|
Revision: 1756
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1756&view=rev
Author: roman_yakovenko
Date: 2009-08-24 19:55:14 +0000 (Mon, 24 Aug 2009)
Log Message:
-----------
adding ability to override virtual protected member functions from Python
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/code_creators/calldef.py
pyplusplus_dev/unittests/data/function_adaptor_to_be_exported.hpp
pyplusplus_dev/unittests/function_adaptor_tester.py
Modified: pyplusplus_dev/pyplusplus/code_creators/calldef.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/calldef.py 2009-08-18 18:02:47 UTC (rev 1755)
+++ pyplusplus_dev/pyplusplus/code_creators/calldef.py 2009-08-24 19:55:14 UTC (rev 1756)
@@ -332,7 +332,7 @@
if hasattr( self.declaration, 'adaptor' ) and self.declaration.adaptor:
result = "%s( %s )" % ( self.declaration.adaptor, result )
-
+
return result
class mem_fun_pv_wrapper_t( calldef_wrapper_t ):
@@ -530,7 +530,7 @@
def _create_impl(self):
answer = [ self.create_function() ]
- answer.append( os.linesep )
+ answer.append( '' )
answer.append( self.create_default_function() )
return os.linesep.join( answer )
@@ -681,12 +681,12 @@
def create_function_ref_code(self, use_function_alias=False):
if use_function_alias:
return '%s( &%s )' \
- % ( self.function_type_alias, self.wrapper.full_name() )
+ % ( self.function_type_alias, self.wrapper.default_full_name() )
elif self.declaration.create_with_signature:
return '(%s)(&%s)' \
- % ( self.wrapper.function_type().partial_decl_string, self.wrapper.full_name() )
+ % ( self.wrapper.function_type().partial_decl_string, self.wrapper.default_full_name() )
else:
- return '&%s' % self.wrapper.full_name()
+ return '&%s' % self.wrapper.default_full_name()
class mem_fun_protected_v_wrapper_t( calldef_wrapper_t ):
def __init__( self, function):
@@ -695,6 +695,9 @@
def full_name(self):
return self.parent.full_name + '::' + self.declaration.name
+ def default_full_name(self):
+ return self.parent.full_name + '::default_' + self.declaration.alias
+
def function_type(self):
return declarations.member_function_type_t(
return_type=self.declaration.return_type
@@ -729,7 +732,7 @@
template.append( 'else{' )
native_precall_code = self.declaration.override_native_precall_code
if native_precall_code:
- template.append( self.indent( os.linesep.join( native_precall_code ) ) )
+ template.append( self.indent( os.linesep.join( native_precall_code ) ) )
template.append( self.indent('%(return_)sthis->%(wrapped_class)s::%(name)s( %(args)s );') )
template.append( '}' )
template = os.linesep.join( template )
@@ -753,9 +756,31 @@
answer.append( '}' )
return os.linesep.join( answer )
+
+ def create_default_body(self):
+ function_call = declarations.call_invocation.join( self.declaration.partial_name
+ , [ self.function_call_args() ] )
+ body = self.wrapped_class_identifier() + '::' + function_call + ';'
+ if not declarations.is_void( self.declaration.return_type ):
+ body = 'return ' + body
+ precall_code = self.declaration.default_precall_code
+ if precall_code:
+ body = os.linesep.join( precall_code ) + os.linesep + body
+ return body
+
+ def create_default_function( self ):
+ answer = [ self.create_declaration('default_' + self.declaration.alias) + '{' ]
+ answer.append( self.indent( self.create_default_body() ) )
+ answer.append( '}' )
+ return os.linesep.join( answer )
+
def _create_impl(self):
- return self.create_function()
+ answer = [ self.create_function() ]
+ answer.append( '' )
+ answer.append( self.create_default_function() )
+ return os.linesep.join( answer )
+
class mem_fun_protected_pv_t( calldef_t ):
def __init__( self, function, wrapper ):
calldef_t.__init__( self, function=function, wrapper=wrapper )
@@ -1035,7 +1060,7 @@
def __init__( self, constructor ):
code_creator.code_creator_t.__init__( self )
declaration_based.declaration_based_t.__init__( self, declaration=constructor )
-
+
@property
def parent_class( self ):
return self.declaration.parent
@@ -1080,11 +1105,11 @@
def __init__( self, constructor ):
code_creator.code_creator_t.__init__( self )
declaration_based.declaration_based_t.__init__( self, declaration=constructor )
-
+
@property
def parent_class( self ):
return self.declaration.parent
-
+
def _create_constructor_call( self ):
return algorithm.create_identifier( self, self.parent_class.decl_string ) + '()'
Modified: pyplusplus_dev/unittests/data/function_adaptor_to_be_exported.hpp
===================================================================
--- pyplusplus_dev/unittests/data/function_adaptor_to_be_exported.hpp 2009-08-18 18:02:47 UTC (rev 1755)
+++ pyplusplus_dev/unittests/data/function_adaptor_to_be_exported.hpp 2009-08-24 19:55:14 UTC (rev 1756)
@@ -42,5 +42,24 @@
};
+class Foo
+{
+public:
+ Foo() { }
+ virtual ~Foo() { }
+public:
+ virtual int virtual_public()
+ {
+ return 1;
+ }
+ int call_virtual_protected(){
+ return virtual_protected();
+ }
+protected:
+ virtual int virtual_protected()
+ {
+ return 2;
+ }
+};
#endif//__function_adaptor_to_be_exported_hpp__
Modified: pyplusplus_dev/unittests/function_adaptor_tester.py
===================================================================
--- pyplusplus_dev/unittests/function_adaptor_tester.py 2009-08-18 18:02:47 UTC (rev 1755)
+++ pyplusplus_dev/unittests/function_adaptor_tester.py 2009-08-24 19:55:14 UTC (rev 1756)
@@ -30,7 +30,31 @@
mfuns.add_override_native_precall_code( '//add_override_native_precall_code' )
mb.class_('base3_t' ).add_wrapper_code( '//just a comment to force Py++ create wrapper' )
mb.mem_fun( '::derived_t::get_two' ).alias = 'get2'
+ Foo = mb.class_('Foo')
+ for f in [ 'virtual_public', 'virtual_protected' ]:
+ f = Foo.mem_fun( f )
+ f.add_default_precall_code( '//add_default_precall_code' )
+ f.add_override_precall_code( '//add_override_precall_code' )
+ f.add_override_native_precall_code( '//add_override_native_precall_code' )
+ def create_foo_derived(self, module):
+ class pyfoo( module.Foo ):
+ def __init__( self ):
+ module.Foo.__init__( self )
+
+ def virtual_protected( self ):
+ return 3
+ return pyfoo( );
+
+ def create_foo_derived2(self, module):
+ class pyfoo2( module.Foo ):
+ def __init__( self ):
+ module.Foo.__init__( self )
+
+ def virtual_protected( self ):
+ return module.Foo.virtual_protected( self )
+ return pyfoo2( );
+
def run_tests( self, module):
foo = module.foo_t()
self.failUnless( foo.get_zero() == 0 )
@@ -38,6 +62,16 @@
self.failUnless( module.foo_t.get_two() == 2 )
self.failUnless( module.get_one() == 1 )
+ pyfoo = self.create_foo_derived( module )
+ self.failUnless( pyfoo.virtual_public() == 1 )
+ self.failUnless( pyfoo.virtual_protected() == 3 )
+ self.failUnless( pyfoo.call_virtual_protected() == 3 )
+
+ pyfoo2 = self.create_foo_derived2( module )
+ self.failUnless( pyfoo2.virtual_public() == 1 )
+ self.failUnless( pyfoo2.virtual_protected() == 2 )
+ self.failUnless( pyfoo2.call_virtual_protected() == 2 )
+
def create_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite(tester_t))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|