{"id":16325,"url":"https://patchwork.libcamera.org/api/patches/16325/?format=json","web_url":"https://patchwork.libcamera.org/patch/16325/","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":"<20220622151918.451635-2-fsylvestre@baylibre.com>","date":"2022-06-22T15:19:14","name":"[libcamera-devel,1/5] libcamera: yaml_parser: Add getList() function","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"d03ab8a6626449e78fb9dc8392ad37e39bde26af","submitter":{"id":123,"url":"https://patchwork.libcamera.org/api/people/123/?format=json","name":"Florian Sylvestre","email":"fsylvestre@baylibre.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16325/mbox/","series":[{"id":3208,"url":"https://patchwork.libcamera.org/api/series/3208/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3208","date":"2022-06-22T15:19:13","name":"Add GSL, LSC and DPCC tuning support for rkisp1","version":1,"mbox":"https://patchwork.libcamera.org/series/3208/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16325/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16325/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 CA33CBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 22 Jun 2022 15:19:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3F93E6563A;\n\tWed, 22 Jun 2022 17:19:25 +0200 (CEST)","from mail-wr1-x436.google.com (mail-wr1-x436.google.com\n\t[IPv6:2a00:1450:4864:20::436])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B44A1633A7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Jun 2022 17:19:22 +0200 (CEST)","by mail-wr1-x436.google.com with SMTP id r20so3470784wra.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Jun 2022 08:19:22 -0700 (PDT)","from BL087.. ([2a01:e34:eea9:e630:4175:47f:ec:c265])\n\tby smtp.gmail.com with ESMTPSA id\n\tbi11-20020a05600c3d8b00b0039c362311d2sm1745388wmb.9.2022.06.22.08.19.21\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 22 Jun 2022 08:19:21 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655911165;\n\tbh=3Ii/EC6Crwfa61DMI8UWdPMO7Asz9MwoR1YFNELjJbE=;\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=iL4xoZW9Em7FykxKjkXOYIcZbOjMGMYxkaL2Zlq3eFkx7fzYWplYX6Vra6NwSlUIi\n\t+/m7y/9hC9Sgc0T6gUbTdHitB3+ajxerPKDThbhTHnyxuR43MR16qYjgavWXZ4gmyV\n\tKcfBWQcznOTHnUJAeTck6/SdbnDkqTG5rEovv7i+g3F+/PDlDinpNYvlSr8bMqDBaX\n\tYRcuunx0bWdk2rGkT+k/WIuDoQewvWL3KHIcNLJyUJv2pBgvKohyTXURBX6c8FtkaH\n\tQjIXGBvP1FLIPnefk1oIrGBlOp1hj8TNtu4nN1kMAblvuY0H1EtNKnfffBkJ7q9B7E\n\t4POcKH09jo4sw==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=baylibre-com.20210112.gappssmtp.com; s=20210112;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=AE6oXn0AJ2vVpFGOXOrAOauwGaTg8VttfgGqOkuBWk0=;\n\tb=Hhv3ocGq9n0oyTO4+rPGUTHYOx4gmwuNdDvH/qyewObwvkbZwnb17dTJmaRDdPqH2S\n\tjSuLaWOo8mvXc6eXqw129YzpaNjVIEO8odf/WGL31m+PaYtlllNpu8WUR7mP8sSUdDs4\n\twFcrbWcLDysTZa+ps5+FjF83sUNN6R+Tc2EqG3xxoB7OhW1by96PAEgrc0X4Or1Soc/z\n\twXXYXsQLAqXk1Q3TO2RINKoyr3HCy23FpkSn7wLS862a2gGLEk+1MLw0utLTxRayjDaT\n\tNPiiXDsSnRe3TYMZvAbI158DXLA49ByRFwI84J04env7bHS/hW3UXDaepnGOnP/2DTAw\n\tBDWg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=baylibre-com.20210112.gappssmtp.com\n\theader.i=@baylibre-com.20210112.gappssmtp.com header.b=\"Hhv3ocGq\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=AE6oXn0AJ2vVpFGOXOrAOauwGaTg8VttfgGqOkuBWk0=;\n\tb=TLf8JNc116PQOjB/suXoLRFqaK2QTotg3yHA+LKyY2azQyas35TR4sOrUKJXVYjZtI\n\t4zx+A30jkgGo7VgE8m/HlLZwbDCMNLYwt3h+3yGYEr5/1k9seoeCilQznznLUVg3SNVy\n\t0xuKxPu+N5mB8S89kcqxCy2C0dQe/6mPt0K82rzt14F9n4oFn3S8wQCLiEIJNoS8zL5h\n\t97Bus74cDNbM1bZfEOznc07r6CCItN3xfAtCWOkB5rW1thL90ArHGr0GDRMRyumh5cRm\n\tZW8WLdQIIb0+abywolx7XOdrrIVY47vWQ3FWoDWdN6LED5K+ATh1DKeniZdHqHXtjCEi\n\tRSag==","X-Gm-Message-State":"AJIora9+DjZV/aRpsXK3ikHfmePKqQWJZMt1boZseZ2kFkOdOC7h8m3G\n\tUiulkcxS+seWNxMQ+vfyCCH9wUregIV0Eg==","X-Google-Smtp-Source":"AGRyM1uS4AuXwkFv4w5ZfFomqTNfiuNtrOmTmiDGY2rZfNk67TWfg3eznO/7iQq3u4mQNGZ/cXPF7w==","X-Received":"by 2002:a05:6000:22a:b0:21b:9bc4:b166 with SMTP id\n\tl10-20020a056000022a00b0021b9bc4b166mr3897295wrz.287.1655911162113; \n\tWed, 22 Jun 2022 08:19:22 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 22 Jun 2022 17:19:14 +0200","Message-Id":"<20220622151918.451635-2-fsylvestre@baylibre.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20220622151918.451635-1-fsylvestre@baylibre.com>","References":"<20220622151918.451635-1-fsylvestre@baylibre.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 1/5] libcamera: yaml_parser: Add getList()\n\tfunction","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":"Florian Sylvestre via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Florian Sylvestre <fsylvestre@baylibre.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Allow to retrieve a YAML list of any already supported types in a std::vector.\n\nSigned-off-by: Florian Sylvestre <fsylvestre@baylibre.com>\n---\n include/libcamera/internal/yaml_parser.h | 16 ++++++\n src/libcamera/yaml_parser.cpp            | 73 ++++++++++++++++++++++++\n test/yaml-parser.cpp                     |  6 ++\n 3 files changed, 95 insertions(+)","diff":"diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\nindex 064cf443..ea9189bd 100644\n--- a/include/libcamera/internal/yaml_parser.h\n+++ b/include/libcamera/internal/yaml_parser.h\n@@ -167,6 +167,22 @@ public:\n #endif\n \tT get(const T &defaultValue, bool *ok = nullptr) const;\n \n+#ifndef __DOXYGEN__\n+\ttemplate<typename T,\n+\t\t typename std::enable_if_t<\n+\t\t\t std::is_same<bool, T>::value ||\n+\t\t\t std::is_same<double, T>::value ||\n+\t\t\t std::is_same<int16_t, T>::value ||\n+\t\t\t std::is_same<uint16_t, T>::value ||\n+\t\t\t std::is_same<int32_t, T>::value ||\n+\t\t\t std::is_same<uint32_t, T>::value ||\n+\t\t\t std::is_same<std::string, T>::value ||\n+\t\t\t std::is_same<Size, T>::value> * = nullptr>\n+#else\n+\ttemplate<typename T>\n+#endif\n+\tstd::vector<T> getList(bool *ok = nullptr) 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 5c45e44e..95c0038b 100644\n--- a/src/libcamera/yaml_parser.cpp\n+++ b/src/libcamera/yaml_parser.cpp\n@@ -117,6 +117,23 @@ std::size_t YamlObject::size() const\n  * \\return Value as a bool type\n  */\n \n+/**\n+ * \\fn template<typename T> YamlObject::getList<T>(\n+ *\tbool *ok) const\n+ * \\brief Parse the YamlObject as a list of \\a T.\n+ * \\param[out] ok The result of whether the parse succeeded\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 \\a ok is set\n+ * to false and a default empty vector is returned. Otherwise, the\n+ * YamlObject list of values is returned, and \\a ok is set to true.\n+ *\n+ * The \\a ok pointer is optional and can be a nullptr if the caller doesn't\n+ * need to know if parsing succeeded.\n+ *\n+ * \\return Value as a std::vector<T> type\n+ */\n+\n #ifndef __DOXYGEN__\n \n template<>\n@@ -323,6 +340,62 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const\n \treturn Size(width, height);\n }\n \n+template<typename T,\n+\t typename std::enable_if_t<\n+\t\t std::is_same<bool, T>::value ||\n+\t\t std::is_same<double, T>::value ||\n+\t\t std::is_same<int16_t, T>::value ||\n+\t\t std::is_same<uint16_t, T>::value ||\n+\t\t std::is_same<int32_t, T>::value ||\n+\t\t std::is_same<uint32_t, T>::value ||\n+\t\t std::is_same<std::string, T>::value ||\n+\t\t std::is_same<Size, T>::value> *>\n+std::vector<T> YamlObject::getList(bool *ok) const\n+{\n+\tsetOk(ok, false);\n+\n+\tstd::vector<T> defaultValue;\n+\n+\tif (type_ != Type::List)\n+\t\treturn defaultValue;\n+\n+\tstd::vector<T> value = std::vector<T>(list_.size());\n+\n+\t/*\n+\t * Provide somme dummy defaultValue to get() function\n+\t * and rely on the ok variable to know if the parsing\n+\t * was correct.\n+\t */\n+\tT defaultArgument = T();\n+\tbool result;\n+\tfor (unsigned int i = 0; i < list_.size(); ++i) {\n+\t\tresult = true;\n+\t\tvalue[i] = list_[i]->get<T>(defaultArgument, &result);\n+\n+\t\tif (!result)\n+\t\t\treturn defaultValue;\n+\t}\n+\n+\tsetOk(ok, true);\n+\treturn value;\n+}\n+\n+template std::vector<bool> YamlObject::getList<bool>(bool *ok) const;\n+\n+template std::vector<double> YamlObject::getList<double>(bool *ok) const;\n+\n+template std::vector<int16_t> YamlObject::getList<int16_t>(bool *ok) const;\n+\n+template std::vector<uint16_t> YamlObject::getList<uint16_t>(bool *ok) const;\n+\n+template std::vector<int32_t> YamlObject::getList<int32_t>(bool *ok) const;\n+\n+template std::vector<uint32_t> YamlObject::getList<uint32_t>(bool *ok) const;\n+\n+template std::vector<std::string> YamlObject::getList<std::string>(bool *ok) const;\n+\n+template std::vector<Size> YamlObject::getList<Size>(bool *ok) const;\n+\n #endif /* __DOXYGEN__ */\n \n /**\ndiff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp\nindex 38f84823..bb96a11b 100644\n--- a/test/yaml-parser.cpp\n+++ b/test/yaml-parser.cpp\n@@ -524,6 +524,12 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\tstd::vector<uint16_t> values = firstElement.getList<uint16_t>();\n+\t\tif (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","1/5"]}