revise cpp codegen again
use f'' strings, polish formatting
This commit is contained in:
parent
6cabb3e301
commit
636e265477
@ -93,32 +93,32 @@ def generate_operation(operation_name, declaration_only=False):
|
||||
# Add a C++ style comment block with some additional markings (@param,
|
||||
# @return)
|
||||
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'\n * - **{cppize(name)}** -- '
|
||||
result += f'{details["blurb"]}, '
|
||||
result += f'{get_cpp_type(details["type"])}.'
|
||||
result += '\n *'
|
||||
|
||||
for name in intro.method_args:
|
||||
result += '\n * @param {} {}.' \
|
||||
.format(cppize(name), intro.details[name]['blurb'])
|
||||
details = intro.details[name]
|
||||
result += f'\n * @param {cppize(name)} {details["blurb"]}.'
|
||||
|
||||
if has_output:
|
||||
# skip the first element
|
||||
for name in required_output[1:]:
|
||||
result += '\n * @param {} {}.' \
|
||||
.format(cppize(name), intro.details[name]['blurb'])
|
||||
details = intro.details[name]
|
||||
result += f'\n * @param {cppize(name)} {details["blurb"]}.'
|
||||
|
||||
result += '\n * @param options Set of options.'
|
||||
|
||||
if has_output:
|
||||
result += '\n * @return {}.' \
|
||||
.format(intro.details[required_output[0]]['blurb'])
|
||||
details = intro.details[required_output[0]]
|
||||
result += f'\n * @return {details["blurb"]}.'
|
||||
|
||||
result += '\n */\n'
|
||||
else:
|
||||
@ -130,7 +130,7 @@ def generate_operation(operation_name, declaration_only=False):
|
||||
# the first output arg will be used as the result
|
||||
cpp_type = get_cpp_type(intro.details[required_output[0]]['type'])
|
||||
spacing = '' if cpp_type.endswith(cplusplus_suffixes) else ' '
|
||||
result += '{0}{1}'.format(cpp_type, spacing)
|
||||
result += f'{cpp_type}{spacing}'
|
||||
else:
|
||||
result += 'void '
|
||||
|
||||
@ -141,13 +141,13 @@ def generate_operation(operation_name, declaration_only=False):
|
||||
if operation_name in cplusplus_keywords:
|
||||
cplusplus_operation += '_image'
|
||||
|
||||
result += '{0}( '.format(cplusplus_operation)
|
||||
result += f'{cplusplus_operation}( '
|
||||
for name in intro.method_args:
|
||||
details = intro.details[name]
|
||||
gtype = details['type']
|
||||
cpp_type = get_cpp_type(gtype)
|
||||
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
|
||||
if has_output:
|
||||
@ -157,9 +157,9 @@ def generate_operation(operation_name, declaration_only=False):
|
||||
gtype = details['type']
|
||||
cpp_type = get_cpp_type(gtype)
|
||||
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 intro.member_x is not None:
|
||||
@ -177,36 +177,35 @@ def generate_operation(operation_name, declaration_only=False):
|
||||
name = required_output[0]
|
||||
cpp_type = get_cpp_type(intro.details[name]['type'])
|
||||
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 += ' (options ? options : VImage::option())'
|
||||
result += f' call( "{operation_name}",\n'
|
||||
result += f' (options ? options : VImage::option())'
|
||||
if intro.member_x is not None:
|
||||
result += '->\n'
|
||||
result += ' set( "{0}", *this )'.format(intro.member_x)
|
||||
result += f'->\n'
|
||||
result += f' set( "{intro.member_x}", *this )'
|
||||
|
||||
all_required = intro.method_args
|
||||
|
||||
if has_output:
|
||||
# first element needs to be passed by reference
|
||||
arg = cppize(required_output[0])
|
||||
result += '->\n'
|
||||
result += ' set( "{0}", &{1} )' \
|
||||
.format(required_output[0], arg)
|
||||
result += f'->\n'
|
||||
result += f' set( "{required_output[0]}", &{arg} )'
|
||||
|
||||
# append the remaining list
|
||||
all_required += required_output[1:]
|
||||
|
||||
for name in all_required:
|
||||
arg = cppize(name)
|
||||
result += '->\n'
|
||||
result += ' set( "{0}", {1} )'.format(name, arg)
|
||||
result += f'->\n'
|
||||
result += f' set( "{name}", {arg} )'
|
||||
|
||||
result += ' );\n'
|
||||
|
||||
if has_output:
|
||||
result += '\n'
|
||||
result += ' return( {0} );\n'.format(required_output[0])
|
||||
result += f'\n'
|
||||
result += f' return( {required_output[0]} );\n'
|
||||
|
||||
result += '}'
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
// bodies for vips operations
|
||||
// Sun 5 Jul 22:36:37 BST 2020
|
||||
// Mon 17 Aug 18:04:15 BST 2020
|
||||
// this file is generated automatically, do not edit!
|
||||
|
||||
VImage VImage::CMC2LCh( VOption *options ) const
|
||||
|
Loading…
Reference in New Issue
Block a user