From patchwork Sat Feb 29 16:42:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2934 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 27341627B1 for ; Sat, 29 Feb 2020 17:43:28 +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 BA1A4A28 for ; Sat, 29 Feb 2020 17:43:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1582994607; bh=C+HNPoqHGm77ozAdT3bjmZwyOkAxGPmKZhu1ad5gpm8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IfCOe6DHQxnxG9JX8puYICDbm3AlZi/d+Q4rZJOoPcWFsZzno+6rmWiOTt1If4uVy SoGiTt5xfMVuZURkeMvdQMkZkJQbLQOmOm7Qf4vZ1bmPOy3Zw3YTXItZN4BO/0MxyL rIXzc0Hu6mg3xm6ugjV9RvfxafjqSBQAnXXUQMYI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 29 Feb 2020 18:42:40 +0200 Message-Id: <20200229164254.23604-18-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> References: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 17/31] 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: Sat, 29 Feb 2020 16:43:31 -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 d70a6bc4b83a..f99c90e934c1 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 f4089c8ffb4e..829eea6f4240 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -806,6 +806,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