Patch Detail
Show a patch.
GET /api/1.1/patches/20274/?format=api
{ "id": 20274, "url": "https://patchwork.libcamera.org/api/1.1/patches/20274/?format=api", "web_url": "https://patchwork.libcamera.org/patch/20274/", "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": "<20240613013944.23344-3-laurent.pinchart@ideasonboard.com>", "date": "2024-06-13T01:39:35", "name": "[02/11] libcamera: yaml_parser: Delegate YamlObject::get() to helper structure", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "304756dba098ae13a9ed20e7d2be7d613b25fea0", "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/20274/mbox/", "series": [ { "id": 4386, "url": "https://patchwork.libcamera.org/api/1.1/series/4386/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4386", "date": "2024-06-13T01:39:33", "name": "ipa: libipa: Vector and Pwl improvements", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4386/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/20274/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/20274/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 19284C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Jun 2024 01:40:12 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E202F6548E;\n\tThu, 13 Jun 2024 03:40:10 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A6F2C6548D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jun 2024 03:40:07 +0200 (CEST)", "from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DB842D77;\n\tThu, 13 Jun 2024 03:39:53 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"hm0R90g1\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1718242794;\n\tbh=rpXcpQX6Ga5FqCCk4kox9hOvcSZpo6tu6GCqeSqh7nI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=hm0R90g1qgK/MdAguc3ykL2G65RlPBgD+gWu1y3XBNCh+Zos8KLnLMSUSbDOHpZKR\n\tS7gcQcarJSUZcnlVAoK21W9CUFB9ns1vqQb/5ANQpMZ0kVK1A5dUfkeIsxafQExuBK\n\t+/QAFFOF9BAO5b2NTsNd+jSc5cA6X6h4P7LBcsCc=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Paul Elder <paul.elder@ideasonboard.com>,\n\tDavid Plowman <david.plowman@raspberrypi.com>,\n\tNaushir Patuck <naush@raspberrypi.com>", "Subject": "[PATCH 02/11] libcamera: yaml_parser: Delegate YamlObject::get() to\n\thelper structure", "Date": "Thu, 13 Jun 2024 04:39:35 +0300", "Message-ID": "<20240613013944.23344-3-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.44.2", "In-Reply-To": "<20240613013944.23344-1-laurent.pinchart@ideasonboard.com>", "References": "<20240613013944.23344-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "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": "The YamlObject::get() function is a function template that gets fully\nspecialized for various types. This works fine for non-template types,\nbut specializing it for template types (e.g. a std::vector<U>) would\nrequire partial template specialization, which C++ allows for classes\nand variables but not functions.\n\nTo work around this problem, delegate the implementation to a new\nYamlObject::Getter structure template, which will support partial\nspecialization.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/internal/yaml_parser.h | 12 +++-\n src/libcamera/yaml_parser.cpp | 78 +++++++++++++-----------\n 2 files changed, 55 insertions(+), 35 deletions(-)", "diff": "diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\nindex 81cc0e25ae0f..06a41146ad01 100644\n--- a/include/libcamera/internal/yaml_parser.h\n+++ b/include/libcamera/internal/yaml_parser.h\n@@ -162,7 +162,10 @@ public:\n \tstd::size_t size() const;\n \n \ttemplate<typename T>\n-\tstd::optional<T> get() const;\n+\tstd::optional<T> get() const\n+\t{\n+\t\treturn Getter<T>{}.get(*this);\n+\t}\n \n \ttemplate<typename T, typename U>\n \tT get(U &&defaultValue) const\n@@ -199,6 +202,8 @@ public:\n private:\n \tLIBCAMERA_DISABLE_COPY_AND_MOVE(YamlObject)\n \n+\ttemplate<typename T>\n+\tfriend struct Getter;\n \tfriend class YamlParserContext;\n \n \tenum class Type {\n@@ -207,6 +212,11 @@ private:\n \t\tValue,\n \t};\n \n+\ttemplate<typename T>\n+\tstruct Getter {\n+\t\tstd::optional<T> get(const YamlObject &obj) const;\n+\t};\n+\n \tType type_;\n \n \tstd::string value_;\ndiff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\nindex b68a44c15c35..56670ba7a584 100644\n--- a/src/libcamera/yaml_parser.cpp\n+++ b/src/libcamera/yaml_parser.cpp\n@@ -118,14 +118,15 @@ std::size_t YamlObject::size() const\n #ifndef __DOXYGEN__\n \n template<>\n-std::optional<bool> YamlObject::get() const\n+std::optional<bool>\n+YamlObject::Getter<bool>::get(const YamlObject &obj) const\n {\n-\tif (type_ != Type::Value)\n+\tif (obj.type_ != Type::Value)\n \t\treturn std::nullopt;\n \n-\tif (value_ == \"true\")\n+\tif (obj.value_ == \"true\")\n \t\treturn true;\n-\telse if (value_ == \"false\")\n+\telse if (obj.value_ == \"false\")\n \t\treturn false;\n \n \treturn std::nullopt;\n@@ -182,14 +183,15 @@ bool parseUnsignedInteger(const std::string &str, unsigned long max,\n } /* namespace */\n \n template<>\n-std::optional<int8_t> YamlObject::get() const\n+std::optional<int8_t>\n+YamlObject::Getter<int8_t>::get(const YamlObject &obj) const\n {\n-\tif (type_ != Type::Value)\n+\tif (obj.type_ != Type::Value)\n \t\treturn std::nullopt;\n \n \tlong value;\n \n-\tif (!parseSignedInteger(value_, std::numeric_limits<int8_t>::min(),\n+\tif (!parseSignedInteger(obj.value_, std::numeric_limits<int8_t>::min(),\n \t\t\t\tstd::numeric_limits<int8_t>::max(), &value))\n \t\treturn std::nullopt;\n \n@@ -197,14 +199,15 @@ std::optional<int8_t> YamlObject::get() const\n }\n \n template<>\n-std::optional<uint8_t> YamlObject::get() const\n+std::optional<uint8_t>\n+YamlObject::Getter<uint8_t>::get(const YamlObject &obj) const\n {\n-\tif (type_ != Type::Value)\n+\tif (obj.type_ != Type::Value)\n \t\treturn std::nullopt;\n \n \tunsigned long value;\n \n-\tif (!parseUnsignedInteger(value_, std::numeric_limits<uint8_t>::max(),\n+\tif (!parseUnsignedInteger(obj.value_, std::numeric_limits<uint8_t>::max(),\n \t\t\t\t &value))\n \t\treturn std::nullopt;\n \n@@ -212,14 +215,15 @@ std::optional<uint8_t> YamlObject::get() const\n }\n \n template<>\n-std::optional<int16_t> YamlObject::get() const\n+std::optional<int16_t>\n+YamlObject::Getter<int16_t>::get(const YamlObject &obj) const\n {\n-\tif (type_ != Type::Value)\n+\tif (obj.type_ != Type::Value)\n \t\treturn std::nullopt;\n \n \tlong value;\n \n-\tif (!parseSignedInteger(value_, std::numeric_limits<int16_t>::min(),\n+\tif (!parseSignedInteger(obj.value_, std::numeric_limits<int16_t>::min(),\n \t\t\t\tstd::numeric_limits<int16_t>::max(), &value))\n \t\treturn std::nullopt;\n \n@@ -227,14 +231,15 @@ std::optional<int16_t> YamlObject::get() const\n }\n \n template<>\n-std::optional<uint16_t> YamlObject::get() const\n+std::optional<uint16_t>\n+YamlObject::Getter<uint16_t>::get(const YamlObject &obj) const\n {\n-\tif (type_ != Type::Value)\n+\tif (obj.type_ != Type::Value)\n \t\treturn std::nullopt;\n \n \tunsigned long value;\n \n-\tif (!parseUnsignedInteger(value_, std::numeric_limits<uint16_t>::max(),\n+\tif (!parseUnsignedInteger(obj.value_, std::numeric_limits<uint16_t>::max(),\n \t\t\t\t &value))\n \t\treturn std::nullopt;\n \n@@ -242,14 +247,15 @@ std::optional<uint16_t> YamlObject::get() const\n }\n \n template<>\n-std::optional<int32_t> YamlObject::get() const\n+std::optional<int32_t>\n+YamlObject::Getter<int32_t>::get(const YamlObject &obj) const\n {\n-\tif (type_ != Type::Value)\n+\tif (obj.type_ != Type::Value)\n \t\treturn std::nullopt;\n \n \tlong value;\n \n-\tif (!parseSignedInteger(value_, std::numeric_limits<int32_t>::min(),\n+\tif (!parseSignedInteger(obj.value_, std::numeric_limits<int32_t>::min(),\n \t\t\t\tstd::numeric_limits<int32_t>::max(), &value))\n \t\treturn std::nullopt;\n \n@@ -257,14 +263,15 @@ std::optional<int32_t> YamlObject::get() const\n }\n \n template<>\n-std::optional<uint32_t> YamlObject::get() const\n+std::optional<uint32_t>\n+YamlObject::Getter<uint32_t>::get(const YamlObject &obj) const\n {\n-\tif (type_ != Type::Value)\n+\tif (obj.type_ != Type::Value)\n \t\treturn std::nullopt;\n \n \tunsigned long value;\n \n-\tif (!parseUnsignedInteger(value_, std::numeric_limits<uint32_t>::max(),\n+\tif (!parseUnsignedInteger(obj.value_, std::numeric_limits<uint32_t>::max(),\n \t\t\t\t &value))\n \t\treturn std::nullopt;\n \n@@ -272,18 +279,19 @@ std::optional<uint32_t> YamlObject::get() const\n }\n \n template<>\n-std::optional<double> YamlObject::get() const\n+std::optional<double>\n+YamlObject::Getter<double>::get(const YamlObject &obj) const\n {\n-\tif (type_ != Type::Value)\n+\tif (obj.type_ != Type::Value)\n \t\treturn std::nullopt;\n \n-\tif (value_ == \"\")\n+\tif (obj.value_ == \"\")\n \t\treturn std::nullopt;\n \n \tchar *end;\n \n \terrno = 0;\n-\tdouble value = utils::strtod(value_.c_str(), &end);\n+\tdouble value = utils::strtod(obj.value_.c_str(), &end);\n \n \tif ('\\0' != *end || errno == ERANGE)\n \t\treturn std::nullopt;\n@@ -292,28 +300,30 @@ std::optional<double> YamlObject::get() const\n }\n \n template<>\n-std::optional<std::string> YamlObject::get() const\n+std::optional<std::string>\n+YamlObject::Getter<std::string>::get(const YamlObject &obj) const\n {\n-\tif (type_ != Type::Value)\n+\tif (obj.type_ != Type::Value)\n \t\treturn std::nullopt;\n \n-\treturn value_;\n+\treturn obj.value_;\n }\n \n template<>\n-std::optional<Size> YamlObject::get() const\n+std::optional<Size>\n+YamlObject::Getter<Size>::get(const YamlObject &obj) const\n {\n-\tif (type_ != Type::List)\n+\tif (obj.type_ != Type::List)\n \t\treturn std::nullopt;\n \n-\tif (list_.size() != 2)\n+\tif (obj.list_.size() != 2)\n \t\treturn std::nullopt;\n \n-\tauto width = list_[0].value->get<uint32_t>();\n+\tauto width = obj.list_[0].value->get<uint32_t>();\n \tif (!width)\n \t\treturn std::nullopt;\n \n-\tauto height = list_[1].value->get<uint32_t>();\n+\tauto height = obj.list_[1].value->get<uint32_t>();\n \tif (!height)\n \t\treturn std::nullopt;\n \n", "prefixes": [ "02/11" ] }