Patch Detail
Show a patch.
GET /api/1.1/patches/3379/?format=api
{ "id": 3379, "url": "https://patchwork.libcamera.org/api/1.1/patches/3379/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3379/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20200404004438.17992-3-laurent.pinchart@ideasonboard.com>", "date": "2020-04-04T00:44:29", "name": "[libcamera-devel,v4,02/11] libcamera: utils: Add string join function", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "a6f40c734aade7ff5eae7d7583c3e8a6634356dc", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3379/mbox/", "series": [ { "id": 796, "url": "https://patchwork.libcamera.org/api/1.1/series/796/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=796", "date": "2020-04-04T00:44:27", "name": "Simple pipeline handler", "version": 4, "mbox": "https://patchwork.libcamera.org/series/796/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3379/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3379/checks/", "tags": {}, "headers": { "Return-Path": "<laurent.pinchart@ideasonboard.com>", "Received": [ "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 97F16605D1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 4 Apr 2020 02:44:52 +0200 (CEST)", "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0C5E972E;\n\tSat, 4 Apr 2020 02:44:51 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"DWb1CjQ8\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1585961092;\n\tbh=GJot6HF1SG9eiADRdo2WwxIhwXYKPWyxLEI7qzHNHyk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=DWb1CjQ8qGHe7a3jrBPdRhp9DrlJq6zJMwStqoWbs1iG05eyd/704TOkJCPFfFPt6\n\tcODMq0+l8evj+q/cWMVXXrHN62/sHrsyjQH7ku5T+pFYmOTYjYfblfrSVudsm2MElc\n\tMAbOGDLAC1ZTRNbrQiZh/IYbMbMVwFaiYHLmusTE=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Martijn Braam <martijn@brixit.nl>,\n\tBenjamin GAIGNARD <benjamin.gaignard@st.com>,\n\tAndrey Konovalov <andrey.konovalov@linaro.org>", "Date": "Sat, 4 Apr 2020 03:44:29 +0300", "Message-Id": "<20200404004438.17992-3-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.24.1", "In-Reply-To": "<20200404004438.17992-1-laurent.pinchart@ideasonboard.com>", "References": "<20200404004438.17992-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 02/11] libcamera: utils: Add string\n\tjoin 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>", "X-List-Received-Date": "Sat, 04 Apr 2020 00:44:52 -0000" }, "content": "Add a utils::join() function to join elements of a container into a\nstring, with a separator and an optional conversion function if the\nelements are not implicitly convertible to std::string.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\nChanges since v3:\n\n- Add a test for the conversion function\n---\n src/libcamera/include/utils.h | 44 +++++++++++++++++++++++++++++++++++\n src/libcamera/utils.cpp | 16 +++++++++++++\n test/utils.cpp | 20 +++++++++++++++-\n 3 files changed, 79 insertions(+), 1 deletion(-)", "diff": "diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\nindex cfa620f24581..242eeded9d50 100644\n--- a/src/libcamera/include/utils.h\n+++ b/src/libcamera/include/utils.h\n@@ -11,6 +11,7 @@\n #include <chrono>\n #include <memory>\n #include <ostream>\n+#include <sstream>\n #include <string>\n #include <string.h>\n #include <sys/time.h>\n@@ -109,6 +110,49 @@ inline _hex hex<uint64_t>(uint64_t value, unsigned int width)\n \n size_t strlcpy(char *dst, const char *src, size_t size);\n \n+#ifndef __DOXYGEN__\n+template<typename Container, typename UnaryOp>\n+std::string join(const Container &items, const std::string &sep, UnaryOp op)\n+{\n+\tstd::ostringstream ss;\n+\tbool first = true;\n+\n+\tfor (typename Container::const_iterator it = std::begin(items);\n+\t it != std::end(items); ++it) {\n+\t\tif (!first)\n+\t\t\tss << sep;\n+\t\telse\n+\t\t\tfirst = false;\n+\n+\t\tss << op(*it);\n+\t}\n+\n+\treturn ss.str();\n+}\n+\n+template<typename Container>\n+std::string join(const Container &items, const std::string &sep)\n+{\n+\tstd::ostringstream ss;\n+\tbool first = true;\n+\n+\tfor (typename Container::const_iterator it = std::begin(items);\n+\t it != std::end(items); ++it) {\n+\t\tif (!first)\n+\t\t\tss << sep;\n+\t\telse\n+\t\t\tfirst = false;\n+\n+\t\tss << *it;\n+\t}\n+\n+\treturn ss.str();\n+}\n+#else\n+template<typename Container, typename UnaryOp>\n+std::string join(const Container &items, const std::string &sep, UnaryOp op = nullptr);\n+#endif\n+\n namespace details {\n \n class StringSplitter\ndiff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\nindex 58ee7cc19c8c..97f9b632e45b 100644\n--- a/src/libcamera/utils.cpp\n+++ b/src/libcamera/utils.cpp\n@@ -297,6 +297,22 @@ details::StringSplitter::iterator details::StringSplitter::end() const\n \treturn iterator(this, std::string::npos);\n }\n \n+/**\n+ * \\fn template<typename Container, typename UnaryOp> \\\n+ * std::string utils::join(const Container &items, const std::string &sep, UnaryOp op)\n+ * \\brief Join elements of a container in a string with a separator\n+ * \\param[in] items The container\n+ * \\param[in] sep The separator to add between elements\n+ * \\param[in] op A function that converts individual elements to strings\n+ *\n+ * This function joins all elements in the \\a items container into a string and\n+ * returns it. The \\a sep separator is added between elements. If the container\n+ * elements are not implicitly convertible to std::string, the \\a op function\n+ * shall be provided to perform conversion of elements to std::string.\n+ *\n+ * \\return A string that concatenates all elements in the container\n+ */\n+\n /**\n * \\fn split(const std::string &str, const std::string &delim)\n * \\brief Split a string based on a delimiter\ndiff --git a/test/utils.cpp b/test/utils.cpp\nindex 58816f153066..55ce9365a53e 100644\n--- a/test/utils.cpp\n+++ b/test/utils.cpp\n@@ -10,6 +10,8 @@\n #include <string>\n #include <vector>\n \n+#include <libcamera/geometry.h>\n+\n #include \"test.h\"\n #include \"utils.h\"\n \n@@ -99,7 +101,7 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\t/* utils::split() test. */\n+\t\t/* utils::join() and utils::split() test. */\n \t\tstd::vector<std::string> elements = {\n \t\t\t\"/bin\",\n \t\t\t\"/usr/bin\",\n@@ -111,6 +113,11 @@ protected:\n \t\tfor (const auto &element : elements)\n \t\t\tpath += (path.empty() ? \"\" : \":\") + element;\n \n+\t\tif (path != utils::join(elements, \":\")) {\n+\t\t\tcerr << \"utils::join() test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\tstd::vector<std::string> dirs;\n \n \t\tfor (const auto &dir : utils::split(path, \":\"))\n@@ -121,6 +128,17 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\t/* utils::join() with conversion function test. */\n+\t\tstd::vector<Size> sizes = { { 0, 0 }, { 100, 100 } };\n+\t\ts = utils::join(sizes, \"/\", [](const Size &size) {\n+\t\t\t\t\treturn size.toString();\n+\t\t\t\t});\n+\n+\t\tif (s != \"0x0/100x100\") {\n+\t\t\tcerr << \"utils::join() with conversion test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\t/* utils::dirname() tests. */\n \t\tif (TestPass != testDirname())\n \t\t\treturn TestFail;\n", "prefixes": [ "libcamera-devel", "v4", "02/11" ] }