From patchwork Tue May 24 22:58:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16028 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 60E71C3256 for ; Tue, 24 May 2022 22:58:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 49B1965673; Wed, 25 May 2022 00:58:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433110; bh=6snE1bRh0/Y/freE7UR3RHw585z+/5KDONypF6MBOh0=; 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=e9i8A1bQxgjIUeSuUj/CmMVhXnlhAe1jba7W0mn0R5PAYvQjDBSC42AWhOAsosjLq puIgYlh1iIiHbOqoy/8Tc9zDOrrZwPsmtUvHj3+1Vdn3v722z49cRVXqnefZVjUFdV S5C2TIh8FWlBXM0EsZEnPqIQYPxD1hKzW81FogcDWt3lCdY2wJWiI8qMTS9gO8Xs1V iIWdYqscWb7LWdHso21TplK0Mb4cEVWqEFW2sEXZ7tIqZ4xSYydQ9ackBlZNoc8HV/ WLXP05Ehy1nS6RuaEIwEQ+SmjSI2l+4SL9I+vg7iCx3X3pEVtEU7OYXbqY3ffxGvFi eZCguK/iHPYNg== 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 7919D60416 for ; Wed, 25 May 2022 00:58:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="b81PIlm6"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ED87CA5E; Wed, 25 May 2022 00:58:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433105; bh=6snE1bRh0/Y/freE7UR3RHw585z+/5KDONypF6MBOh0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b81PIlm6uxTR5CUNGqnCdhSxrLpWcnKrDZhY4WvoVDESwisKH0jeMUa59brEcjuJr yfL+yIHp0AY6FjQjqKqrTw2DQy/h2DH9MI5r3Da0Q3sNxBs6RMb3wc6SfX6WnrjwgL 8g5U8aBcazNN/7/1dDx5qx0x/n1uxHH6WhP+S4+M= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:06 +0300 Message-Id: <20220524225816.6830-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 02/12] 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 --- 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 652adf53d0cc..585b545b71c5 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());