Show a patch.

GET /api/1.1/patches/2627/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2627,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/2627/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2627/",
    "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": "<20200113164245.52535-13-jacopo@jmondi.org>",
    "date": "2020-01-13T16:42:34",
    "name": "[libcamera-devel,12/23] libcamera: Add C++20 std::span<> implementation",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "b5352357208556b3904033cc081a3fed3359037a",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": {
        "id": 15,
        "url": "https://patchwork.libcamera.org/api/1.1/users/15/?format=api",
        "username": "jmondi",
        "first_name": "Jacopo",
        "last_name": "Mondi",
        "email": "jacopo@jmondi.org"
    },
    "mbox": "https://patchwork.libcamera.org/patch/2627/mbox/",
    "series": [
        {
            "id": 618,
            "url": "https://patchwork.libcamera.org/api/1.1/series/618/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=618",
            "date": "2020-01-13T16:42:22",
            "name": "Properties and compound controls",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/618/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2627/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2627/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1D258606EA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Jan 2020 17:40:34 +0100 (CET)",
            "from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id ABA0B100009;\n\tMon, 13 Jan 2020 16:40:33 +0000 (UTC)"
        ],
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 13 Jan 2020 17:42:34 +0100",
        "Message-Id": "<20200113164245.52535-13-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.24.0",
        "In-Reply-To": "<20200113164245.52535-1-jacopo@jmondi.org>",
        "References": "<20200113164245.52535-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 12/23] libcamera: Add C++20 std::span<>\n\timplementation",
        "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": "Mon, 13 Jan 2020 16:40:34 -0000"
    },
    "content": "Add a simplified implementation of C++20 std::span<> class.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n Documentation/Doxyfile.in     |   4 +-\n include/libcamera/meson.build |   1 +\n include/libcamera/span.h      |  89 +++++++++++++++++++++++\n src/libcamera/meson.build     |   1 +\n src/libcamera/span.cpp        | 128 ++++++++++++++++++++++++++++++++++\n 5 files changed, 222 insertions(+), 1 deletion(-)\n create mode 100644 include/libcamera/span.h\n create mode 100644 src/libcamera/span.cpp",
    "diff": "diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in\nindex 8e6fbdbb92b6..6b08960a921f 100644\n--- a/Documentation/Doxyfile.in\n+++ b/Documentation/Doxyfile.in\n@@ -838,8 +838,10 @@ RECURSIVE              = YES\n # Note that relative paths are relative to the directory from which doxygen is\n # run.\n \n-EXCLUDE                = @TOP_SRCDIR@/src/libcamera/device_enumerator_sysfs.cpp \\\n+EXCLUDE                = @TOP_SRCDIR@/include/libcamera/span.h \\\n+\t\t\t @TOP_SRCDIR@/src/libcamera/device_enumerator_sysfs.cpp \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/device_enumerator_udev.cpp \\\n+\t\t\t @TOP_SRCDIR@/src/libcamera/span.cpp \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/include/device_enumerator_sysfs.h \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/include/device_enumerator_udev.h \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/pipeline/ \\\ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex f58c02d2cf35..f47c583cbbc0 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -14,6 +14,7 @@ libcamera_api = files([\n     'pixelformats.h',\n     'request.h',\n     'signal.h',\n+    'span.h',\n     'stream.h',\n     'timer.h',\n ])\ndiff --git a/include/libcamera/span.h b/include/libcamera/span.h\nnew file mode 100644\nindex 000000000000..3e63603f60ed\n--- /dev/null\n+++ b/include/libcamera/span.h\n@@ -0,0 +1,89 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * span.h - C++20 std::span<> implementation for C++11\n+ */\n+\n+#ifndef __LIBCAMERA_SPAN_H__\n+#define __LIBCAMERA_SPAN_H__\n+\n+#include <array>\n+#include <stddef.h>\n+\n+namespace libcamera {\n+\n+template<typename T>\n+class Span\n+{\n+private:\n+\tusing iterator = T *;\n+\tusing const_iterator = const T *;\n+\n+\tclass Storage\n+\t{\n+\tpublic:\n+\t\tStorage(T *ptr, size_t size)\n+\t\t\t: ptr_(ptr), size_(size)\n+\t\t{\n+\t\t}\n+\n+\t\tT *ptr() const { return ptr_; }\n+\t\tsize_t size() const { return size_; }\n+\n+\tprivate:\n+\t\tT *ptr_;\n+\t\tsize_t size_;\n+\t};\n+\n+public:\n+\tSpan(T &v)\n+\t\t: storage_(&v, 1)\n+\t{\n+\t}\n+\n+\tSpan(const T &v)\n+\t\t: storage_(const_cast<T *>(&v), 1)\n+\t{\n+\t}\n+\n+\tSpan(T *v, size_t s)\n+\t\t: storage_(v, s)\n+\t{\n+\t}\n+\n+\tSpan(const T *v, size_t s)\n+\t\t: storage_(const_cast<T *>(v), s)\n+\t{\n+\t}\n+\n+\tSpan(std::initializer_list<T> list)\n+\t\t: storage_(const_cast<T *>(list.begin()), list.size())\n+\t{\n+\t}\n+\n+\tSpan(const Span &other) = default;\n+\tSpan &operator=(const Span &other) = default;\n+\n+\tT *data() const { return storage_.ptr(); }\n+\tsize_t size() const { return storage_.size(); }\n+\n+\tT &operator[](unsigned int index) const\n+\t{\n+\t\tif (index >= size())\n+\t\t\treturn *(end() - 1);\n+\t\treturn *(data() + index);\n+\t}\n+\n+\tconstexpr iterator begin() const { return data(); }\n+\tconstexpr iterator cbegin() const { return begin(); }\n+\tconstexpr iterator end() const { return data() + size(); }\n+\tconstexpr iterator cend() const { return end(); }\n+\n+private:\n+\tStorage storage_;\n+};\n+\n+}; /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_SPAN_H__ */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 1e5b54b34078..ecc5b5fe4023 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -36,6 +36,7 @@ libcamera_sources = files([\n     'request.cpp',\n     'semaphore.cpp',\n     'signal.cpp',\n+    'span.cpp',\n     'stream.cpp',\n     'thread.cpp',\n     'timer.cpp',\ndiff --git a/src/libcamera/span.cpp b/src/libcamera/span.cpp\nnew file mode 100644\nindex 000000000000..72ffdf7481c4\n--- /dev/null\n+++ b/src/libcamera/span.cpp\n@@ -0,0 +1,128 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * span.h - C++20 std::span<> implementation for C++11\n+ */\n+\n+#include <libcamera/span.h>\n+\n+/**\n+ * \\file span.h\n+ * \\brief libcamera implementation of C++20 std::span<>\n+ */\n+\n+namespace libcamera {\n+\n+/**\n+ * \\class Span\n+ * \\brief Representation of a sequence of contiguous objects of type T\n+ *\n+ * This class represents a sequence of fixed size of contiguous objects of\n+ * template type T with the first object residing in position 0.\n+ *\n+ * A Span internally consists of a pointer to raw memory and an associated\n+ * number of elements there located. It does not enforce any ownership on the\n+ * memory it represents, but it only provides a convenient, lightweight and\n+ * easily transportable view on such memory area.\n+ *\n+ * A Span can be constructed from a single element as well as from raw memory\n+ * by providing an associated size. It can be accessed by index and iterated\n+ * as a regular standard library container. As Span does not enforce any memory\n+ * ownership, destroying a Span instance does not invalidate the memory it\n+ * represents.\n+ *\n+ * The libcamera implementation of Span it's a simplified implementation of\n+ * C++20 the std::span<> class and it is no 1-to-1 compatible with it. Care\n+ * should be taken in not mixing usage of the two classes.\n+ */\n+\n+/**\n+ * \\fn Span::Span(T &v)\n+ * \\brief Contruct a Span of size 1 representing element \\a v\n+ * \\param[in] v The element represented by the Span\n+ */\n+\n+/**\n+ * \\fn Span::Span(const T &v)\n+ * \\brief Contruct a Span of size 1 representing the constant element \\a v\n+ * \\param[in] v The constant element represented by the Span\n+ */\n+\n+/**\n+ * \\fn Span::Span(T *v, size_t s)\n+ * \\brief Contruct a Span of size \\a s representing elements in memory \\a v\n+ * \\param[in] v The memory area represeted by the Span\n+ * \\param[in] s The number of elements in memory area \\a v\n+ */\n+\n+/**\n+ * \\fn Span::Span(const T *v, size_t s)\n+ * \\brief Contruct a Span of size \\a s representing elements in constant memory \\a v\n+ * \\param[in] v The constant memory area represeted by the Span\n+ * \\param[in] s The number of elements in memory area \\a v\n+ */\n+\n+/**\n+ * \\fn Span::Span(std::initializer_list<T> list)\n+ * \\brief Contruct a Span with an initialier list of elements\n+ * \\param[in] list The initializer list\n+ */\n+\n+/**\n+ * \\fn Span::Span(const Span &other)\n+ * \\brief Contruct a Span with the content of \\a other\n+ * \\param[in] other The other Span\n+ */\n+\n+/**\n+ * \\fn Span::operator=(const Span &other)\n+ * \\brief Replace the content of the Span with the one from \\a other\n+ * \\param[in] other The other Span\n+ */\n+\n+/**\n+ * \\fn Span::data()\n+ * \\brief Retrieve a pointer to the beginning of the memory area represented by\n+ * the Span\n+ * \\return A pointer to the raw memory area\n+ */\n+\n+/**\n+ * \\fn Span::size()\n+ * \\brief Retrieve the number of elements in the Span\n+ * \\return The number of elements in the Span\n+ */\n+\n+/**\n+ * \\fn Span::operator[](unsigned int index)\n+ * \\brief Retrieve element in position \\a index\n+ * \\param[in] index\n+ *\n+ * If \\a index is larger than the number of elements in the Span, the last\n+ * element is returned.\n+ *\n+ * \\return The element at position \\a index\n+ */\n+\n+/**\n+ * \\fn iterator Span::begin()\n+ * \\brief Retrieve an iterator to the first element in the Span\n+ */\n+\n+/**\n+ * \\fn const_iterator Span::cbegin()\n+ * \\brief Retrieve a constant iterator to the first element in the Span\n+ */\n+\n+/**\n+ * \\fn iterator Span::end()\n+ * \\brief Retrieve an iterator pointing to the past-the-end element in the Span\n+ */\n+\n+/**\n+ * \\fn const_iterator Span::cend()\n+ * \\brief Retrieve a constant iterator pointing to the past-the-end element in the Span\n+ */\n+\n+} /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "12/23"
    ]
}