[{"id":23389,"web_url":"https://patchwork.libcamera.org/comment/23389/","msgid":"<20220613041143.GD2369877@pyrite.rasen.tech>","date":"2022-06-13T04:11:43","subject":"Re: [libcamera-devel] [RFC PATCH v2 02/14] libcamera: yaml_parser:\n\tExtend YamlObject::size() to dictionaries","submitter":{"id":97,"url":"https://patchwork.libcamera.org/api/people/97/","name":"Nicolas Dufresne via libcamera-devel","email":"libcamera-devel@lists.libcamera.org"},"content":"Hi Laurent,\n\nOn Sat, Jun 04, 2022 at 09:59:27PM +0300, Laurent Pinchart via libcamera-devel wrote:\n> Dictionaries have a size too, extend the size() function to support\n> them.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/yaml_parser.h |  3 +-\n>  src/libcamera/yaml_parser.cpp            | 42 +++++++++++++-----------\n>  test/yaml-parser.cpp                     |  5 +++\n>  3 files changed, 30 insertions(+), 20 deletions(-)\n> \n> diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\n> index e002fcf59278..b4f852b1ce54 100644\n> --- a/include/libcamera/internal/yaml_parser.h\n> +++ b/include/libcamera/internal/yaml_parser.h\n> @@ -39,6 +39,8 @@ public:\n>  \t\treturn type_ == Type::Dictionary;\n>  \t}\n>  \n> +\tstd::size_t size() const;\n> +\n>  #ifndef __DOXYGEN__\n>  \ttemplate<typename T,\n>  \t\t typename std::enable_if_t<\n> @@ -53,7 +55,6 @@ public:\n>  #endif\n>  \tT get(const T &defaultValue, bool *ok = nullptr) const;\n>  \n> -\tstd::size_t size() const;\n>  \tconst YamlObject &operator[](std::size_t index) const;\n>  \n>  \tbool contains(const std::string &key) const;\n> diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\n> index 4b5ea427bf45..5b872dbb0a2d 100644\n> --- a/src/libcamera/yaml_parser.cpp\n> +++ b/src/libcamera/yaml_parser.cpp\n> @@ -74,6 +74,29 @@ YamlObject::~YamlObject() = default;\n>   * \\return True if the YamlObject is a dictionary, false otherwise\n>   */\n>  \n> +/**\n> + * \\fn YamlObject::size()\n> + * \\brief Retrieve the number of elements in a dictionary or list YamlObject\n> + *\n> + * This function retrieves the size of the YamlObject, defined as the number of\n> + * child elements it contains. Only YamlObject instances of Dictionary or List\n> + * types have a size, calling this function on other types of instances is\n> + * invalid and results in undefined behaviour.\n> + *\n> + * \\return The size of the YamlObject\n> + */\n> +std::size_t YamlObject::size() const\n> +{\n> +\tswitch (type_) {\n> +\tcase Type::Dictionary:\n> +\t\treturn dictionary_.size();\n> +\tcase Type::List:\n> +\t\treturn list_.size();\n> +\tdefault:\n> +\t\treturn 0;\n> +\t}\n> +}\n> +\n>  /**\n>   * \\fn template<typename T> YamlObject::get<T>(\n>   *\tconst T &defaultValue, bool *ok) const\n> @@ -235,25 +258,6 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const\n>  \n>  #endif /* __DOXYGEN__ */\n>  \n> -/**\n> - * \\fn YamlObject::size()\n> - * \\brief Retrieve the number of elements in a list YamlObject\n> - *\n> - * This function retrieves the size of the YamlObject, defined as the number of\n> - * child elements it contains. Only YamlObject instances of List type have a\n> - * size, calling this function on other types of instances is invalid and\n> - * results in undefined behaviour.\n> - *\n> - * \\return The size of the YamlObject\n> - */\n> -std::size_t YamlObject::size() const\n> -{\n> -\tif (type_ != Type::List)\n> -\t\treturn 0;\n> -\n> -\treturn list_.size();\n> -}\n> -\n>  /**\n>   * \\fn YamlObject::operator[](std::size_t index) const\n>   * \\brief Retrieve the element from list YamlObject by index\n> diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp\n> index 5315d99fae5d..c5b4ddbb19e5 100644\n> --- a/test/yaml-parser.cpp\n> +++ b/test/yaml-parser.cpp\n> @@ -421,6 +421,11 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>  \n> +\t\tif (dictObj.size() != 3) {\n> +\t\t\tcerr << \"Dictionary object parse with wrong size\" << std::endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n>  \t\tauto memeberNames = dictObj.memberNames();\n>  \t\tsort(memeberNames.begin(), memeberNames.end());\n>  \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 B1B75BD161\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 13 Jun 2022 04:11:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 63A1265637;\n\tMon, 13 Jun 2022 06:11:52 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2A09165631\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Jun 2022 06:11:51 +0200 (CEST)","from pyrite.rasen.tech (softbank036240126034.bbtec.net\n\t[36.240.126.34])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B52D1440;\n\tMon, 13 Jun 2022 06:11:49 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655093512;\n\tbh=51TkIcGAGrMevg+b5tRtg9GZWziZM+fs2PgT0rb4CPI=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=U1fax5bUgW+BM+wFxPNJjfuDZdAJOX+uiFAIosUjAb2+sOe4ScYiugecEZgdEeTpD\n\tXI35UpL7w9dmbD8Fv+sAxn9lKJHpzw0qzUUoAdkX1rgCfzr0hwa82PZjP821t+gcmI\n\tBkYZHsBVbAQNSrdqrycIf0zN/syebSykmErRNSAZ1hww9f/KKGCg+hzyTFqmg3vq02\n\t9aRnddFphUg2E4JCYk/ukNOvfeWQ9Qx8jqHIUO41dGeLrl13EhIDUc+5lS7eDDzDxF\n\ti1B3J+CPop3hESP05G4ns5McOpri4Z+5MkTAm8A/G8/Ez1BbD3wTxitqXmUK1S9mf8\n\tVHe1Uk9XPMxQw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1655093511;\n\tbh=51TkIcGAGrMevg+b5tRtg9GZWziZM+fs2PgT0rb4CPI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=hgkLB2NBMXIRqYBEPbyCpktlGtq9twC+ABfZc/a7K651WqwExyRZA8v8uLqm3NdPJ\n\tcQSP7mz9r80mozUDC1U5ynv3MArHHBxByVcRsn0NTP1/2toOzphaHMdadBlJ1KFHU5\n\tra7xmMWRV6Q0EjqweetO/5sUVI70hh64s8dMrO80="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"hgkLB2NB\"; dkim-atps=neutral","Date":"Mon, 13 Jun 2022 13:11:43 +0900","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20220613041143.GD2369877@pyrite.rasen.tech>","References":"<20220604185939.29163-1-laurent.pinchart@ideasonboard.com>\n\t<20220604185939.29163-3-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20220604185939.29163-3-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [RFC PATCH v2 02/14] libcamera: yaml_parser:\n\tExtend YamlObject::size() to dictionaries","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>","From":"Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"paul.elder@ideasonboard.com","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]