From patchwork Thu Feb 29 16:57:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 19569 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 9821ABE080 for ; Thu, 29 Feb 2024 16:58:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0199A6286C; Thu, 29 Feb 2024 17:58:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JcUIgVFb"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 02F9261C96 for ; Thu, 29 Feb 2024 17:58:10 +0100 (CET) Received: from jasper.fritz.box (unknown [IPv6:2a00:6020:448c:6c00:69c9:7315:683e:a8b]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4948DD4A; Thu, 29 Feb 2024 17:57:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1709225877; bh=garPSutDujJXALhkhrWtBPRSlTBRaN81I895RmsaSvk=; h=From:To:Cc:Subject:Date:From; b=JcUIgVFbZGymhd4kaOW/E1FYTE/RXdVYuwCNn4UlEZUFeLGVqsbR6MYhyJo1u1Ooq EJtg5Tkg/86J6MxorXz74mRC0IL5OQYPwtBKTuj4xdbpE7LKx3yNdNuMSrAVpawRAM FoWJRWCh6GXMRhJeeopShb+vt00jV+vhQb1/9QHg= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Subject: [PATCH] libcamera: controls: Add overwriteExisting parameter to ControlList::merge Date: Thu, 29 Feb 2024 17:57:53 +0100 Message-Id: <20240229165753.154936-1-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.40.1 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" This is useful in many cases although not included in the stl. A typical usecase would be: ContolList controls = getDefaults() controls.merge(someSpecialValues, true) ... Signed-off-by: Stefan Klug --- Hey, this is my first email patch - hurray :-) Cheers, Stefan include/libcamera/controls.h | 2 +- src/libcamera/controls.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index cf942055..0bf778d8 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -368,7 +368,7 @@ public: std::size_t size() const { return controls_.size(); } void clear() { controls_.clear(); } - void merge(const ControlList &source); + void merge(const ControlList &source, bool overwriteExisting = false); bool contains(unsigned int id) const; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index b808116c..8ef29a96 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -910,10 +910,13 @@ ControlList::ControlList(const ControlInfoMap &infoMap, /** * \brief Merge the \a source into the ControlList * \param[in] source The ControlList to merge into this object + * \param[in] overwriteExisting Control if existing elements in *this shall be + * overwritten * * Merging two control lists copies elements from the \a source and inserts * them in *this. If the \a source contains elements whose key is already - * present in *this, then those elements are not overwritten. + * present in *this, then those elements are only overwritten if + * overwriteExisting is true. * * Only control lists created from the same ControlIdMap or ControlInfoMap may * be merged. Attempting to do otherwise results in undefined behaviour. @@ -921,7 +924,7 @@ ControlList::ControlList(const ControlInfoMap &infoMap, * \todo Reimplement or implement an overloaded version which internally uses * std::unordered_map::merge() and accepts a non-const argument. */ -void ControlList::merge(const ControlList &source) +void ControlList::merge(const ControlList &source, bool overwriteExisting) { /** * \todo ASSERT that the current and source ControlList are derived @@ -936,7 +939,7 @@ void ControlList::merge(const ControlList &source) */ for (const auto &ctrl : source) { - if (contains(ctrl.first)) { + if (!overwriteExisting && contains(ctrl.first)) { const ControlId *id = idmap_->at(ctrl.first); LOG(Controls, Warning) << "Control " << id->name() << " not overwritten";