Show a patch.

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

{
    "id": 23098,
    "url": "https://patchwork.libcamera.org/api/patches/23098/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/23098/",
    "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": "<20250401131939.749583-5-barnabas.pocze@ideasonboard.com>",
    "date": "2025-04-01T13:19:39",
    "name": "[v1,4/4] libcamera: controls: Simplify ControlValue::{ControlValue, get, set}",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "970f8623f8dbce642ac8ca7ff201103aef8b910c",
    "submitter": {
        "id": 216,
        "url": "https://patchwork.libcamera.org/api/people/216/?format=api",
        "name": "Barnabás Pőcze",
        "email": "barnabas.pocze@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/23098/mbox/",
    "series": [
        {
            "id": 5101,
            "url": "https://patchwork.libcamera.org/api/series/5101/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5101",
            "date": "2025-04-01T13:19:35",
            "name": "libcamera: controls: Misc. changes",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/5101/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/23098/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/23098/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 C91C8C3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  1 Apr 2025 13:19:54 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 08BB668993;\n\tTue,  1 Apr 2025 15:19:50 +0200 (CEST)",
            "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 0FF9A68987\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  1 Apr 2025 15:19:44 +0200 (CEST)",
            "from pb-laptop.local (185.221.143.221.nat.pool.zt.hu\n\t[185.221.143.221])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D6EA78DB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  1 Apr 2025 15:17:51 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"wNTsAZWX\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1743513472;\n\tbh=mwW6x9TBMmlyGxuMnq6tMVV/YoQQ+Jb8V2Sov7+p4Zc=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=wNTsAZWXFzrdfxiJSQjnpN8OuE0+FMqWSzzN81TZacFDqyP0wHopuud6IQNqO83My\n\tCwu1J+XCvn9YuBVRLa8XKFVfvu9JhKFUmkMbrAFMokcn22IMmPMOE3t53onRuHGa7E\n\tZnNLYnHIIVYeNFaQXX/s4i9hlV0U2XzC2q7L9hXc=",
        "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[PATCH v1 4/4] libcamera: controls: Simplify\n\tControlValue::{ControlValue, get, set}",
        "Date": "Tue,  1 Apr 2025 15:19:39 +0200",
        "Message-ID": "<20250401131939.749583-5-barnabas.pocze@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.49.0",
        "In-Reply-To": "<20250401131939.749583-1-barnabas.pocze@ideasonboard.com>",
        "References": "<20250401131939.749583-1-barnabas.pocze@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Whether or not the control has an array type can be determined from the\nstatic information in `detail::control_type<T>`, so use that and\n`if constexpr` to deduplicate the constructor, get, and set functions.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n include/libcamera/controls.h | 75 ++++++++++--------------------------\n 1 file changed, 20 insertions(+), 55 deletions(-)",
    "diff": "diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex 85c724ec1..22b5e3d96 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -136,28 +136,14 @@ public:\n \tControlValue();\n \n #ifndef __DOXYGEN__\n-\ttemplate<typename T, std::enable_if_t<!details::is_span<T>::value &&\n-\t\t\t\t\t      details::control_type<T>::value &&\n-\t\t\t\t\t      !std::is_same<std::string, std::remove_cv_t<T>>::value,\n-\t\t\t\t\t      std::nullptr_t> = nullptr>\n-\tControlValue(const T &value)\n-\t\t: type_(ControlTypeNone), numElements_(0)\n-\t{\n-\t\tset(details::control_type<std::remove_cv_t<T>>::value, false,\n-\t\t    &value, 1, sizeof(T));\n-\t}\n-\n-\ttemplate<typename T, std::enable_if_t<details::is_span<T>::value ||\n-\t\t\t\t\t      std::is_same<std::string, std::remove_cv_t<T>>::value,\n-\t\t\t\t\t      std::nullptr_t> = nullptr>\n+\ttemplate<typename T, typename = std::void_t<decltype(details::control_type<T>::value)>>\n #else\n \ttemplate<typename T>\n #endif\n \tControlValue(const T &value)\n-\t\t: type_(ControlTypeNone), numElements_(0)\n+\t\t: type_(ControlTypeNone), isArray_(false), numElements_(0)\n \t{\n-\t\tset(details::control_type<std::remove_cv_t<T>>::value, true,\n-\t\t    value.data(), value.size(), sizeof(typename T::value_type));\n+\t\tset(value);\n \t}\n \n \t~ControlValue();\n@@ -180,54 +166,33 @@ public:\n \t\treturn !(*this == other);\n \t}\n \n-#ifndef __DOXYGEN__\n-\ttemplate<typename T, std::enable_if_t<!details::is_span<T>::value &&\n-\t\t\t\t\t      !std::is_same<std::string, std::remove_cv_t<T>>::value,\n-\t\t\t\t\t      std::nullptr_t> = nullptr>\n-\tT get() const\n-\t{\n-\t\tassert(type_ == details::control_type<std::remove_cv_t<T>>::value);\n-\t\tassert(!isArray_);\n-\n-\t\treturn *reinterpret_cast<const T *>(data().data());\n-\t}\n-\n-\ttemplate<typename T, std::enable_if_t<details::is_span<T>::value ||\n-\t\t\t\t\t      std::is_same<std::string, std::remove_cv_t<T>>::value,\n-\t\t\t\t\t      std::nullptr_t> = nullptr>\n-#else\n \ttemplate<typename T>\n-#endif\n \tT get() const\n \t{\n-\t\tassert(type_ == details::control_type<std::remove_cv_t<T>>::value);\n-\t\tassert(isArray_);\n+\t\tusing TypeInfo = details::control_type<std::remove_cv_t<T>>;\n \n-\t\tusing V = typename T::value_type;\n-\t\tconst V *value = reinterpret_cast<const V *>(data().data());\n-\t\treturn T{ value, numElements_ };\n-\t}\n+\t\tassert(type_ == TypeInfo::value);\n+\t\tassert(isArray_ == (TypeInfo::size > 0));\n \n-#ifndef __DOXYGEN__\n-\ttemplate<typename T, std::enable_if_t<!details::is_span<T>::value &&\n-\t\t\t\t\t      !std::is_same<std::string, std::remove_cv_t<T>>::value,\n-\t\t\t\t\t      std::nullptr_t> = nullptr>\n-\tvoid set(const T &value)\n-\t{\n-\t\tset(details::control_type<std::remove_cv_t<T>>::value, false,\n-\t\t    reinterpret_cast<const void *>(&value), 1, sizeof(T));\n+\t\tif constexpr (TypeInfo::size > 0)\n+\t\t\treturn T(reinterpret_cast<const typename T::value_type *>(data().data()), numElements_);\n+\t\telse\n+\t\t\treturn *reinterpret_cast<const T *>(data().data());\n \t}\n \n-\ttemplate<typename T, std::enable_if_t<details::is_span<T>::value ||\n-\t\t\t\t\t      std::is_same<std::string, std::remove_cv_t<T>>::value,\n-\t\t\t\t\t      std::nullptr_t> = nullptr>\n-#else\n \ttemplate<typename T>\n-#endif\n \tvoid set(const T &value)\n \t{\n-\t\tset(details::control_type<std::remove_cv_t<T>>::value, true,\n-\t\t    value.data(), value.size(), sizeof(typename T::value_type));\n+\t\tusing TypeInfo = details::control_type<std::remove_cv_t<T>>;\n+\t\tconstexpr auto type = TypeInfo::value;\n+\n+\t\tif constexpr (TypeInfo::size > 0) {\n+\t\t\tstatic_assert(std::is_trivially_copyable_v<typename T::value_type>);\n+\t\t\tset(type, true, value.data(), value.size(), sizeof(typename T::value_type));\n+\t\t} else {\n+\t\t\tstatic_assert(std::is_trivially_copyable_v<T>);\n+\t\t\tset(type, false, reinterpret_cast<const void *>(&value), 1, sizeof(T));\n+\t\t}\n \t}\n \n \tvoid reserve(ControlType type, bool isArray = false,\n",
    "prefixes": [
        "v1",
        "4/4"
    ]
}