Message ID | 20250806154842.597155-3-barnabas.pocze@ideasonboard.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Quoting Barnabás Pőcze (2025-08-07 00:48:42) > Forcing the "non-pod" members to be initialized from `const T&` is not the > ideal solution because it disallows e.g. move constructors. So generate a > templated constructor, which members to be initialized more freely, e.g. > using move constructors. > > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> > --- > .../libcamera_templates/core_ipa_interface.h.tmpl | 2 ++ > .../libcamera_templates/definition_functions.tmpl | 15 +++++++++++---- > .../module_ipa_interface.h.tmpl | 2 ++ > 3 files changed, 15 insertions(+), 4 deletions(-) > > diff --git a/utils/codegen/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl b/utils/codegen/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl > index 3942e5708..93f988cd9 100644 > --- a/utils/codegen/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl > +++ b/utils/codegen/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl > @@ -16,6 +16,8 @@ > > {% if has_map %}#include <map>{% endif %} > {% if has_string %}#include <string>{% endif %} > +#include <type_traits> > +#include <utility> > {% if has_array %}#include <vector>{% endif %} > > #include <libcamera/controls.h> > diff --git a/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl > index 3a57a3c2c..0b5bbd933 100644 > --- a/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl > +++ b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl > @@ -28,14 +28,21 @@ public: > #ifndef __DOXYGEN__ > {{struct.mojom_name}}() = default; > > + template< > + {%- for field in struct.fields %} > + typename T{{loop.index}} = {{field|name}}, > + {%- endfor %} > + {%- for field in struct.fields %} > + std::enable_if_t<std::is_constructible_v<{{field|name}}, T{{loop.index}}>> * = nullptr{{"," if not loop.last}} > + {%- endfor %} > + > > {{struct.mojom_name}}( > {%- for field in struct.fields -%} > -{{"const " if not field|is_pod}}{{field|name}} {{"&" if not field|is_pod}}_{{field.mojom_name}}{{", " if not loop.last}} > + T{{loop.index}} &&arg{{loop.index}}{{ ", " if not loop.last }} > {%- endfor -%} > ) > - : > -{%- for field in struct.fields -%} > -{{" " if loop.first}}{{field.mojom_name}}(_{{field.mojom_name}}){{", " if not loop.last}} > +{%- for field in struct.fields %} > + {{": " if loop.first else ", "}}{{field.mojom_name}}(std::forward<T{{loop.index}}>(arg{{loop.index}})) > {%- endfor %} > { > } > diff --git a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl > index 5d70ea6a2..3913eb1fb 100644 > --- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl > +++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl > @@ -16,6 +16,8 @@ > > {% if has_map %}#include <map>{% endif %} > {% if has_string %}#include <string>{% endif %} > +#include <type_traits> > +#include <utility> > {% if has_array %}#include <vector>{% endif %} > > #include <libcamera/base/flags.h> > -- > 2.50.1 >
diff --git a/utils/codegen/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl b/utils/codegen/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl index 3942e5708..93f988cd9 100644 --- a/utils/codegen/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl +++ b/utils/codegen/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl @@ -16,6 +16,8 @@ {% if has_map %}#include <map>{% endif %} {% if has_string %}#include <string>{% endif %} +#include <type_traits> +#include <utility> {% if has_array %}#include <vector>{% endif %} #include <libcamera/controls.h> diff --git a/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl index 3a57a3c2c..0b5bbd933 100644 --- a/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl +++ b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl @@ -28,14 +28,21 @@ public: #ifndef __DOXYGEN__ {{struct.mojom_name}}() = default; + template< + {%- for field in struct.fields %} + typename T{{loop.index}} = {{field|name}}, + {%- endfor %} + {%- for field in struct.fields %} + std::enable_if_t<std::is_constructible_v<{{field|name}}, T{{loop.index}}>> * = nullptr{{"," if not loop.last}} + {%- endfor %} + > {{struct.mojom_name}}( {%- for field in struct.fields -%} -{{"const " if not field|is_pod}}{{field|name}} {{"&" if not field|is_pod}}_{{field.mojom_name}}{{", " if not loop.last}} + T{{loop.index}} &&arg{{loop.index}}{{ ", " if not loop.last }} {%- endfor -%} ) - : -{%- for field in struct.fields -%} -{{" " if loop.first}}{{field.mojom_name}}(_{{field.mojom_name}}){{", " if not loop.last}} +{%- for field in struct.fields %} + {{": " if loop.first else ", "}}{{field.mojom_name}}(std::forward<T{{loop.index}}>(arg{{loop.index}})) {%- endfor %} { } diff --git a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl index 5d70ea6a2..3913eb1fb 100644 --- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl +++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl @@ -16,6 +16,8 @@ {% if has_map %}#include <map>{% endif %} {% if has_string %}#include <string>{% endif %} +#include <type_traits> +#include <utility> {% if has_array %}#include <vector>{% endif %} #include <libcamera/base/flags.h>
Forcing the "non-pod" members to be initialized from `const T&` is not the ideal solution because it disallows e.g. move constructors. So generate a templated constructor, which members to be initialized more freely, e.g. using move constructors. Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> --- .../libcamera_templates/core_ipa_interface.h.tmpl | 2 ++ .../libcamera_templates/definition_functions.tmpl | 15 +++++++++++---- .../module_ipa_interface.h.tmpl | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-)