"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "cplusplus/gen-operators.py" between
vips-8.10.6.tar.gz and vips-8.11.0.tar.gz

About: VIPS is a free image processing system (see also the GUI nip2).

gen-operators.py  (vips-8.10.6):gen-operators.py  (vips-8.11.0)
#!/usr/bin/env python #!/usr/bin/python3
# This file generates the member definitions and declarations for all vips # This file generates the member definitions and declarations for all vips
# operators. # operators.
# this needs pyvips # this needs pyvips
# #
# pip install --user pyvips # pip install --user pyvips
# Sample member declaration: # Sample member declaration:
# VImage invert(VOption *options = 0) const; # VImage invert(VOption *options = 0) const;
skipping to change at line 42 skipping to change at line 42
gtype_to_cpp = { gtype_to_cpp = {
GValue.gbool_type: 'bool', GValue.gbool_type: 'bool',
GValue.gint_type: 'int', GValue.gint_type: 'int',
GValue.gdouble_type: 'double', GValue.gdouble_type: 'double',
GValue.gstr_type: 'const char *', GValue.gstr_type: 'const char *',
GValue.refstr_type: 'char *', GValue.refstr_type: 'char *',
GValue.gflags_type: 'int', GValue.gflags_type: 'int',
GValue.image_type: 'VImage', GValue.image_type: 'VImage',
GValue.source_type: 'VSource', GValue.source_type: 'VSource',
GValue.target_type: 'VTarget', GValue.target_type: 'VTarget',
GValue.guint64_type: 'guint64',
type_from_name('VipsInterpolate'): 'VInterpolate',
GValue.array_int_type: 'std::vector<int>', GValue.array_int_type: 'std::vector<int>',
GValue.array_double_type: 'std::vector<double>', GValue.array_double_type: 'std::vector<double>',
GValue.array_image_type: 'std::vector<VImage>', GValue.array_image_type: 'std::vector<VImage>',
GValue.blob_type: 'VipsBlob *' GValue.blob_type: 'VipsBlob *'
} }
cplusplus_suffixes = ('*', '&') cplusplus_suffixes = ('*', '&')
cplusplus_keywords = ('case', 'switch') cplusplus_keywords = ('case', 'switch')
# values for VipsArgumentFlags # values for VipsArgumentFlags
_REQUIRED = 1 _REQUIRED = 1
_INPUT = 16 _INPUT = 16
_OUTPUT = 32 _OUTPUT = 32
_DEPRECATED = 64 _DEPRECATED = 64
_MODIFY = 128 _MODIFY = 128
# for VipsOperationFlags # for VipsOperationFlags
_OPERATION_DEPRECATED = 8 _OPERATION_DEPRECATED = 8
def get_cpp_type(gtype): def get_cpp_type(gtype):
"""Map a gtype to C++ type name we use to represent it. """Map a gtype to the C++ type name we use to represent it.
""" """
if gtype in gtype_to_cpp: if gtype in gtype_to_cpp:
return gtype_to_cpp[gtype] return gtype_to_cpp[gtype]
fundamental = gobject_lib.g_type_fundamental(gtype) fundamental = gobject_lib.g_type_fundamental(gtype)
# enum params use the C name as their name # enum params use the C name as their name
if fundamental == GValue.genum_type: if fundamental == GValue.genum_type:
return type_name(gtype) return type_name(gtype)
skipping to change at line 85 skipping to change at line 87
return '<unknown type>' return '<unknown type>'
# swap any '-' for '_' # swap any '-' for '_'
def cppize(name): def cppize(name):
return name.replace('-', '_') return name.replace('-', '_')
def generate_operation(operation_name, declaration_only=False): def generate_operation(operation_name, declaration_only=False):
intro = Introspect.get(operation_name) intro = Introspect.get(operation_name)
required_output = [name for name in intro.required_output if name != intro.m required_output = [name
ember_x] for name in intro.required_output if name != intro.member_x]
has_output = len(required_output) >= 1 has_output = len(required_output) >= 1
# Add a C++ style comment block with some additional markings (@param, # Add a C++ style comment block with some additional markings (@param,
# @return) # @return)
if declaration_only: if declaration_only:
result = '\n/**\n * {}.'.format(intro.description.capitalize()) result = f'\n/**\n * {intro.description.capitalize()}.'
if len(intro.optional_input) > 0:
result += '\n *\n * **Optional parameters**'
for name in intro.optional_input:
details = intro.details[name]
result += f'\n * - **{cppize(name)}** -- '
result += f'{details["blurb"]}, '
result += f'{get_cpp_type(details["type"])}.'
result += '\n *'
for name in intro.method_args: for name in intro.method_args:
result += '\n * @param {} {}.' \ details = intro.details[name]
.format(cppize(name), intro.details[name]['blurb']) result += f'\n * @param {cppize(name)} {details["blurb"]}.'
if has_output: if has_output:
# skip the first element # skip the first element
for name in required_output[1:]: for name in required_output[1:]:
result += '\n * @param {} {}.' \ details = intro.details[name]
.format(cppize(name), intro.details[name]['blurb']) result += f'\n * @param {cppize(name)} {details["blurb"]}.'
result += '\n * @param options Optional options.' result += '\n * @param options Set of options.'
if has_output: if has_output:
result += '\n * @return {}.' \ details = intro.details[required_output[0]]
.format(intro.details[required_output[0]]['blurb']) result += f'\n * @return {details["blurb"]}.'
result += '\n */\n' result += '\n */\n'
else: else:
result = '\n' result = '\n'
if intro.member_x is None and declaration_only: if intro.member_x is None and declaration_only:
result += 'static ' result += 'static '
if has_output: if has_output:
# the first output arg will be used as the result # the first output arg will be used as the result
cpp_type = get_cpp_type(intro.details[required_output[0]]['type']) cpp_type = get_cpp_type(intro.details[required_output[0]]['type'])
spacing = '' if cpp_type.endswith(cplusplus_suffixes) else ' ' spacing = '' if cpp_type.endswith(cplusplus_suffixes) else ' '
result += '{0}{1}'.format(cpp_type, spacing) result += f'{cpp_type}{spacing}'
else: else:
result += 'void ' result += 'void '
if not declaration_only: if not declaration_only:
result += 'VImage::' result += 'VImage::'
cplusplus_operation = operation_name cplusplus_operation = operation_name
if operation_name in cplusplus_keywords: if operation_name in cplusplus_keywords:
cplusplus_operation += '_image' cplusplus_operation += '_image'
result += '{0}( '.format(cplusplus_operation) result += f'{cplusplus_operation}( '
for name in intro.method_args: for name in intro.method_args:
details = intro.details[name] details = intro.details[name]
gtype = details['type'] gtype = details['type']
cpp_type = get_cpp_type(gtype) cpp_type = get_cpp_type(gtype)
spacing = '' if cpp_type.endswith(cplusplus_suffixes) else ' ' spacing = '' if cpp_type.endswith(cplusplus_suffixes) else ' '
result += '{0}{1}{2}, '.format(cpp_type, spacing, cppize(name)) result += f'{cpp_type}{spacing}{cppize(name)}, '
# output params are passed by reference # output params are passed by reference
if has_output: if has_output:
# skip the first element # skip the first element
for name in required_output[1:]: for name in required_output[1:]:
details = intro.details[name] details = intro.details[name]
gtype = details['type'] gtype = details['type']
cpp_type = get_cpp_type(gtype) cpp_type = get_cpp_type(gtype)
spacing = '' if cpp_type.endswith(cplusplus_suffixes) else ' ' spacing = '' if cpp_type.endswith(cplusplus_suffixes) else ' '
result += '{0}{1}*{2}, '.format(cpp_type, spacing, cppize(name)) result += f'{cpp_type}{spacing}*{cppize(name)}, '
result += 'VOption *options {0})'.format('= 0 ' if declaration_only else '') result += f'VOption *options {"= 0 " if declaration_only else ""})'
# if no 'this' available, it's a class method and they are all const # if no 'this' available, it's a class method and they are all const
if intro.member_x is not None: if intro.member_x is not None:
result += ' const' result += ' const'
if declaration_only: if declaration_only:
result += ';' result += ';'
return result return result
result += '\n{\n' result += '\n{\n'
if has_output: if has_output:
# the first output arg will be used as the result # the first output arg will be used as the result
name = required_output[0] name = required_output[0]
cpp_type = get_cpp_type(intro.details[name]['type']) cpp_type = get_cpp_type(intro.details[name]['type'])
spacing = '' if cpp_type.endswith(cplusplus_suffixes) else ' ' spacing = '' if cpp_type.endswith(cplusplus_suffixes) else ' '
result += ' {0}{1}{2};\n\n'.format(cpp_type, spacing, cppize(name)) result += f' {cpp_type}{spacing}{cppize(name)};\n\n'
result += ' call( "{0}",\n'.format(operation_name) result += f' call( "{operation_name}",\n'
result += ' (options ? options : VImage::option())' result += f' (options ? options : VImage::option())'
if intro.member_x is not None: if intro.member_x is not None:
result += '->\n' result += f'->\n'
result += ' set( "{0}", *this )'.format(intro.member_x) result += f' set( "{intro.member_x}", *this )'
all_required = intro.method_args all_required = intro.method_args
if has_output: if has_output:
# first element needs to be passed by reference # first element needs to be passed by reference
arg = cppize(required_output[0]) arg = cppize(required_output[0])
result += '->\n' result += f'->\n'
result += ' set( "{0}", &{1} )' \ result += f' set( "{required_output[0]}", &{arg} )'
.format(required_output[0], arg)
# append the remaining list # append the remaining list
all_required += required_output[1:] all_required += required_output[1:]
for name in all_required: for name in all_required:
arg = cppize(name) arg = cppize(name)
result += '->\n' result += f'->\n'
result += ' set( "{0}", {1} )'.format(name, arg) result += f' set( "{name}", {arg} )'
result += ' );\n' result += ' );\n'
if has_output: if has_output:
result += '\n' result += f'\n'
result += ' return( {0} );\n'.format(required_output[0]) result += f' return( {required_output[0]} );\n'
result += '}' result += '}'
return result return result
def generate_operators(declarations_only=False): def generate_operators(declarations_only=False):
all_nicknames = [] all_nicknames = []
def add_nickname(gtype, a, b): def add_nickname(gtype, a, b):
nickname = nickname_find(gtype) nickname = nickname_find(gtype)
 End of changes. 20 change blocks. 
29 lines changed or deleted 39 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)