[{"id":38638,"web_url":"https://patchwork.libcamera.org/comment/38638/","msgid":"<ee640bf5-fe16-4dd5-aeba-6f0d44fd5bd7@protonmail.com>","date":"2026-04-24T07:52:41","subject":"Re: [PATCH v3 07/37] libcamera: yaml_parser: Add functions to add\n\tchildren","submitter":{"id":133,"url":"https://patchwork.libcamera.org/api/people/133/","name":"Pőcze Barnabás","email":"pobrn@protonmail.com"},"content":"2026. 04. 24. 1:00 keltezéssel, Laurent Pinchart írta:\n> Add YamlObject::add() functions to add children to a list or dictionary\n> object. This will be used by the YamlParserContext to replace direct\n> access to YamlObject member variables to decouple the two classes.\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> - Fix typo in documentation\n> \n> Changes since v1:\n> \n> - Avoid std::map lookup before insertion in YamlObject::add()\n> - Don't move child node if add fails\n> ---\n\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\n\n>   include/libcamera/internal/yaml_parser.h |  5 ++-\n>   src/libcamera/yaml_parser.cpp            | 55 ++++++++++++++++++++++++\n>   2 files changed, 59 insertions(+), 1 deletion(-)\n> \n> diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\n> index 0666762308ac..3be61c503c88 100644\n> --- a/include/libcamera/internal/yaml_parser.h\n> +++ b/include/libcamera/internal/yaml_parser.h\n> @@ -28,7 +28,7 @@ class YamlObject\n>   {\n>   private:\n>   \tstruct Value {\n> -\t\tValue(std::string &&k, std::unique_ptr<YamlObject> &&v)\n> +\t\tValue(std::string k, std::unique_ptr<YamlObject> &&v)\n>   \t\t\t: key(std::move(k)), value(std::move(v))\n>   \t\t{\n>   \t\t}\n> @@ -197,6 +197,9 @@ public:\n>   \tbool contains(std::string_view key) const;\n>   \tconst YamlObject &operator[](std::string_view key) const;\n> \n> +\tYamlObject *add(std::unique_ptr<YamlObject> &&child);\n> +\tYamlObject *add(std::string key, std::unique_ptr<YamlObject> &&child);\n> +\n>   private:\n>   \tLIBCAMERA_DISABLE_COPY_AND_MOVE(YamlObject)\n> \n> diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\n> index 8c84f560ff0f..5b2e743ee41a 100644\n> --- a/src/libcamera/yaml_parser.cpp\n> +++ b/src/libcamera/yaml_parser.cpp\n> @@ -436,6 +436,61 @@ const YamlObject &YamlObject::operator[](std::string_view key) const\n>   \treturn *iter->second;\n>   }\n> \n> +/**\n> + * \\brief Add a child object to a list\n> + * \\param[in] child The child object\n> + *\n> + * Append the \\a child object as the last element of this object's children\n> + * list. This object must be empty, in which case it is converted to the\n> + * Type::List type, or be a list. Otherwise, the function returns a nullptr and\n> + * the \\a child is not modified.\n> + *\n> + * \\return A pointer to the child object if successfully added, nullptr\n> + * otherwise\n> + */\n> +YamlObject *YamlObject::add(std::unique_ptr<YamlObject> &&child)\n> +{\n> +\tif (type_ == Type::Empty)\n> +\t\ttype_ = Type::List;\n> +\n> +\tif (type_ != Type::List)\n> +\t\treturn nullptr;\n> +\n> +\tValue &elem = list_.emplace_back(std::string{}, std::move(child));\n> +\treturn elem.value.get();\n> +}\n> +\n> +/**\n> + * \\brief Add a child object to a dictionary\n> + * \\param[in] key The dictionary key\n> + * \\param[in] child The child object\n> + *\n> + * Add the \\a child object with the given \\a key to this object's children. This\n> + * object must be empty, in which case it is converted to the Type::Dictionary\n> + * type, or be a dictionary. Otherwise, the function returns a nullptr and the\n> + * \\a child is not modified.\n> + *\n> + * Keys are unique. If a child with the same \\a key already exists, the function\n> + * returns a nullptr and the \\a child is not modified.\n> + *\n> + * \\return A pointer to the child object if successfully added, nullptr\n> + * otherwise\n> + */\n> +YamlObject *YamlObject::add(std::string key, std::unique_ptr<YamlObject> &&child)\n> +{\n> +\tif (type_ == Type::Empty)\n> +\t\ttype_ = Type::Dictionary;\n> +\n> +\tif (type_ != Type::Dictionary)\n> +\t\treturn nullptr;\n> +\n> +\tauto [it, inserted] = dictionary_.try_emplace(std::move(key), child.get());\n> +\tif (!inserted)\n> +\t\treturn nullptr;\n> +\n> +\treturn list_.emplace_back(it->first, std::move(child)).value.get();\n> +}\n> +\n>   #ifndef __DOXYGEN__\n> \n>   class YamlParserContext\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 798DCBDCB5\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Apr 2026 07:52:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 89FB862F62;\n\tFri, 24 Apr 2026 09:52:48 +0200 (CEST)","from mail-106121.protonmail.ch (mail-106121.protonmail.ch\n\t[79.135.106.121])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7FDA362CE6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Apr 2026 09:52:47 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"TJwDC1fW\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1777017165; x=1777276365;\n\tbh=lI3rQEAwcJAEMIhxVACuoaTdqtaRPa6tYOQx5iUtVig=;\n\th=Date:To:From:Subject:Message-ID:In-Reply-To:References:\n\tFeedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:\n\tMessage-ID:BIMI-Selector;\n\tb=TJwDC1fWd3TuPjTWAdmzUyI11/lDe55zy2zS0c4xA25DWtoA8xm22+clKTXIGxEQL\n\tDRj9JuJ2HljhZJVRZqCRLk2oIipeyUEsorex5q/1epsUlVE9ueiaGgNXyqT9auJxAS\n\tyyFoADOtLduz5mcO4gi8uvsnk4JdUGUwQfAtnKg543NmN085QqoAZ3S5f5YQB39akX\n\tT6wXHPBJqkU0sT2FUQsxrCyS8Bb4J9atvkKH8OUR/Q0IZKwytP4/J+n8uAaXcKalmp\n\tQ0jFsY8Ibfm0SL8r8Fx9Msc8TxYDiFgs/906r0LItdIZ2omZlTZpbxv3qFNEC/AF+Y\n\tx/MtZMV/UKJFw==","Date":"Fri, 24 Apr 2026 07:52:41 +0000","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","From":"=?utf-8?q?P=C5=91cze_Barnab=C3=A1s?= <pobrn@protonmail.com>","Subject":"Re: [PATCH v3 07/37] libcamera: yaml_parser: Add functions to add\n\tchildren","Message-ID":"<ee640bf5-fe16-4dd5-aeba-6f0d44fd5bd7@protonmail.com>","In-Reply-To":"<20260423230059.3180987-8-laurent.pinchart@ideasonboard.com>","References":"<20260423230059.3180987-1-laurent.pinchart@ideasonboard.com>\n\t<20260423230059.3180987-8-laurent.pinchart@ideasonboard.com>","Feedback-ID":"20568564:user:proton","X-Pm-Message-ID":"ea8ac0b158285f2bc879ddd38f9eeee31fd0f66a","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","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>"}}]