def find_class_methods(cls): names = set() if not cls.is_abstract(): op = Vips.Operation.new(cls.name) found = False for prop in op.props: flags = op.get_argument_flags(prop.name) if not flags & Vips.ArgumentFlags.INPUT: continue if not flags & Vips.ArgumentFlags.REQUIRED: continue if GObject.type_is_a(vips_type_image, prop.value_type): found = True break if not found: gtype = Vips.type_find("VipsOperation", cls.name) names.add(Vips.nickname_find(gtype)) if len(cls.children) > 0: for child in cls.children: # not easy to get at the deprecated flag in an abtract type? if cls.name != 'VipsWrap7': names.update(find_class_methods(child)) return names
def gen_operation(cls): op = Vips.Operation.new(cls.name) gtype = Vips.type_find("VipsOperation", cls.name) nickname = Vips.nickname_find(gtype) all_required = find_required(op) result = find_first_output(op, all_required) this = find_first_input_image(op, all_required) # shallow copy required = all_required[:] if result != None: required.remove(result) if this != None: required.remove(this) # no "this" available, it's a class method if this == None: print 'static', if result == None: print 'void', else: print '%s' % gtype_to_cpp[result.value_type.name], print '%s(' % nickname, gen_arg_list(required) print ')' print ' throw( VError );'
def gen_operation(cls): op = Vips.Operation.new(cls.name) gtype = Vips.type_find("VipsOperation", cls.name) nickname = Vips.nickname_find(gtype) all_required = find_required(op) result = find_first_output(op, all_required) this = find_first_input_image(op, all_required) # shallow copy required = all_required[:] if result != None: required.remove(result) if this != None: required.remove(this) if result == None: print 'void', else: print '%s' % gtype_to_cpp[result.value_type.name], print 'VImage::%s(' % nickname, gen_arg_list(op, required) print ')' print '{' if result != None: print ' %s %s;' % (get_ctype(result), cppize(result.name)) print '' print ' call( "%s"' % nickname, first = True for prop in all_required: if first: print ',' print ' (options ? options : VImage::option())', first = False print '->' print ' ', if prop == this: print 'set( "%s", *this )' % prop.name, else: flags = op.get_argument_flags(prop.name) arg = cppize(prop.name) if flags & Vips.ArgumentFlags.OUTPUT and prop == result: arg = '&' + arg print 'set( "%s", %s )' % (prop.name, arg), print ');' if result != None: print '' print ' return( %s );' % cppize(result.name) print '}' print ''
def define_class_methods(cls): if not cls.is_abstract(): op = Vips.Operation.new(cls.name) found = False for prop in op.props: flags = op.get_argument_flags(prop.name) if flags & Vips.ArgumentFlags.INPUT and flags & Vips.ArgumentFlags.REQUIRED: if GObject.type_is_a(vips_type_image, prop.value_type): found = True break if not found: gtype = Vips.type_find("VipsOperation", cls.name) nickname = Vips.nickname_find(gtype) logging.debug('adding %s as a class method' % nickname) method = lambda *args, **kwargs: vips_image_class_method( nickname, args, kwargs) setattr(Vips.Image, nickname, classmethod(method)) if len(cls.children) > 0: for child in cls.children: # not easy to get at the deprecated flag in an abtract type? if cls.name != 'VipsWrap7': define_class_methods(child)
def gen_function(cls): op = Vips.Operation.new(cls.name) gtype = Vips.type_find("VipsOperation", cls.name) nickname = Vips.nickname_find(gtype) print '<row>' print ' <entry>%s</entry>' % nickname print ' <entry>%s</entry>' % op.get_description() print ' <entry>vips_%s()</entry>' % nickname print '</row>'
def gen_function_list(cls): if not cls.is_abstract(): gtype = Vips.type_find("VipsOperation", cls.name) nickname = Vips.nickname_find(gtype) if not nickname in generated: gen_function(cls) generated[nickname] = True if len(cls.children) > 0: for child in cls.children: gen_function_list(child)
def find_class_methods(cls): if not cls.is_abstract(): gtype = Vips.type_find("VipsOperation", cls.name) nickname = Vips.nickname_find(gtype) if not nickname in generated: gen_operation(cls) generated[nickname] = True if len(cls.children) > 0: for child in cls.children: find_class_methods(child)
def find_class_methods(cls): methods = [] skipped = [] if not cls.is_abstract(): gtype = Vips.type_find("VipsOperation", cls.name) nickname = Vips.nickname_find(gtype) if not nickname in generated: try: methods.append(gen_operation(cls)) generated[nickname] = True except Exception as e: skipped.append('// Unsupported: %s: %s' % (nickname, str(e))) if len(cls.children) > 0: for child in cls.children: m, s = find_class_methods(child) methods.extend(m) skipped.extend(s) return methods, skipped
def define_class_methods(cls): if len(cls.children) > 0: for child in cls.children: # not easy to get at the deprecated flag in an abtract type? if cls.name != 'VipsWrap7': define_class_methods(child) elif cls.is_instantiatable(): op = Vips.Operation.new(cls.name) found = False for prop in op.props: flags = op.get_argument_flags(prop.name) if flags & Vips.ArgumentFlags.INPUT and flags & Vips.ArgumentFlags.REQUIRED: if GObject.type_is_a(vips_type_image, prop.value_type): found = True break if not found: gtype = Vips.type_find("VipsOperation", cls.name) nickname = Vips.nickname_find(gtype) logging.debug('adding %s as a class method' % nickname) method = lambda *args, **kwargs: vips_image_class_method( nickname, args, kwargs) setattr(Vips.Image, nickname, classmethod(method))
def gen_operation(cls): op = Vips.Operation.new(cls.name) gtype = Vips.type_find("VipsOperation", cls.name) op_name = Vips.nickname_find(gtype) func_name = upper_camelcase(op_name) args = [] decls = [] return_types = [] return_names = [] return_values = [] input_options = [] output_options = [] method_args = [] call_values = [] images_in = 0 images_out = 0 all_props = find_required(op) for prop in all_props: name = lower_camelcase(prop.name) prop_type = get_type(prop) flags = op.get_argument_flags(prop.name) method_name = get_options_method_name(prop) if flags & Vips.ArgumentFlags.OUTPUT: if GObject.type_is_a(vips_type_image, prop.value_type): images_out += 1 else: method_args.append('%s *%s' % (name, prop_type)) return_types.append(prop_type) decls.append('var %s %s' % (name, prop_type)) return_values.append(name) output_options.append('Output%s("%s", &%s),' % (method_name, prop.name, name)) else: if GObject.type_is_a(vips_type_image, prop.value_type): images_in += 1 else: call_values.append(name) method_args.append('%s %s' % (name, prop_type)) args.append('%s %s' % (name, prop_type)) arg_name = name if GObject.type_is_a(param_enum, prop): arg_name = 'int(%s)' % arg_name input_options.append('Input%s("%s", %s),' % (method_name, prop.name, arg_name)) args.append('options ...*Option') decls.append('var err error') return_types.append('error') return_values.append('err') method_args.append('options ...*Option') call_values.append('options...') funcs = [] d = { 'op_name': op_name, 'func_name': func_name, 'args': ', '.join(args), 'decls': '\n\t'.join(decls), 'input_options': '\n\t\t'.join(input_options), 'output_options': '\n\t\t'.join(output_options), 'return_types': ', '.join(return_types), 'return_values': ', '.join(return_values), } funcs.append(emit_func(d)) if images_in == 1 and images_out == 1: d['method_args'] = ', '.join(method_args) d['call_values'] = ', '.join(call_values) funcs.append(emit_method(d)) return '\n'.join(funcs)
def gen_operation(cls): op = Vips.Operation.new(cls.name) gtype = Vips.type_find("VipsOperation", cls.name) op_name = Vips.nickname_find(gtype) func_name = upper_camelcase(op_name) args = [] decls = [] return_types = [] return_values = [] input_options = [] output_options = [] method_args = [] call_values = [] images_in = 0 images_out = 0 all_props = find_required(op) for prop in all_props: name = lower_camelcase(prop.name) prop_type = get_type(prop) flags = op.get_argument_flags(prop.name) method_name = get_options_method_name(prop) if flags & Vips.ArgumentFlags.OUTPUT: if GObject.type_is_a(vips_type_image, prop.value_type): images_out += 1 else: method_args.append("%s *%s" % (name, prop_type)) return_types.append(prop_type) decls.append("var %s %s" % (name, prop_type)) return_values.append(name) output_options.append('Output%s("%s", &%s),' % (method_name, prop.name, name)) else: if GObject.type_is_a(vips_type_image, prop.value_type): images_in += 1 else: call_values.append(name) method_args.append("%s %s" % (name, prop_type)) args.append("%s %s" % (name, prop_type)) arg_name = name if GObject.type_is_a(param_enum, prop): arg_name = "int(%s)" % arg_name input_options.append('Input%s("%s", %s),' % (method_name, prop.name, arg_name)) args.append("options ...*Option") decls.append("var err error") return_types.append("error") return_values.append("err") method_args.append("options ...*Option") call_values.append("options...") funcs = [] d = { "op_name": op_name, "func_name": func_name, "args": ", ".join(args), "decls": "\n\t".join(decls), "input_options": "\n\t\t".join(input_options), "output_options": "\n\t\t".join(output_options), "return_types": ", ".join(return_types), "return_values": ", ".join(return_values), } funcs.append(emit_func(d)) if images_in == 1 and images_out == 1: d["method_args"] = ", ".join(method_args) d["call_values"] = ", ".join(call_values) funcs.append(emit_method(d)) return "\n".join(funcs)
def gen_operation(cls): op = Vips.Operation.new(cls.name) gtype = Vips.type_find("VipsOperation", cls.name) nickname = Vips.nickname_find(gtype) all_required = find_required(op) result = find_first_output(op, all_required) this = find_first_input_image(op, all_required) this_part = '' # shallow copy required = all_required[:] if result != None: required.remove(result) if this != None: required.remove(this) this_part = '(image *Image) ' output = '' for i in range(0, 2): with_options = (i == 1) if with_options: output += '\n\n' go_name = upper_camelcase(nickname) if with_options: go_name += 'Ex' output += '// %s executes the \'%s\' operation\n' % (go_name, nickname) output += '// (see %s at http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/func-list.html)\n' % nickname output += 'func %s%s(%s)' % (this_part, go_name, gen_arg_list(op, required, with_options)) if result != None: output += ' %s' % go_types[result.value_type.name] output += ' {\n' if result != None: output += '\tvar %s %s\n' % (lower_camelcase( result.name), get_type(result)) if with_options: output += '\tif options == nil {\n' output += '\t\toptions = NewOptions()\n' output += '\t}\n' else: output += '\toptions := NewOptions()\n' output += '\tvipsCall("%s", options' % nickname options = [] for prop in all_required: method_name = get_options_method_name(prop) arg_name = '' if prop == this: arg_name = 'image' else: flags = op.get_argument_flags(prop.name) arg_name = lower_camelcase(prop.name) if flags & Vips.ArgumentFlags.OUTPUT: method_name += 'Out' if prop == result: arg_name = '&' + arg_name if GObject.type_is_a(param_enum, prop): arg_name = 'int(%s)' % arg_name options.append('.\n\t\t%s("%s", %s)' % (method_name, prop.name, arg_name)) output += '%s)\n' % ''.join(options) if result != None: output += '\treturn %s\n' % lower_camelcase(result.name) output += '}' return output