def __call__(self, variable, hint=None): if not isinstance(variable, declarations.variable_t): return None assert hint in ('get', 'set') if not declarations.is_reference(variable.decl_type): return None no_ref = declarations.remove_reference(variable.decl_type) base_type = declarations.remove_const(no_ref) if python_traits.is_immutable(base_type): #the relevant code creator will generate code, that will return this member variable #by value return decl_wrappers.default_call_policies() if not isinstance(base_type, declarations.declarated_t): return None base_type = declarations.remove_alias(base_type) declaration = base_type.declaration if declarations.is_class_declaration(declaration): return None if declaration.is_abstract: return None if declarations.has_destructor( declaration ) and not declarations.has_public_destructor(declaration): return None if not declarations.has_copy_constructor(declaration): return None if hint == 'get': #if we rich this line, it means that we are able to create an obect using #copy constructor. if declarations.is_const(no_ref): return decl_wrappers.return_value_policy( decl_wrappers.copy_const_reference) else: return decl_wrappers.return_value_policy( decl_wrappers.copy_non_const_reference) else: return decl_wrappers.default_call_policies()
def __call__(self, calldef, hint=None): if not isinstance( calldef, declarations.calldef_t ): return None if isinstance( calldef, declarations.constructor_t ): return None return_type = declarations.remove_alias( calldef.return_type ) if isinstance( return_type, declarations.reference_t ) \ and isinstance( return_type.base, declarations.const_t ): return decl_wrappers.return_value_policy( decl_wrappers.copy_const_reference ) if declarations.is_same( return_type, self.__const_wchar_pointer ): return decl_wrappers.return_value_policy( decl_wrappers.return_by_value ) if opaque_types_manager.find_out_opaque_decl( return_type, ensure_opaque_decl=True ): return decl_wrappers.return_value_policy( decl_wrappers.return_opaque_pointer ) return None
def __call__(self, calldef, hint=None): if not isinstance( calldef, declarations.calldef_t ): return None if not isinstance( calldef, declarations.member_operator_t ): return None if calldef.symbol != '[]': return None return_type = declarations.remove_cv( calldef.return_type ) if declarations.is_reference( return_type ): return_type = declarations.remove_reference( return_type ) if python_traits.is_immutable( return_type ): if declarations.is_const( calldef.return_type ): return decl_wrappers.return_value_policy( decl_wrappers.copy_const_reference ) else: return decl_wrappers.return_value_policy( decl_wrappers.copy_non_const_reference ) else: return decl_wrappers.return_internal_reference()
def __call__( self, variable, hint=None ): if not isinstance( variable, declarations.variable_t ): return None assert hint in ( 'get', 'set' ) if not declarations.is_reference( variable.type ): return None no_ref = declarations.remove_reference( variable.type ) base_type = declarations.remove_const( no_ref ) if python_traits.is_immutable( base_type ): #the relevant code creator will generate code, that will return this member variable #by value return decl_wrappers.default_call_policies() if not isinstance( base_type, declarations.declarated_t ): return None base_type = declarations.remove_alias( base_type ) decl = base_type.declaration if declarations.is_class_declaration( decl ): return None if decl.is_abstract: return None if declarations.has_destructor( decl ) and not declarations.has_public_destructor( decl ): return None if not declarations.has_copy_constructor(decl): return None if hint == 'get': #if we rich this line, it means that we are able to create an obect using #copy constructor. if declarations.is_const( no_ref ): return decl_wrappers.return_value_policy( decl_wrappers.copy_const_reference ) else: return decl_wrappers.return_value_policy( decl_wrappers.copy_non_const_reference ) else: return decl_wrappers.default_call_policies()
def __call__( self, calldef, hint=None ): if not isinstance( calldef, declarations.calldef_t ): return None if isinstance( calldef, declarations.constructor_t ): return None return_type = declarations.remove_alias( calldef.return_type ) void_ptr = declarations.pointer_t( declarations.void_t() ) const_void_ptr = declarations.pointer_t( declarations.const_t( declarations.void_t() ) ) if declarations.is_same( return_type, void_ptr ) \ or declarations.is_same( return_type, const_void_ptr ): return decl_wrappers.return_value_policy( decl_wrappers.return_opaque_pointer ) return None
def exportFunctions( mb ): """export utility functions.""" ## include all free functions mb.namespace("alignlib").free_functions().include() # change these functions to use handles. for prefix in ( "makeEVDParameters", "makeNormalDistributionParameters"): try: mb.free_functions( lambda mem_fun: mem_fun.name.startswith( prefix )).call_policies = \ return_value_policy( manage_new_object ) except RuntimeError: print "could not find any function with prefix %s" % prefix ####################################################################################### ####################################################################################### ####################################################################################### ## patches to exclude problematic functions for prefix in ("getMapResidue", "makeAlignatorDotsWrap", "getDefaultPalette" ): try: mb.free_functions( lambda mem_fun: mem_fun.name.startswith( prefix )).exclude() except RuntimeError: print "could not find declaration for %s" % prefix
from environment import settings from pyplusplus import decl_wrappers from pyplusplus.decl_wrappers import return_self from pyplusplus.decl_wrappers import return_internal_reference from pyplusplus.decl_wrappers import with_custodian_and_ward from pyplusplus.decl_wrappers import copy_const_reference from pyplusplus.decl_wrappers import copy_non_const_reference from pyplusplus.decl_wrappers import manage_new_object from pyplusplus.decl_wrappers import reference_existing_object from pyplusplus.decl_wrappers import return_by_value from pyplusplus.decl_wrappers import return_opaque_pointer from pyplusplus.decl_wrappers import return_value_policy db = { "::FX::fx2powerprimes" : return_value_policy( return_by_value ) , "::FX::FX4Splitter::getBottomLeft" : return_value_policy( reference_existing_object ) , "::FX::FX4Splitter::getBottomRight" : return_value_policy( reference_existing_object ) , "::FX::FX4Splitter::getTopLeft" : return_value_policy( reference_existing_object ) , "::FX::FX4Splitter::getTopRight" : return_value_policy( reference_existing_object ) , "::FX::FXAccelTable::targetOfAccel" : return_internal_reference() , "::FX::FXACL::owner" : return_internal_reference() , "::FX::FXACL::Permissions::setAll" : return_self() , "::FX::FXACL::Permissions::setAppend" : return_self() , "::FX::FXACL::Permissions::setCopyOnWrite" : return_self() , "::FX::FXACL::Permissions::setCreateDirs" : return_self() , "::FX::FXACL::Permissions::setCreateFiles" : return_self() , "::FX::FXACL::Permissions::setDeleteDirs" : return_self() , "::FX::FXACL::Permissions::setDeleteFiles" : return_self() , "::FX::FXACL::Permissions::setExecute" : return_self() , "::FX::FXACL::Permissions::setGenExecute" : return_self()
def set_call_policies(mb): #for func in mb.calldefs(): # if "QMemArray" in func.name: # print "HERE!", func.name, func.parent.name, [x.name for x in func.arguments] #sys.exit(0) #first of all call policies defined within data base for fname, call_pol in call_policies.db.items(): #print fname try: if fname.startswith( '::FX::FX' ): mb.member_functions( fname ).call_policies = call_pol else: mb.calldefs( fname ).call_policies = call_pol except: print "ERROR, skipping! was:",sys.exc_info()[0],sys.exc_info()[1] try: copy_funcs = mb.calldefs( lambda decl: 'FXGL' in decl.parent.name and decl.name == 'copy' ) copy_funcs.call_policies = decl_wrappers.return_value_policy( decl_wrappers.manage_new_object ) except: print "ERROR, skipping! was:",sys.exc_info()[0],sys.exc_info()[1] try: take_funcs = mb.calldefs( lambda decl: 'QPtrVector<' in decl.parent.name \ and decl.name == 'take' \ and declarations.is_pointer( decl.return_type ) ) # Set reference_existing object only on the overload not returning a bool take_funcs.call_policies = decl_wrappers.return_value_policy( decl_wrappers.reference_existing_object ) except: print "ERROR, skipping! was:",sys.exc_info()[0],sys.exc_info()[1] try: mb.calldefs( 'manufacture' ).call_policies \ = decl_wrappers.return_value_policy( decl_wrappers.manage_new_object ) mb.calldefs( 'getMetaClass' ).call_policies \ = decl_wrappers.return_value_policy( decl_wrappers.reference_existing_object ) except: print "ERROR, skipping! was:",sys.exc_info()[0],sys.exc_info()[1] #third calculated return_by_value = decl_wrappers.return_value_policy( decl_wrappers.return_by_value ) return_internal_ref = decl_wrappers.return_internal_reference() const_t = declarations.const_t pointer_t = declarations.pointer_t #~ system_wide = { #~ pointer_t( declarations.char_t() ) : return_by_value #~ , pointer_t( declarations.wchar_t() ) : return_by_value #~ #used in 3/4 d/f mat/vec classes #~ , pointer_t( declarations.float_t() ) : return_internal_ref #~ , pointer_t( const_t( declarations.float_t() ) ) : return_internal_ref #~ , pointer_t( declarations.double_t() ) : return_internal_ref #~ , pointer_t( const_t( declarations.double_t() ) ) : return_internal_ref #~ } #~ for type_, policy in system_wide.items(): #~ mb.calldefs( return_type=type_ ).call_policies = policy for name in ['::FX::FXVec4d', '::FX::FXVec4f', '::FX::FXVec3d', '::FX::FXVec3f', '::FX::FXVec2d', '::FX::FXVec2f', '::FX::QMemArray<unsigned char>']: try: mb.casting_operators( name ).call_policies = return_internal_ref except: print "ERROR, skipping! was:",sys.exc_info()[0],sys.exc_info()[1] return None