From patchwork Thu Jun 13 01:39:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20275 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 8A2DBC3293 for ; Thu, 13 Jun 2024 01:40:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 112F965493; Thu, 13 Jun 2024 03:40:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="sxLc39Lo"; 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 E6DB06548C for ; Thu, 13 Jun 2024 03:40:08 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2DBD7E39; Thu, 13 Jun 2024 03:39:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718242795; bh=vEHaev4LalzGsWPM+nfMRN0TeBcAy0Ra1ZUNuwKQxo4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sxLc39LoSC5da49TATx8c+iU3+cdfv5ONSAeoyzeI5BDBL3l222QlxSrFyHTE2uMk ZhUSyMOlWVVA5irChhI2gCywZ5RHIm1/PjdmE9iKkpdba4gMCWr4l0Nvvu494cHwKB bmA0sczb/Wvro8lg/SbpqBBKh7Q5uvYlTPJG4Dm4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , David Plowman , Naushir Patuck Subject: [PATCH 03/11] ipa: libipa: vector: Specialize YamlObject getter Date: Thu, 13 Jun 2024 04:39:36 +0300 Message-ID: <20240613013944.23344-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> References: <20240613013944.23344-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" Implement a specialization of the YamlObject::Getter structure to support deserializing ipa::Vector objects from YAML data. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- src/ipa/libipa/vector.cpp | 17 +++++++++++++++++ src/ipa/libipa/vector.h | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp index 5de4ae48b419..4e987d82fa70 100644 --- a/src/ipa/libipa/vector.cpp +++ b/src/ipa/libipa/vector.cpp @@ -148,6 +148,23 @@ namespace ipa { * \return True if the two vectors are not equal, false otherwise */ +#ifndef __DOXYGEN__ +bool vectorValidateYaml(const YamlObject &obj, unsigned int size) +{ + if (!obj.isList()) + return false; + + if (obj.size() != size) { + LOG(Vector, Error) + << "Wrong number of values in YAML vector: expected " + << size << ", got " << obj.size(); + return false; + } + + return true; +} +#endif /* __DOXYGEN__ */ + } /* namespace ipa */ } /* namespace libcamera */ diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h index 7c444363d4bb..4b2fe581ecc2 100644 --- a/src/ipa/libipa/vector.h +++ b/src/ipa/libipa/vector.h @@ -180,6 +180,10 @@ bool operator!=(const Vector &lhs, const Vector &rhs) return !(lhs == rhs); } +#ifndef __DOXYGEN__ +bool vectorValidateYaml(const YamlObject &obj, unsigned int size); +#endif /* __DOXYGEN__ */ + } /* namespace ipa */ #ifndef __DOXYGEN__ @@ -195,6 +199,27 @@ std::ostream &operator<<(std::ostream &out, const ipa::Vector &v) return out; } + +template +struct YamlObject::Getter> { + std::optional> get(const YamlObject &obj) const + { + if (!ipa::vectorValidateYaml(obj, Rows)) + return std::nullopt; + + ipa::Vector vector; + + unsigned int i = 0; + for (const YamlObject &entry : obj.asList()) { + const auto value = entry.get(); + if (!value) + return std::nullopt; + vector[i++] = *value; + } + + return vector; + } +}; #endif /* __DOXYGEN__ */ } /* namespace libcamera */