| Trees | Indices | Help |
|
|---|
|
|
1 # Copyright 2004-2008 Roman Yakovenko 2 # Distributed under the Boost Software License, Version 1.0. (See 3 # accompanying file LICENSE_1_0.txt or copy at 4 # http://www.boost.org/LICENSE_1_0.txt) 5 6 import os 7 import algorithm 8 import code_creator 9 from pygccxml import declarations 10 from pyplusplus import decl_wrappers 11 #virtual functions that returns const reference to something 12 #could not be overriden by Python. The reason is simple: 13 #in boost::python::override::operator(...) result of marshaling 14 #(Python 2 C++) is saved on stack, after functions returns the result 15 #will be reference to no where - access violetion. 16 #For example see temporal variable tester 17 18 use_enum_workaround = False21 22 PARAM_SEPARATOR = code_creator.code_creator_t.PARAM_SEPARATOR 239725 self.__decl = declaration 26 if None is arguments: 27 arguments = self.__decl.arguments 28 self.__args = arguments 29 self.__id_creator = identifier_creator3032 global use_enum_workaround 33 if not declarations.is_enum( arg.type ): 34 return False 35 if use_enum_workaround: 36 return True 37 #enum belongs to the class we are working on 38 if self.__decl.parent is declarations.enum_declaration( arg.type ).parent \ 39 and isinstance( self.__decl, declarations.constructor_t ): 40 return True 41 return False4244 if not self.__args: 45 return '' 46 boost_arg = self.__id_creator( '::boost::python::arg' ) 47 boost_obj = self.__id_creator( '::boost::python::object' ) 48 result = ['( '] 49 for arg in self.__args: 50 if 1 < len( result ): 51 result.append( self.PARAM_SEPARATOR ) 52 result.append( boost_arg ) 53 result.append( '("%s")' % arg.name ) 54 if self.__decl.use_default_arguments and arg.default_value: 55 if not declarations.is_pointer( arg.type ) or arg.default_value != '0': 56 arg_type_no_alias = declarations.remove_alias( arg.type ) 57 if declarations.is_fundamental( arg_type_no_alias ) \ 58 and declarations.is_integral( arg_type_no_alias ) \ 59 and not arg.default_value.startswith( arg_type_no_alias.decl_string ): 60 result.append( '=(%s)(%s)' % ( arg_type_no_alias.partial_decl_string 61 , arg.default_value ) ) 62 elif self.__should_use_enum_wa( arg ): 63 #Work around for bug/missing functionality in boost.python. 64 #registration order 65 result.append( '=(long)(%s)' % arg.default_value ) 66 else: 67 result.append( '=%s' % arg.default_value ) 68 else: 69 result.append( '=%s()' % boost_obj ) 70 result.append( ' )' ) 71 return ''.join( result )72 7981 args = [] 82 for index, arg in enumerate( self.__args ): 83 result = arg.type.partial_decl_string + ' ' + self.argument_name(index) 84 if arg.default_value: 85 result += '=%s' % arg.default_value 86 args.append( result ) 87 if len( args ) == 1: 88 return args[ 0 ] 89 return self.PARAM_SEPARATOR.join( args )9092 params = [] 93 for index, arg in enumerate( self.__args ): 94 params.append( decl_wrappers.python_traits.call_traits( arg.type ) 95 % self.argument_name( index ) ) 96 return ', '.join( params )100 object.__init__( self ) 101 self.__creator = creator 102 self.__controller = controller 103 self.__function = controller.function 104 self.__return_vars = return_vars[:] 105 self.__pre_return_code = None 106 self.__return_stmt = None 107 self.__result_var = result_var 108 self.__call_policy_alias = controller.register_variable_name( 'call_policies_t' )109 110 @property