[libcamera-devel] [PATCH v2 2/5] generate fixed- and variable-sized Span Controls
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Tue Apr 5 18:24:22 CEST 2022
Hi Christian,
Thank you for the patch.
On Tue, Apr 05, 2022 at 01:42:12AM +0100, Christian Rauch via libcamera-devel wrote:
> This defines Controls with a 'size' as either variable-sized Span<T> or as
> fixed-sized Span<T,N>.
>
> Signed-off-by: Christian Rauch <Rauch.Christian at gmx.de>
> ---
> utils/gen-controls.py | 33 +++++++++++++++++++++++----------
> 1 file changed, 23 insertions(+), 10 deletions(-)
>
> diff --git a/utils/gen-controls.py b/utils/gen-controls.py
> index 3f99b5e2..4cadf160 100755
> --- a/utils/gen-controls.py
> +++ b/utils/gen-controls.py
> @@ -7,6 +7,7 @@
> # gen-controls.py - Generate control definitions from YAML
>
> import argparse
> +from math import prod
I'd prefer
import math
and math.prod() below, to avoid future namespace clashes.
> import string
> import sys
> import yaml
> @@ -22,6 +23,26 @@ def format_description(description):
> return '\n'.join([(line and ' * ' or ' *') + line for line in description])
>
>
> +def get_ctrl_type_format(ctrl):
This should be named get_ctrl_type() as it returns the control type.
> + ctrl_type = ctrl['type']
> + ctrl_size_arr = ctrl.get('size')
> + ctrl_is_span = ctrl_size_arr is not None
> + if ctrl_is_span:
> + ctrl_span_size = prod(ctrl_size_arr) if len(ctrl_size_arr) > 0 else None
You can move this to the "elif ctrl_is_span" below.
> +
> + if ctrl_type == 'string':
> + return 'std::string'
> + elif ctrl_is_span:
> + if ctrl_span_size:
> + # fixed-sized Span
> + return 'Span<const {}, {}>'.format(ctrl_type, ctrl_span_size)
We're increasingly standardizing on the f'...' string formatting method,
which here would be
return f'Span<const {ctrl_type}, {ctrl_span_size}>'
> + else:
> + # variable-sized Span
> + return 'Span<const {}>'.format(ctrl_type)
Same here.
> + else:
> + return ctrl_type
> +
> +
> def generate_cpp(controls):
> enum_doc_start_template = string.Template('''/**
> * \\enum ${name}Enum
> @@ -50,11 +71,7 @@ ${description}
> name, ctrl = ctrl.popitem()
> id_name = snake_case(name).upper()
>
> - ctrl_type = ctrl['type']
> - if ctrl_type == 'string':
> - ctrl_type = 'std::string'
> - elif ctrl.get('size'):
> - ctrl_type = 'Span<const %s>' % ctrl_type
> + ctrl_type = get_ctrl_type_format(ctrl)
>
> info = {
> 'name': name,
> @@ -135,11 +152,7 @@ def generate_h(controls):
>
> ids.append('\t' + id_name + ' = ' + str(id_value) + ',')
>
> - ctrl_type = ctrl['type']
> - if ctrl_type == 'string':
> - ctrl_type = 'std::string'
> - elif ctrl.get('size'):
> - ctrl_type = 'Span<const %s>' % ctrl_type
> + ctrl_type = get_ctrl_type_format(ctrl)
Nice change overall :-)
>
> info = {
> 'name': name,
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list