[{"id":38640,"web_url":"https://patchwork.libcamera.org/comment/38640/","msgid":"<9459598e-83a0-4b3d-a980-2cda41c993f3@ideasonboard.com>","date":"2026-04-24T07:54:03","subject":"Re: [PATCH v3 20/37] libcamera: value_node: Add functions to erase\n\tchild nodes","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2026. 04. 24. 1:00 keltezéssel, Laurent Pinchart írta:\n> There will be a need to erase child nodes when implementing support for\n> overriding configuration options. Add two erase() functions to the\n> ValueNode class, mimicking the add() API.\n> \n> More erase() overloads could be added, for instance taking iterators as\n> parameters, to improve efficiency. This should be considered later, when\n> usage of the ValueNode class will expand, based on the actual usage\n> patterns.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n> ---\n> Changes since v2:\n> \n> - Use std::string_view() for first overload\n> - Add todo comment\n> ---\n\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\n\n>   include/libcamera/internal/value_node.h |  3 ++\n>   src/libcamera/value_node.cpp            | 54 +++++++++++++++++++++++++\n>   2 files changed, 57 insertions(+)\n> \n> diff --git a/include/libcamera/internal/value_node.h b/include/libcamera/internal/value_node.h\n> index ccae69e25a82..cab14943c03f 100644\n> --- a/include/libcamera/internal/value_node.h\n> +++ b/include/libcamera/internal/value_node.h\n> @@ -244,6 +244,9 @@ public:\n>   \tValueNode *add(std::initializer_list<std::string_view> path,\n>   \t\t       std::unique_ptr<ValueNode> &&child);\n> \n> +\tvoid erase(std::string_view key);\n> +\tvoid erase(std::initializer_list<std::string_view> path);\n> +\n>   private:\n>   \tLIBCAMERA_DISABLE_COPY_AND_MOVE(ValueNode)\n> \n> diff --git a/src/libcamera/value_node.cpp b/src/libcamera/value_node.cpp\n> index 6ab11009fccc..2c875db366e7 100644\n> --- a/src/libcamera/value_node.cpp\n> +++ b/src/libcamera/value_node.cpp\n> @@ -620,4 +620,58 @@ ValueNode *ValueNode::add(std::initializer_list<std::string_view> path,\n>   \treturn node;\n>   }\n> \n> +/**\n> + * \\brief Erase a child node in a dictionary\n> + * \\param[in] key The dictionary key\n> + *\n> + * Erase the child node referenced by \\a key in a dictionary node. If the \\a\n> + * key does not exist, or if this node is not a dictionary, the function\n> + * returns without performing any operation.\n> + */\n> +void ValueNode::erase(std::string_view key)\n> +{\n> +\tauto node = dictionary_.find(key);\n> +\tif (node == dictionary_.end())\n> +\t\treturn;\n> +\n> +\t/* \\todo Not an ideal algorithm */\n> +\tfor (auto iter = list_.begin(); iter != list_.end(); ++iter) {\n> +\t\tif (iter->value.get() != node->second)\n> +\t\t\tcontinue;\n> +\n> +\t\tlist_.erase(iter);\n> +\t\tbreak;\n> +\t}\n> +\n> +\tdictionary_.erase(node);\n> +}\n> +\n> +/**\n> + * \\brief Erase the child node at the given path\n> + * \\param[in] path The path\n> + *\n> + * Erase the child node at the given \\a path. If no child node exists for the\n> + * path, the function returns without performing any operation.\n> + */\n> +void ValueNode::erase(std::initializer_list<std::string_view> path)\n> +{\n> +\tif (!path.size())\n> +\t\treturn;\n> +\n> +\tValueNode *node = this;\n> +\n> +\tfor (const auto [i, name] : utils::enumerate(path)) {\n> +\t\tif (i == path.size() - 1) {\n> +\t\t\tnode->erase(name);\n> +\t\t\treturn;\n> +\t\t}\n> +\n> +\t\tauto iter = node->dictionary_.find(name);\n> +\t\tif (iter == node->dictionary_.end())\n> +\t\t\treturn;\n> +\n> +\t\tnode = iter->second;\n> +\t}\n> +}\n> +\n>   } /* namespace libcamera */\n> --\n> Regards,\n> \n> Laurent Pinchart\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 38A2FBDCB5\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Apr 2026 07:54:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E052162F62;\n\tFri, 24 Apr 2026 09:54:07 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2E0E862F62\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Apr 2026 09:54:06 +0200 (CEST)","from [192.168.33.62] (185.221.140.120.nat.pool.zt.hu\n\t[185.221.140.120])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7BC07802;\n\tFri, 24 Apr 2026 09:52:26 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"wQVTO3jt\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1777017146;\n\tbh=1beMTFqaHSOn91QKHVp06cq8ryWy/GLQVBrNkyBzbYU=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=wQVTO3jt6+ar4AkpZDKdt1svSFi9Vxa9Ql0WdXKib/JAe09Q7ba7nhx4DEaHsSRyG\n\tNd1ZUH7R5XaGQ4wRuTIhmpI4SfnDod5BRBFSdfF1I0lSANIHGDwMkr/x+gJ9/cyu+v\n\te0hLrX1MKrtukX9UzALWGZXC52Lp00uC2DvX6BpY=","Message-ID":"<9459598e-83a0-4b3d-a980-2cda41c993f3@ideasonboard.com>","Date":"Fri, 24 Apr 2026 09:54:03 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 20/37] libcamera: value_node: Add functions to erase\n\tchild nodes","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20260423230059.3180987-1-laurent.pinchart@ideasonboard.com>\n\t<9u3tNiUcXvM6TK63TnciZA4-q-s5fIdwqr-xeyFVlCUWGNLQrihn1gaWuEXBCx3kNyqYFp1cUp58BkWMOK2szA==@protonmail.internalid>\n\t<20260423230059.3180987-21-laurent.pinchart@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20260423230059.3180987-21-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]