Patch Detail
Show a patch.
GET /api/patches/8546/?format=api
{ "id": 8546, "url": "https://patchwork.libcamera.org/api/patches/8546/?format=api", "web_url": "https://patchwork.libcamera.org/patch/8546/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200701210948.999363-2-niklas.soderlund@ragnatech.se>", "date": "2020-07-01T21:09:47", "name": "[libcamera-devel,v2,1/2] libcamera: utils: Add map_keys() function", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "deb90a78f91f9b3f6c0903fdc05489e895dca0fc", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/8546/mbox/", "series": [ { "id": 1069, "url": "https://patchwork.libcamera.org/api/series/1069/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1069", "date": "2020-07-01T21:09:46", "name": "libcamera: utils: Add map_keys() function", "version": 2, "mbox": "https://patchwork.libcamera.org/series/1069/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/8546/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/8546/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 87224C2E69\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 1 Jul 2020 21:10:06 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BE61660C58;\n\tWed, 1 Jul 2020 23:10:05 +0200 (CEST)", "from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1B4D360C53\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 1 Jul 2020 23:10:04 +0200 (CEST)", "from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de\n\t[79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 3a49eb76-bbdf-11ea-933e-005056917a89;\n\tWed, 01 Jul 2020 23:10:02 +0200 (CEST)" ], "X-Halon-ID": "3a49eb76-bbdf-11ea-933e-005056917a89", "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": "Wed, 1 Jul 2020 23:09:47 +0200", "Message-Id": "<20200701210948.999363-2-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.27.0", "In-Reply-To": "<20200701210948.999363-1-niklas.soderlund@ragnatech.se>", "References": "<20200701210948.999363-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v2 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>\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", "v2", "1/2" ] }