[pygccxml-commit] SF.net SVN: pygccxml:[1471] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-12-16 23:22:37
|
Revision: 1471 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1471&view=rev Author: roman_yakovenko Date: 2008-12-16 22:16:38 +0000 (Tue, 16 Dec 2008) Log Message: ----------- adding ability to assign variable an address Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/member_variable.py pyplusplus_dev/pyplusplus/code_repository/ctypes_integration.py pyplusplus_dev/unittests/member_variables_tester.py Modified: pyplusplus_dev/pyplusplus/code_creators/member_variable.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2008-12-16 13:16:38 UTC (rev 1470) +++ pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2008-12-16 22:16:38 UTC (rev 1471) @@ -656,15 +656,26 @@ def __init__(self, variable, wrapper=None ): member_variable_base_t.__init__( self, variable=variable, wrapper=wrapper ) + def has_setter( self ) : + return declarations.is_pointer( self.declaration.type ) \ + and not declarations.is_const( self.declaration.type ) + def _create_m_var( self ): + param_sep = self.PARAM_SEPARATOR + if self.has_setter() or self.documentation: + param_sep = os.linesep + self.indent( self.PARAM_SEPARATOR, 3 ) answer = [ 'add_property' ] answer.append( '( ' ) answer.append('"%s"' % self.alias) - answer.append( self.PARAM_SEPARATOR ) + answer.append( param_sep ) answer.append( 'pyplus_conv::make_addressof_getter(&%s)' % self.decl_identifier ) + if self.has_setter(): + answer.append( param_sep ) + answer.append( 'pyplus_conv::make_address_setter(&%s)' + % self.decl_identifier ) if self.documentation: - answer.append( self.PARAM_SEPARATOR ) + answer.append( param_sep ) answer.append( self.documentation ) answer.append( ' ) ' ) return ''.join( answer ) Modified: pyplusplus_dev/pyplusplus/code_repository/ctypes_integration.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/ctypes_integration.py 2008-12-16 13:16:38 UTC (rev 1470) +++ pyplusplus_dev/pyplusplus/code_repository/ctypes_integration.py 2008-12-16 22:16:38 UTC (rev 1471) @@ -41,6 +41,16 @@ return size_t( boost::addressof( inst.*offset ) ); } +template< typename TType, typename TMemVarType> +void +assign_address( TType* inst_ptr, TMemVarType TType::* offset, size_t address ){ + if( !inst_ptr ){ + throw std::runtime_error( "unable to dereference null pointer" ); + } + TType& inst = *inst_ptr; + inst.*offset = reinterpret_cast< TMemVarType >( address ); +} + template< typename TType > size_t addressof_inst( const TType* inst_ptr){ @@ -61,6 +71,17 @@ , boost::mpl::vector< size_t, const TType* >() ); } +template< typename TType, typename TMemVarType > +boost::python::object +make_address_setter( TMemVarType TType::* offset ){ + namespace bpl = boost::python; + namespace pyppc = pyplusplus::convenience; + return bpl::make_function( boost::bind( &pyppc::assign_address< TType, TMemVarType >, _1, offset, _2 ) + , bpl::default_call_policies() + , boost::mpl::vector< void, TType*, size_t >() ); +} + + template< typename TType > boost::python::object make_addressof_inst_getter(){ Modified: pyplusplus_dev/unittests/member_variables_tester.py =================================================================== --- pyplusplus_dev/unittests/member_variables_tester.py 2008-12-16 13:16:38 UTC (rev 1470) +++ pyplusplus_dev/unittests/member_variables_tester.py 2008-12-16 22:16:38 UTC (rev 1471) @@ -97,6 +97,15 @@ data = data_type.from_address( image.data ) for j in range(5): self.failUnless( j == data[j] ) + + int_array = ctypes.c_int * 5 + array = int_array() + for i in range( 5 ): + array[i] = 2*i + image.data = ctypes.addressof(array) + data = data_type.from_address( image.data ) + for j in range(5): + self.failUnless( j*2 == data[j] ) data_type = ctypes.POINTER( ctypes.c_int ) data = data_type.from_address( module.image_t.none_image ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |