[{"id":34209,"web_url":"https://patchwork.libcamera.org/comment/34209/","msgid":"<174708579857.7542.11764357279065392155@pyrite.rasen.tech>","date":"2025-05-12T21:36:38","subject":"Re: [PATCH 7/8] libcamera: vector: Add explicit cast and data\n\taccessor","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-04-11 15:04:14)\n> When dealing with Vectors it is useful to be able to cast the to a\n\ns/the//\n\n> different underlying type or to access the underlying data.\n> \n> Add functions for that.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/vector.h | 11 +++++++++++\n>  src/libcamera/vector.cpp            | 18 ++++++++++++++++++\n>  2 files changed, 29 insertions(+)\n> \n> diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h\n> index 16b6aef0b38f..63da55019aef 100644\n> --- a/include/libcamera/internal/vector.h\n> +++ b/include/libcamera/internal/vector.h\n> @@ -63,6 +63,17 @@ public:\n>                 return data_[i];\n>         }\n>  \n> +       template<typename T2>\n> +       explicit operator Vector<T2, Rows>() const\n> +       {\n> +               Vector<T2, Rows> ret;\n> +               for (unsigned int i = 0; i < Rows; i++)\n> +                       ret[i] = static_cast<T2>(data_[i]);\n> +               return ret;\n> +       }\n> +\n> +       constexpr Span<const T, Rows> data() const { return data_; }\n> +\n>         constexpr Vector<T, Rows> operator-() const\n>         {\n>                 Vector<T, Rows> ret;\n> diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp\n> index 4dad1b9001c5..bb89f0de7c4f 100644\n> --- a/src/libcamera/vector.cpp\n> +++ b/src/libcamera/vector.cpp\n> @@ -64,6 +64,24 @@ LOG_DEFINE_CATEGORY(Vector)\n>   * \\copydoc Vector::operator[](size_t i) const\n>   */\n>  \n> +/**\n> + * \\fn Vector::data()\n> + * \\brief Access the vector data\n> + *\n> + * Access the contents of the vector as linear array of values.\n> + *\n> + * \\return A span referencing the vector data as a linear array\n> + */\n> +\n> +/**\n> + * \\fn Vector::operator Vector<T2, Rows>()\n> + * \\brief Cast to a different underlying type\n> + *\n> + * Cast the vector to a different underlying type using static_cast().\n> + *\n> + * \\return A vector of type T2\n> + */\n> +\n>  /**\n>   * \\fn Vector::operator-() const\n>   * \\brief Negate a Vector by negating both all of its coordinates\n> -- \n> 2.43.0\n>","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 F4125C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 May 2025 21:36:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2E55268B50;\n\tMon, 12 May 2025 23:36:43 +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 967F6617C7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 May 2025 23:36:41 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2001:861:3a80:3300:4f2f:8c2c:b3ef:17d4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5D6A28CB;\n\tMon, 12 May 2025 23:36:26 +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=\"P2+HIo8K\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1747085786;\n\tbh=viXvOPIW4WCCFw1PkmFOb/eVVKeJJ9hQeYTNy2Va0qw=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=P2+HIo8KjDKqB1T6ooy/YdhpUrgNi5DK+8Xybb1nrufQO2iHu1Dq3cZBFfGBSUKju\n\t9org5Z5H8MCsohOgzDZu1wh4Teea4Vn7GlBeCxnJ8eO3zHmK6Hoavq4IJ1Q+l3ukB5\n\tbVdY3pYFC0w4jkZoY7xJP446hgt8YZhcPvHSeHRk=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250411130423.2164577-8-stefan.klug@ideasonboard.com>","References":"<20250411130423.2164577-1-stefan.klug@ideasonboard.com>\n\t<20250411130423.2164577-8-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH 7/8] libcamera: vector: Add explicit cast and data\n\taccessor","From":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 12 May 2025 23:36:38 +0200","Message-ID":"<174708579857.7542.11764357279065392155@pyrite.rasen.tech>","User-Agent":"alot/0.0.0","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>"}}]