From patchwork Fri Aug 15 12:31:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 24141 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 3D3C5C3295 for ; Fri, 15 Aug 2025 12:31:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CDD7B6925F; Fri, 15 Aug 2025 14:31:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jtE2w+SH"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5AA0B61443 for ; Fri, 15 Aug 2025 14:31:43 +0200 (CEST) Received: from pb-laptop.local (185.221.141.188.nat.pool.zt.hu [185.221.141.188]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5D7106A8; Fri, 15 Aug 2025 14:30:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1755261048; bh=eChmiVSgIH2h0YYqRMrCyKfGiAnQdeqwwBcOWSwAYHk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jtE2w+SH6XkvUNh1FsQWUAEkbfLMRqOP5X3fkneIL0QyYSMgRkdQJZoJZFdIVQ8hW hd9yO0yO7jOo5bs6K0iow5yyqNfCclrIoWZASNv3CekSa1iTQKN0dwwo48Pu/P8qk6 A+tMgoPrxoqQoDumSzepFn8ZViq2/jw12lOshuxQ= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org, Paul Elder , Laurent Pinchart Subject: [RFC PATCH v2 3/3] utils: codegen: ipc: Generate templated constructor Date: Fri, 15 Aug 2025 14:31:38 +0200 Message-ID: <20250815123138.2213654-3-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250815123138.2213654-1-barnabas.pocze@ideasonboard.com> References: <20250815123138.2213654-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Reviewed-by: Paul Elder Reviewed-by: Laurent Pinchart --- changes in v2: * use `std::is_convertible_v` to avoid accidental use of explicit constructors/conversion operators --- .../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(-) -- 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 {% endif %} {% if has_string %}#include {% endif %} +#include +#include {% if has_array %}#include {% endif %} #include diff --git a/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl index 3a57a3c2c..dec25558f 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> * = 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(_{{field.mojom_name}})) {%- 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 {% endif %} {% if has_string %}#include {% endif %} +#include +#include {% if has_array %}#include {% endif %} #include