From patchwork Tue Jan 13 00:07:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 25732 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 4BB5DC3284 for ; Tue, 13 Jan 2026 00:08:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F293861FE2; Tue, 13 Jan 2026 01:08:50 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="dx6EVZrF"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1397861FA0 for ; Tue, 13 Jan 2026 01:08:48 +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 6B9C8F06 for ; Tue, 13 Jan 2026 01:08:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1768262902; bh=g9l2EBZ7FVe+T4rOJU5XoOl6FlcCCHc/MA8OBHMJAew=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dx6EVZrFtia/1BXrH40FrztA39J9tC8rGCg0QeeX13TyG2m20lYJLkz/nrjkOnkoL ygyV9orhhHunwEQ0kz3KtRA/suMB2i/ofQJJWlueb/QYoCdRYfssK059SRZigk5AgG o2B7itilHvzOiZoASQW9XQ4A5w9O6PXD1Xhq/YhI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 12/36] libcamera: yaml_parser: Add function to set a YamlObject value Date: Tue, 13 Jan 2026 02:07:44 +0200 Message-ID: <20260113000808.15395-13-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" Add a YamlObject::set() function to set the value of an object, with specializations for scalar types. Signed-off-by: Laurent Pinchart --- include/libcamera/internal/yaml_parser.h | 7 +++ src/libcamera/yaml_parser.cpp | 59 ++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 7953befe11e2..c98fe003c877 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -182,6 +182,12 @@ public: return get().value_or(std::forward(defaultValue)); } + template + void set(T &&value) + { + return Accessor>{}.set(*this, std::forward(value)); + } + DictAdapter asDict() const { return DictAdapter{ list_ }; } ListAdapter asList() const { return ListAdapter{ list_ }; } @@ -207,6 +213,7 @@ private: template struct Accessor { std::optional get(const YamlObject &obj) const; + void set(YamlObject &obj, T value); }; Type type_; diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 2b3723287051..9b61d3e8fc50 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -137,6 +137,20 @@ std::size_t YamlObject::size() const * \return The YamlObject value, or \a defaultValue if parsing failed */ +/** + * \fn template YamlObject::set(T &&value) + * \brief Set the value of a YamlObject + * \param[in] value The value + * + * This function sets the value stored in a YamlObject to \a value. The value is + * converted to a string in an implementation-specific way that guarantees that + * subsequent calls to get() will return the same value. + * + * Values can only be set on YamlObject of Type::Value type or empty YamlObject. + * Attempting to set a value on an object of type Type::Dict or Type::List does + * not modify the YamlObject. + */ + #ifndef __DOXYGEN__ template<> @@ -154,6 +168,16 @@ YamlObject::Accessor::get(const YamlObject &obj) const return std::nullopt; } +template<> +void YamlObject::Accessor::set(YamlObject &obj, bool value) +{ + if (obj.type_ != Type::Empty && obj.type_ != Type::Value) + return; + + obj.type_ = Type::Value; + obj.value_ = value ? "true" : "false"; +} + template struct YamlObject::Accessor || @@ -178,6 +202,15 @@ struct YamlObject::Accessor; @@ -194,6 +227,12 @@ YamlObject::Accessor::get(const YamlObject &obj) const return obj.get(); } +template<> +void YamlObject::Accessor::set(YamlObject &obj, float value) +{ + obj.set(std::forward(value)); +} + template<> std::optional YamlObject::Accessor::get(const YamlObject &obj) const @@ -215,6 +254,16 @@ YamlObject::Accessor::get(const YamlObject &obj) const return value; } +template<> +void YamlObject::Accessor::set(YamlObject &obj, double value) +{ + if (obj.type_ != Type::Empty && obj.type_ != Type::Value) + return; + + obj.type_ = Type::Value; + obj.value_ = std::to_string(value); +} + template<> std::optional YamlObject::Accessor::get(const YamlObject &obj) const @@ -225,6 +274,16 @@ YamlObject::Accessor::get(const YamlObject &obj) const return obj.value_; } +template<> +void YamlObject::Accessor::set(YamlObject &obj, std::string value) +{ + if (obj.type_ != Type::Empty && obj.type_ != Type::Value) + return; + + obj.type_ = Type::Value; + obj.value_ = std::move(value); +} + template<> std::optional YamlObject::Accessor::get(const YamlObject &obj) const