From patchwork Tue Jan 13 00:08:00 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 25748 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 A33A4C32DE for ; Tue, 13 Jan 2026 00:09:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3A8AB61FFB; Tue, 13 Jan 2026 01:09:18 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="C75crtFw"; 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 90CF161FBB for ; Tue, 13 Jan 2026 01:09:15 +0100 (CET) Received: from pendragon.ideasonboard.com (81-175-209-152.bb.dnainternet.fi [81.175.209.152]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id E3F8EBCA for ; Tue, 13 Jan 2026 01:08:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1768262930; bh=3Lf3x50+ATkUhpAAFRKWHCsJniBHxNzC3uzR9CcRQOM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=C75crtFwKFBv5F/cXEKgkJt52KmVafxKyjw50/IcEgK2IWlZwY99jvmQqaMt87NAR 2+I5qR6eudt1mi2wdv8awDjz/++COVQOVcx+XpKFQQuzOgCBoGyPTI8n2rw4TaYiAO NLoHIeDO/9NKbc0tlGokT5QlG2KL23pl7lvE6wNc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 28/36] libcamera: value_node: Add mutable children accessors Date: Tue, 13 Jan 2026 02:08:00 +0200 Message-ID: <20260113000808.15395-29-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260113000808.15395-1-laurent.pinchart@ideasonboard.com> References: <20260113000808.15395-1-laurent.pinchart@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" At two at() functions that return mutable pointer to child nodes, based on an index for lists and a key for dictionaries. The API differs from const children accessors that use operator[] and return a reference in order to allow better error handling: while the const accessors return a reference to a global instance of an empty ValueNode when the requested child doesn't exist, a mutable accessor can't do the same without allowing modifying the empty global instance. Signed-off-by: Laurent Pinchart --- include/libcamera/internal/value_node.h | 2 ++ src/libcamera/value_node.cpp | 41 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/include/libcamera/internal/value_node.h b/include/libcamera/internal/value_node.h index 56d200e1cf27..c285be4957ed 100644 --- a/include/libcamera/internal/value_node.h +++ b/include/libcamera/internal/value_node.h @@ -228,9 +228,11 @@ public: ConstDictAdapter asDict() const { return ConstDictAdapter{ list_ }; } ConstListAdapter asList() const { return ConstListAdapter{ list_ }; } + ValueNode *at(std::size_t index); const ValueNode &operator[](std::size_t index) const; bool contains(std::string_view key) const; + ValueNode *at(std::string_view key); const ValueNode &operator[](std::string_view key) const; ValueNode *add(std::unique_ptr child); diff --git a/src/libcamera/value_node.cpp b/src/libcamera/value_node.cpp index 3c56b47bf79d..50b23284f930 100644 --- a/src/libcamera/value_node.cpp +++ b/src/libcamera/value_node.cpp @@ -384,6 +384,24 @@ template struct ValueNode::Accessor>; * \return An adapter of unspecified type compatible with range-based for loops */ +/** + * \brief Retrieve the element from list ValueNode by index + * \param[in] index The element index + * + * This function retrieves an element of the ValueNode. Only ValueNode + * instances of List type associate elements with index, calling this function + * on other types of instances or with an invalid index returns a null pointer. + * + * \return The ValueNode as an element of the list + */ +ValueNode *ValueNode::at(std::size_t index) +{ + if (type_ != Type::List || index >= size()) + return nullptr; + + return list_[index].value.get(); +} + /** * \brief Retrieve the element from list ValueNode by index * \param[in] index The element index @@ -419,6 +437,29 @@ bool ValueNode::contains(std::string_view key) const return dictionary_.find(key) != dictionary_.end(); } +/** + * \brief Retrieve a member by key from the dictionary + * \param[in] key The element key + * + * This function retrieves a member of a ValueNode by \a key. Only ValueNode + * instances of Dictionary type associate elements with keys, calling this + * function on other types of instances or with a nonexistent key returns a null + * pointer. + * + * \return The ValueNode corresponding to the \a key member + */ +ValueNode *ValueNode::at(std::string_view key) +{ + if (type_ != Type::Dictionary) + return nullptr; + + auto iter = dictionary_.find(key); + if (iter == dictionary_.end()) + return nullptr; + + return iter->second; +} + /** * \brief Retrieve a member by key from the dictionary * \param[in] key The element key