Exemple #1
0
    def _generate_for_pointer(self):
        doc = ''  #static property does not support documentation
        if self.declaration.type_qualifiers.has_static:
            add_property = 'add_static_property'
        else:
            if self.documentation:
                doc = self.documentation
            add_property = 'add_property'
        answer = [add_property]
        answer.append('( ')
        answer.append('"%s"' % self.alias)
        answer.append(self.PARAM_SEPARATOR)

        #according to David Abrahams:
        #http://mail.python.org/pipermail/c++-sig/2003-January/003276.html
        call_pol = call_policies.return_internal_reference().create(self)
        make_function = algorithm.create_identifier(
            self, '::boost::python::make_function')

        answer.append(
            '%(mk_func)s( (%(getter_type)s)(&%(wfname)s), %(call_pol)s )' % {
                'mk_func': make_function,
                'getter_type': self.wrapper.getter_type,
                'wfname': self.wrapper.getter_full_name,
                'call_pol': call_pol
            })

        #don't generate setter method, right now I don't know how to do it.
        if self.wrapper.has_setter:
            answer.append(self.PARAM_SEPARATOR)
            call_pol = ''
            if not self.declaration.type_qualifiers.has_static:
                call_pol = ", " + call_policies.with_custodian_and_ward_postcall(
                    1, 2).create(self)
            answer.append(
                '%(mk_func)s( (%(setter_type)s)(&%(wfname)s)%(call_pol)s )' % {
                    'mk_func': make_function,
                    'setter_type': self.wrapper.setter_type,
                    'wfname': self.wrapper.setter_full_name,
                    'call_pol': call_pol
                })
        if doc:
            answer.append(self.PARAM_SEPARATOR)
            answer.append(doc)
        answer.append(' ) ')

        code = ''.join(answer)
        if len(code) <= self.LINE_LENGTH:
            return code
        else:
            for i in range(len(answer)):
                if answer[i] == self.PARAM_SEPARATOR:
                    answer[i] = os.linesep + self.indent(
                        self.indent(self.indent(answer[i])))
            return ''.join(answer)
Exemple #2
0
    def _generate_for_pointer( self ):
        doc = '' #static property does not support documentation
        if self.declaration.type_qualifiers.has_static:
            add_property = 'add_static_property'
        else:
            if self.documentation:
                doc = self.documentation
            add_property = 'add_property'
        answer = [ add_property ]
        answer.append( '( ' )
        answer.append('"%s"' % self.alias)
        answer.append( self.PARAM_SEPARATOR )

        #according to David Abrahams:
        #http://mail.python.org/pipermail/c++-sig/2003-January/003276.html
        call_pol = call_policies.return_internal_reference().create( self )
        make_function = algorithm.create_identifier( self, '::boost::python::make_function' )

        answer.append( '%(mk_func)s( (%(getter_type)s)(&%(wfname)s), %(call_pol)s )'
                       % { 'mk_func' : make_function
                           , 'getter_type' : self.wrapper.getter_type
                           , 'wfname' : self.wrapper.getter_full_name
                           , 'call_pol' : call_pol } )

        #don't generate setter method, right now I don't know how to do it.
        if self.wrapper.has_setter:
            answer.append( self.PARAM_SEPARATOR )
            call_pol = ''
            if not self.declaration.type_qualifiers.has_static:
                call_pol = ", " + call_policies.with_custodian_and_ward_postcall( 1, 2 ).create(self)
            answer.append( '%(mk_func)s( (%(setter_type)s)(&%(wfname)s)%(call_pol)s )'
                       % { 'mk_func' : make_function
                           , 'setter_type' : self.wrapper.setter_type
                           , 'wfname' : self.wrapper.setter_full_name
                           , 'call_pol' : call_pol } )
        if doc:
            answer.append( self.PARAM_SEPARATOR )
            answer.append( doc )
        answer.append( ' ) ' )

        code = ''.join( answer )
        if len( code ) <= self.LINE_LENGTH:
            return code
        else:
            for i in range( len( answer ) ):
                if answer[i] == self.PARAM_SEPARATOR:
                    answer[i] = os.linesep + self.indent( self.indent( self.indent( answer[i] ) ) )
            return ''.join( answer )
 def _guess_call_policies(self):
     item_type = declarations.array_item_type( self.array_type )
     if python_traits.is_immutable( item_type ):
         return call_policies.default_call_policies()
     else:
         return call_policies.return_internal_reference()
 def _guess_call_policies(self):
     item_type = declarations.array_item_type(self.array_type)
     if python_traits.is_immutable(item_type):
         return call_policies.default_call_policies()
     else:
         return call_policies.return_internal_reference()