From patchwork Fri Mar 6 15:59:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2989 Return-Path: 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 72362628B5 for ; Fri, 6 Mar 2020 17:00:22 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1A1C424B for ; Fri, 6 Mar 2020 17:00:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1583510422; bh=Y9NNa4ZR945n/emsic1UFPuZDNHwoiB30UwD/XOCVic=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZOgx8w2BdGCOnZRxwggoJrGg+D/vgks+/3b6E9HXriJICJbebN2/5BZVRBI3iJstA MxwNW52Y++mZeUpdLBThZrcPnC5N3H0XnVVMhZtIPBmF2w/q27C0QLkcCBlVi1ZDa3 xgwR9eUKRBB8YQnRbmKUaXgHvojR+lu+f+G3RC6o= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Mar 2020 17:59:47 +0200 Message-Id: <20200306160002.30549-18-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200306160002.30549-1-laurent.pinchart@ideasonboard.com> References: <20200306160002.30549-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 17/32] libcamera: controls: Allow passing an std::initializer list to set() 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: , X-List-Received-Date: Fri, 06 Mar 2020 16:00:22 -0000 For array controls, the ControlList::set() function takes a value as a type convertible to Span. This allows passing an std::array or an std::vector in addition to an explicit Span, but doesn't accept an std::initializer list as Span has no constructor that takes an initializer list. Callers are thus forced to create temporary objects explicitly, which isn't nice. Fix the issue by providing a ControlList::set() function that takes an std::initializer_list, and convert it to a Span internally. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/controls.h | 10 ++++++++++ src/libcamera/controls.cpp | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 1e24ae30ab36..2102d5711384 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -335,6 +335,16 @@ public: val->set(value); } + template + void set(const Control &ctrl, const std::initializer_list &value) + { + ControlValue *val = find(ctrl.id()); + if (!val) + return; + + val->set(Span>{ value.begin(), value.size() }); + } + const ControlValue &get(unsigned int id) const; void set(unsigned int id, const ControlValue &value); diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index a1eca992884c..3dd740e5f17e 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -802,6 +802,12 @@ bool ControlList::contains(unsigned int id) const * object that the list refers to. */ +/** + * \fn template \ + * void ControlList::set(const Control &ctrl, const std::initializer_list &value) + * \copydoc ControlList::set(const Control &ctrl, const V &value) + */ + /** * \brief Get the value of control \a id * \param[in] id The control numerical ID