{"id":16851,"url":"https://patchwork.libcamera.org/api/patches/16851/?format=json","web_url":"https://patchwork.libcamera.org/patch/16851/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220727222149.30627-4-laurent.pinchart@ideasonboard.com>","date":"2022-07-27T22:21:43","name":"[libcamera-devel,v5,3/9] libcamera: yaml_parser: Add getList() function","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"06b7b764810e876cb0bc992ea2b39c0df691384a","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16851/mbox/","series":[{"id":3338,"url":"https://patchwork.libcamera.org/api/series/3338/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3338","date":"2022-07-27T22:21:40","name":"ipa: rkisp1: Add GSL, LSC, DPCC, Filter and CProc algorithms","version":5,"mbox":"https://patchwork.libcamera.org/series/3338/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16851/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16851/checks/","tags":{},"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 F35DBBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 27 Jul 2022 22:21:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B9D7E6331E;\n\tThu, 28 Jul 2022 00:21:58 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D920963310\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Jul 2022 00:21:55 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6DB23835;\n\tThu, 28 Jul 2022 00:21:55 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658960518;\n\tbh=Ey/FSnyl3Sgk/a2SI/x0+AuB8Vd2N7heHyg8oOf6nP4=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=ZTQLjcW+An9kVFkAF7nHvIotN0q7D15kEFLUw4I9B6Fviet1bIGvn7bm+L3jsUDcY\n\t6sne1sPs/b3020kl20Twxf2E2F2yzd0yFyx74vnynkk2lgQOo++0jlpaRkQmhVhbB8\n\tS1AD1opFnR+hllOvkXT6CkULOM0GVbYDd1XnSSAw0TXg0O4s7s/qvvvN/hPmgLW5n/\n\tEdQa9ehHLqTXGJrrQ1W0GtoR3LGULZ6rzgX9gFQbV4VdAYCQvT41AwBT1vMltuxQoT\n\tVddbbLw5ob1AFDpQqp6P3TrGa2EgjpqVp8q13qCuNiaxnm1vqttA2bRKT8RgwqS65x\n\tSUi1gxmLQcpJQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1658960515;\n\tbh=Ey/FSnyl3Sgk/a2SI/x0+AuB8Vd2N7heHyg8oOf6nP4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ATjAD03bmCu2HQ3XN8v6lvYZ9Xp/E2iR89mhOTnkOlA8PMaqpwmVy4yuarmiPB68C\n\tBJ6Jg4OXv67iKxG/34c2oIEV9fiKuLb19mFHPKFv2DZR4FjbOea9Lt9j3ViMGSeQOt\n\tgYxDO6pc15qd0AH4vhN85eMFbaJ0MH5aQ9T1A5fU="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"ATjAD03b\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 28 Jul 2022 01:21:43 +0300","Message-Id":"<20220727222149.30627-4-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.35.1","In-Reply-To":"<20220727222149.30627-1-laurent.pinchart@ideasonboard.com>","References":"<20220727222149.30627-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 3/9] libcamera: yaml_parser: Add\n\tgetList() function","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":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Florian Sylvestre <fsylvestre@baylibre.com>\n\nAllow to retrieve a YAML list of any already supported types in a\nstd::vector.\n\nSigned-off-by: Florian Sylvestre <fsylvestre@baylibre.com>\nTested-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/internal/yaml_parser.h | 16 +++++++\n src/libcamera/yaml_parser.cpp            | 53 ++++++++++++++++++++++++\n test/yaml-parser.cpp                     |  6 +++\n 3 files changed, 75 insertions(+)","diff":"diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\nindex 61f2223223a7..4b3da0f03512 100644\n--- a/include/libcamera/internal/yaml_parser.h\n+++ b/include/libcamera/internal/yaml_parser.h\n@@ -174,6 +174,22 @@ public:\n \t\treturn get<T>().value_or(defaultValue);\n \t}\n \n+#ifndef __DOXYGEN__\n+\ttemplate<typename T,\n+\t\t typename std::enable_if_t<\n+\t\t\t std::is_same_v<bool, T> ||\n+\t\t\t std::is_same_v<double, T> ||\n+\t\t\t std::is_same_v<int16_t, T> ||\n+\t\t\t std::is_same_v<uint16_t, T> ||\n+\t\t\t std::is_same_v<int32_t, T> ||\n+\t\t\t std::is_same_v<uint32_t, T> ||\n+\t\t\t std::is_same_v<std::string, T> ||\n+\t\t\t std::is_same_v<Size, T>> * = nullptr>\n+#else\n+\ttemplate<typename T>\n+#endif\n+\tstd::optional<std::vector<T>> getList() const;\n+\n \tDictAdapter asDict() const { return DictAdapter{ dictionary_ }; }\n \tListAdapter asList() const { return ListAdapter{ list_ }; }\n \ndiff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\nindex 4299f5abd38a..cb4f1eb29a77 100644\n--- a/src/libcamera/yaml_parser.cpp\n+++ b/src/libcamera/yaml_parser.cpp\n@@ -293,6 +293,59 @@ std::optional<Size> YamlObject::get() const\n \n #endif /* __DOXYGEN__ */\n \n+/**\n+ * \\fn template<typename T> YamlObject::getList<T>() const\n+ * \\brief Parse the YamlObject as a list of \\a T\n+ *\n+ * This function parses the value of the YamlObject as a list of \\a T objects,\n+ * and returns the value as a \\a std::vector<T>. If parsing fails, std::nullopt\n+ * is returned.\n+ *\n+ * \\return The YamlObject value as a std::vector<T>, or std::nullopt if parsing\n+ * failed\n+ */\n+\n+#ifndef __DOXYGEN__\n+\n+template<typename T,\n+\t typename std::enable_if_t<\n+\t\t std::is_same_v<bool, T> ||\n+\t\t std::is_same_v<double, T> ||\n+\t\t std::is_same_v<int16_t, T> ||\n+\t\t std::is_same_v<uint16_t, T> ||\n+\t\t std::is_same_v<int32_t, T> ||\n+\t\t std::is_same_v<uint32_t, T> ||\n+\t\t std::is_same_v<std::string, T> ||\n+\t\t std::is_same_v<Size, T>> *>\n+std::optional<std::vector<T>> YamlObject::getList() const\n+{\n+\tif (type_ != Type::List)\n+\t\treturn {};\n+\n+\tstd::vector<T> values;\n+\tvalues.reserve(list_.size());\n+\n+\tfor (const YamlObject &entry : asList()) {\n+\t\tconst auto value = entry.get<T>();\n+\t\tif (!value)\n+\t\t\treturn {};\n+\t\tvalues.emplace_back(*value);\n+\t}\n+\n+\treturn values;\n+}\n+\n+template std::optional<std::vector<bool>> YamlObject::getList<bool>() const;\n+template std::optional<std::vector<double>> YamlObject::getList<double>() const;\n+template std::optional<std::vector<int16_t>> YamlObject::getList<int16_t>() const;\n+template std::optional<std::vector<uint16_t>> YamlObject::getList<uint16_t>() const;\n+template std::optional<std::vector<int32_t>> YamlObject::getList<int32_t>() const;\n+template std::optional<std::vector<uint32_t>> YamlObject::getList<uint32_t>() const;\n+template std::optional<std::vector<std::string>> YamlObject::getList<std::string>() const;\n+template std::optional<std::vector<Size>> YamlObject::getList<Size>() const;\n+\n+#endif /* __DOXYGEN__ */\n+\n /**\n  * \\fn YamlObject::asDict() const\n  * \\brief Wrap a dictionary YamlObject in an adapter that exposes iterators\ndiff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp\nindex ebb654f2ef9c..bb54e0d7f76a 100644\n--- a/test/yaml-parser.cpp\n+++ b/test/yaml-parser.cpp\n@@ -523,6 +523,12 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\tconst auto &values = firstElement.getList<uint16_t>();\n+\t\tif (!values || values->size() != 2 || (*values)[0] != 1 || (*values)[1] != 2) {\n+\t\t\tcerr << \"getList() failed to return correct vector\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\tauto &secondElement = level2Obj[1];\n \t\tif (!secondElement.isDictionary() ||\n \t\t    !secondElement.contains(\"one\") ||\n","prefixes":["libcamera-devel","v5","3/9"]}