utils: codegen: ipc: Generate templated constructor

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>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Barnabás Pőcze
2025-08-04 15:53:50 +02:00
parent 19549be1e6
commit a1053561ed
3 changed files with 15 additions and 4 deletions

View File

@@ -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>

View File

@@ -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_convertible_v<T{{loop.index}}&&, {{field|name}}>> * = 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}} &&_{{field.mojom_name}}{{ ", " 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}}>(_{{field.mojom_name}}))
{%- endfor %}
{
}

View File

@@ -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>