def _create_body( self ): answer = [] answer.append( 'typedef %s;' % self.wrapper.wrapper_creator_type.create_typedef( 'array_wrapper_creator' ) ) answer.append( os.linesep * 2 ) doc = '' if self.declaration.type_qualifiers.has_static: answer.append( self.parent.class_var_name + '.add_static_property' ) else: if self.documentation: doc = self.documentation answer.append( self.parent.class_var_name + '.add_property' ) answer.append( '( ' ) answer.append('"%s"' % self.declaration.name ) answer.append( os.linesep + self.indent( self.PARAM_SEPARATOR ) ) temp = [ algorithm.create_identifier( self, "::boost::python::make_function" ) ] temp.append( '( ' ) temp.append( 'array_wrapper_creator(&%s)' % self.wrapper.wrapper_creator_full_name ) if not self.declaration.type_qualifiers.has_static: temp.append( os.linesep + self.indent( self.PARAM_SEPARATOR, 6 ) ) temp.append( call_policies.with_custodian_and_ward_postcall( 0, 1 ).create(self) ) temp.append( ' )' ) answer.append( ''.join( temp ) ) if doc: answer.append( os.linesep ) answer.append( self.PARAM_SEPARATOR ) answer.append( doc ) answer.append( ' );' ) return ''.join( answer )
def _create_body( self ): answer = [] answer.append( 'typedef %s;' % self.wrapper.wrapper_creator_type.create_typedef( 'array_wrapper_creator' ) ) answer.append( os.linesep * 2 ) doc = '' if self.declaration.type_qualifiers.has_static: answer.append( self.parent.class_var_name + '.add_static_property' ) else: if self.documentation: doc = self.documentation answer.append( self.parent.class_var_name + '.add_property' ) answer.append( '( ' ) answer.append('"%s"' % self.alias ) answer.append( os.linesep + self.indent( self.PARAM_SEPARATOR ) ) temp = [ algorithm.create_identifier( self, "::boost::python::make_function" ) ] temp.append( '( ' ) temp.append( 'array_wrapper_creator(&%s)' % self.wrapper.wrapper_creator_full_name ) if not self.declaration.type_qualifiers.has_static: temp.append( os.linesep + self.indent( self.PARAM_SEPARATOR, 6 ) ) temp.append( call_policies.with_custodian_and_ward_postcall( 0, 1 ).create(self) ) temp.append( ' )' ) answer.append( ''.join( temp ) ) if doc: answer.append( os.linesep ) answer.append( self.PARAM_SEPARATOR ) answer.append( doc ) answer.append( ' );' ) return ''.join( answer )
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)
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 _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 )