Esempio n. 1
0
    def _create_with_property(self):
        name = '"%s"' % self.alias

        if self.wrapper:
            make_getter = algorithm.create_identifier(
                self, '::boost::python::make_function')
            make_setter = algorithm.create_identifier(
                self, '::boost::python::make_function')

            getter_args = [
                '(%(getter_type)s)(&%(wfname)s)' % {
                    'getter_type': self.wrapper.getter_type.decl_string,
                    'wfname': self.wrapper.getter_full_name
                }
            ]
            setter_args = [
                '(%(setter_type)s)(&%(wfname)s)' % {
                    'setter_type': self.wrapper.setter_type.decl_string,
                    'wfname': self.wrapper.setter_full_name,
                }
            ]
            if self.declaration.getter_call_policies:
                getter_args.append(
                    self.declaration.getter_call_policies.create(self))

            if declarations.is_pointer(self.declaration.decl_type):
                getter_args = getter_args[:1] + [
                    call_policies.return_internal_reference().create(self)
                ]
                if not self.declaration.type_qualifiers.has_static:
                    setter_args.append(
                        call_policies.with_custodian_and_ward_postcall(
                            1, 2).create(self))
            has_setter = self.wrapper.has_setter
        else:
            make_getter = algorithm.create_identifier(
                self, '::boost::python::make_getter')
            make_setter = algorithm.create_identifier(
                self, '::boost::python::make_setter')
            getter_args = [
                '&' + self.decl_identifier,
                self.declaration.getter_call_policies.create(self)
            ]
            setter_args = ['&' + self.decl_identifier]
            has_setter = self.declaration.is_read_only

        getter = '%(mk_func)s(%(args)s)' % {
            'mk_func': make_getter,
            'args': self.indent(self.PARAM_SEPARATOR, 6).join(getter_args)
        }

        setter = None
        if self.wrapper.has_setter:
            setter = '%(mk_func)s(%(args)s)' % {
                'mk_func': make_setter,
                'args': self.indent(self.PARAM_SEPARATOR, 6).join(setter_args)
            }

        return self._create_property(name, getter, setter)
Esempio n. 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)
Esempio n. 3
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 )
        if self.declaration.getter_call_policies:
            call_pol = self.declaration.getter_call_policies.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 self.declaration.setter_call_policies:
                call_pol = self.declaration.setter_call_policies.create( self )
            elif 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 )
Esempio n. 4
0
 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()
Esempio n. 6
0
 def _get_getter_return_policy(self):
     return call_policies.return_internal_reference().create(self)