{"id":8567,"url":"https://patchwork.libcamera.org/api/1.1/patches/8567/?format=json","web_url":"https://patchwork.libcamera.org/patch/8567/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20200702231107.1800602-2-niklas.soderlund@ragnatech.se>","date":"2020-07-02T23:11:06","name":"[libcamera-devel,v3,1/2] libcamera: utils: Add map_keys() function","commit_ref":"c58bec935c3adffac9d99b1675a563d7f2e9ae04","pull_url":null,"state":"accepted","archived":false,"hash":"deb90a78f91f9b3f6c0903fdc05489e895dca0fc","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/8567/mbox/","series":[{"id":1075,"url":"https://patchwork.libcamera.org/api/1.1/series/1075/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1075","date":"2020-07-02T23:11:05","name":"libcamera: utils: Add map_keys() function","version":3,"mbox":"https://patchwork.libcamera.org/series/1075/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/8567/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/8567/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 83BFEBE905\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  2 Jul 2020 23:11:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 86E0260C5F;\n\tFri,  3 Jul 2020 01:11:14 +0200 (CEST)","from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D39B2609C7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Jul 2020 01:11:12 +0200 (CEST)","from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de\n\t[79.202.46.202]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid 51ebd0f5-bcb9-11ea-8fb8-005056917f90;\n\tFri, 03 Jul 2020 01:11:12 +0200 (CEST)"],"X-Halon-ID":"51ebd0f5-bcb9-11ea-8fb8-005056917f90","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  3 Jul 2020 01:11:06 +0200","Message-Id":"<20200702231107.1800602-2-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20200702231107.1800602-1-niklas.soderlund@ragnatech.se>","References":"<20200702231107.1800602-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v3 1/2] libcamera: utils: Add map_keys()\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>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nAdd a map_keys() function to the utils namespace to extract keys from a\nmap.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n[Niklas: change return type to std::vector instead of std::set]\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/internal/utils.h | 10 ++++++++++\n src/libcamera/utils.cpp            |  7 +++++++\n test/utils.cpp                     | 22 ++++++++++++++++++++++\n 3 files changed, 39 insertions(+)","diff":"diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h\nindex 0953423ee8d04466..8d026cc6c0fe777a 100644\n--- a/include/libcamera/internal/utils.h\n+++ b/include/libcamera/internal/utils.h\n@@ -15,6 +15,7 @@\n #include <string>\n #include <string.h>\n #include <sys/time.h>\n+#include <vector>\n \n #define ARRAY_SIZE(a)\t(sizeof(a) / sizeof(a[0]))\n \n@@ -36,6 +37,15 @@ const char *basename(const char *path);\n char *secure_getenv(const char *name);\n std::string dirname(const std::string &path);\n \n+template<typename T>\n+std::vector<typename T::key_type> map_keys(const T &map)\n+{\n+\tstd::vector<typename T::key_type> keys;\n+\tstd::transform(map.begin(), map.end(), std::back_inserter(keys),\n+\t\t       [](const auto &value) { return value.first; });\n+\treturn keys;\n+}\n+\n template<class InputIt1, class InputIt2>\n unsigned int set_overlap(InputIt1 first1, InputIt1 last1,\n \t\t\t InputIt2 first2, InputIt2 last2)\ndiff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\nindex d55338fe681a8516..0567328fe31ba6f9 100644\n--- a/src/libcamera/utils.cpp\n+++ b/src/libcamera/utils.cpp\n@@ -127,6 +127,13 @@ std::string dirname(const std::string &path)\n \treturn path.substr(0, pos + 1);\n }\n \n+/**\n+ * \\fn std::vector<typename T::key_type> map_keys(const T &map)\n+ * \\brief Retrieve the keys of a std::map<>\n+ * \\param[in] map The map whose keys to retrieve\n+ * \\return A std::vector<> containing the keys of \\a map\n+ */\n+\n /**\n  * \\fn libcamera::utils::set_overlap(InputIt1 first1, InputIt1 last1,\n  *\t\t\t\t     InputIt2 first2, InputIt2 last2)\ndiff --git a/test/utils.cpp b/test/utils.cpp\nindex 66b91f1203e1f4e8..f482e6a1d829edbd 100644\n--- a/test/utils.cpp\n+++ b/test/utils.cpp\n@@ -6,6 +6,7 @@\n  */\n \n #include <iostream>\n+#include <map>\n #include <sstream>\n #include <string>\n #include <vector>\n@@ -144,6 +145,27 @@ protected:\n \t\tif (TestPass != testDirname())\n \t\t\treturn TestFail;\n \n+\n+\t\t/* utils::map_keys() test. */\n+\t\tconst std::map<std::string, unsigned int> map{\n+\t\t\t{ \"zero\", 0 },\n+\t\t\t{ \"one\", 1 },\n+\t\t\t{ \"two\", 2 },\n+\t\t};\n+\t\tstd::vector<std::string> expectedKeys{\n+\t\t\t\"zero\",\n+\t\t\t\"one\",\n+\t\t\t\"two\",\n+\t\t};\n+\n+\t\tstd::sort(expectedKeys.begin(), expectedKeys.end());\n+\n+\t\tconst std::vector<std::string> keys = utils::map_keys(map);\n+\t\tif (keys != expectedKeys) {\n+\t\t\tcerr << \"utils::map_keys() test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\treturn TestPass;\n \t}\n };\n","prefixes":["libcamera-devel","v3","1/2"]}