[{"id":35394,"web_url":"https://patchwork.libcamera.org/comment/35394/","msgid":"<175515474804.3701817.17612363867668903155@neptunite.rasen.tech>","date":"2025-08-14T06:59:08","subject":"Re: [RFC PATCH v1 3/3] utils: codegen: ipc: Generate templated\n\tconstructor","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Quoting Barnabás Pőcze (2025-08-07 00:48:42)\n> Forcing the \"non-pod\" members to be initialized from `const T&` is not the\n> ideal solution because it disallows e.g. move constructors. So generate a\n> templated constructor, which members to be initialized more freely, e.g.\n> using move constructors.\n> \n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  .../libcamera_templates/core_ipa_interface.h.tmpl |  2 ++\n>  .../libcamera_templates/definition_functions.tmpl | 15 +++++++++++----\n>  .../module_ipa_interface.h.tmpl                   |  2 ++\n>  3 files changed, 15 insertions(+), 4 deletions(-)\n> \n> 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\n> index 3942e5708..93f988cd9 100644\n> --- a/utils/codegen/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl\n> +++ b/utils/codegen/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl\n> @@ -16,6 +16,8 @@\n>  \n>  {% if has_map %}#include <map>{% endif %}\n>  {% if has_string %}#include <string>{% endif %}\n> +#include <type_traits>\n> +#include <utility>\n>  {% if has_array %}#include <vector>{% endif %}\n>  \n>  #include <libcamera/controls.h>\n> diff --git a/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl\n> index 3a57a3c2c..0b5bbd933 100644\n> --- a/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl\n> +++ b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl\n> @@ -28,14 +28,21 @@ public:\n>  #ifndef __DOXYGEN__\n>         {{struct.mojom_name}}() = default;\n>  \n> +       template<\n> +       {%- for field in struct.fields %}\n> +               typename T{{loop.index}} = {{field|name}},\n> +       {%- endfor %}\n> +       {%- for field in struct.fields %}\n> +               std::enable_if_t<std::is_constructible_v<{{field|name}}, T{{loop.index}}>> * = nullptr{{\",\" if not loop.last}}\n> +       {%- endfor %}\n> +       >\n>         {{struct.mojom_name}}(\n>  {%- for field in struct.fields -%}\n> -{{\"const \" if not field|is_pod}}{{field|name}} {{\"&\" if not field|is_pod}}_{{field.mojom_name}}{{\", \" if not loop.last}}\n> +               T{{loop.index}} &&arg{{loop.index}}{{ \", \" if not loop.last }}\n>  {%- endfor -%}\n>  )\n> -               :\n> -{%- for field in struct.fields -%}\n> -{{\" \" if loop.first}}{{field.mojom_name}}(_{{field.mojom_name}}){{\", \" if not loop.last}}\n> +{%- for field in struct.fields %}\n> +               {{\": \" if loop.first else \", \"}}{{field.mojom_name}}(std::forward<T{{loop.index}}>(arg{{loop.index}}))\n>  {%- endfor %}\n>         {\n>         }\n> 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\n> index 5d70ea6a2..3913eb1fb 100644\n> --- a/utils/codegen/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl\n> +++ b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl\n> @@ -16,6 +16,8 @@\n>  \n>  {% if has_map %}#include <map>{% endif %}\n>  {% if has_string %}#include <string>{% endif %}\n> +#include <type_traits>\n> +#include <utility>\n>  {% if has_array %}#include <vector>{% endif %}\n>  \n>  #include <libcamera/base/flags.h>\n> -- \n> 2.50.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id D6C4FBEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 14 Aug 2025 06:59:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B8E5769251;\n\tThu, 14 Aug 2025 08:59:15 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9726B61436\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 14 Aug 2025 08:59:14 +0200 (CEST)","from neptunite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:d967:c4f9:b351:2e11])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 06C8E6DF;\n\tThu, 14 Aug 2025 08:58:19 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"wJy1t2Dx\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755154700;\n\tbh=jOngeN2UjNbicRHKn/xoK0VmD1lskjjQvt2lPfOo+ec=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=wJy1t2DxxPWbkcyWTipog/tcTPUFjHr2lwC/EnhNcJLYxH1Q+qQ9WWHQYd9dNSVjU\n\twP6qNL1xFfbCmLpgLEkxNk2fcbcYiVPGHxCCkV58mG4Z0ZiRovjOD70wdr1/smHyBu\n\tGt0DmEIElQleLPn71H0k/ZGIkA8OGEcNc3NicFIc=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250806154842.597155-3-barnabas.pocze@ideasonboard.com>","References":"<20250806154842.597155-1-barnabas.pocze@ideasonboard.com>\n\t<20250806154842.597155-3-barnabas.pocze@ideasonboard.com>","Subject":"Re: [RFC PATCH v1 3/3] utils: codegen: ipc: Generate templated\n\tconstructor","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 14 Aug 2025 15:59:08 +0900","Message-ID":"<175515474804.3701817.17612363867668903155@neptunite.rasen.tech>","User-Agent":"alot/0.0.0","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]