From patchwork Sat Jun 4 18:59:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16157 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 61F8BC3273 for ; Sat, 4 Jun 2022 19:00:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 366A865639; Sat, 4 Jun 2022 21:00:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1654369201; bh=nhjLA//4m1HvlSUtXkPDjGURRb36QN5w86OMCpUkbyc=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Uoo1IiCsDxI2iFbQkz82wu18OvOy/l4dMyAFsIhmBbEOdtsWQzEqm3msiMy/xCvEr lScRHbVJ5VHZmqut1bQ0LltO19fUNz+06ao1hcw4WduzUsOEOwDu1GAnJG7YDtHwm3 BjtYSZ1gQm1mdMhqPRi7CX/rTxCN8mDsL0DqgwT8twomdeEGVJbBqNNIvA1PCEgMGT 0msUKlNSNp8811F09jl5ZdIKEid0XogH5uYzchvrSc3j7J2innVE/gLPDEZmDolmvy R/haNubhkgumGSKCsF5gyTYxU75Ea7Cu1AuWQyAwAJCQ6nJYXvFa+uwMIp4vuK/Fp6 g9Sli870EIlqA== 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 0722765632 for ; Sat, 4 Jun 2022 21:00:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XExsG9DY"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (85-76-79-203-nat.elisa-mobile.fi [85.76.79.203]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C43EB6D4; Sat, 4 Jun 2022 20:59:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1654369199; bh=nhjLA//4m1HvlSUtXkPDjGURRb36QN5w86OMCpUkbyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XExsG9DYSDtI7Vz6AQMeLM6YAjfU1iw/G50KmjNdeOioNNrI/wQrvRRAXrNWq4OD9 GqPWJ3cDeOqO9by31BnVB8tCtN2sKYiPRQWX6KlhH+6jiO/Ti2SYUqcefoUfY2xlly Txo8jIvw6wDXAq6oI8jOHynB0rIRDH8bXf1RIgV0= To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Jun 2022 21:59:27 +0300 Message-Id: <20220604185939.29163-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220604185939.29163-1-laurent.pinchart@ideasonboard.com> References: <20220604185939.29163-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 02/14] libcamera: yaml_parser: Extend YamlObject::size() to dictionaries 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Dictionaries have a size too, extend the size() function to support them. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- include/libcamera/internal/yaml_parser.h | 3 +- src/libcamera/yaml_parser.cpp | 42 +++++++++++++----------- test/yaml-parser.cpp | 5 +++ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index e002fcf59278..b4f852b1ce54 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -39,6 +39,8 @@ public: return type_ == Type::Dictionary; } + std::size_t size() const; + #ifndef __DOXYGEN__ template YamlObject::get( * const T &defaultValue, bool *ok) const @@ -235,25 +258,6 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const #endif /* __DOXYGEN__ */ -/** - * \fn YamlObject::size() - * \brief Retrieve the number of elements in a list YamlObject - * - * This function retrieves the size of the YamlObject, defined as the number of - * child elements it contains. Only YamlObject instances of List type have a - * size, calling this function on other types of instances is invalid and - * results in undefined behaviour. - * - * \return The size of the YamlObject - */ -std::size_t YamlObject::size() const -{ - if (type_ != Type::List) - return 0; - - return list_.size(); -} - /** * \fn YamlObject::operator[](std::size_t index) const * \brief Retrieve the element from list YamlObject by index diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 5315d99fae5d..c5b4ddbb19e5 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -421,6 +421,11 @@ protected: return TestFail; } + if (dictObj.size() != 3) { + cerr << "Dictionary object parse with wrong size" << std::endl; + return TestFail; + } + auto memeberNames = dictObj.memberNames(); sort(memeberNames.begin(), memeberNames.end());