From patchwork Mon Apr 18 12:19:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 15683 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A6F79C3256 for ; Mon, 18 Apr 2022 12:19:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0C65565640; Mon, 18 Apr 2022 14:19:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1650284357; bh=IHRbArZENtCk/9GGSIqukwg7vP9eUMyTjAYQ9udG8SA=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=PkqEajs3chlr8+cFBwh8EwFtsHaKma/RAGopgM/TRh0vS+srgmRBPtQNN9K6DDS7n kwPL1mkzcczVioSkCIW68LrtQyyAWjQd52El2LTDhRp/FisIkK8pEAB2gyx8jQJSq6 EnWqaT+5TUx5KBY5OAcFdmb53bdL++cuKHRJZUJsn9xzrbhcY+3lx1VIS73mkhyZR9 uDfS82Y0PCCBy+NRjzVoVzFt/PhhS8Clb6ce9zU9GA00OK1W6D+npN+96IYsTFZE2E 31vZ+JKYn/hyo/X0EeoV5kUVvN2vmpDlcNroN9uBVi+yUOxGI+84XXdmaknp6cebIH n9iX7z3uGcKWA== Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D73956563F for ; Mon, 18 Apr 2022 14:19:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="fp6Tp7+w"; dkim-atps=neutral Received: by mail-pl1-x629.google.com with SMTP id d15so12183425pll.10 for ; Mon, 18 Apr 2022 05:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tvhcZdLPX+KLjwsmlR1o9jk+2FLwanNO6rI9kHfyUs8=; b=fp6Tp7+wDisIcC1ixjc8zvdTUureixq6DOMU6lwBVsRc8KgCCaf19A4rElEfr/5JZj Yfb/x9iJMNhfKBI00+0bvyLvuke8E6eIh7sT6l5MEtFaCoLKnSiP2SwnX3tGQc4FHZcI amAUOLJoc4PBq4Ky2GxjFYWQFh2jOAn8dCYtg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tvhcZdLPX+KLjwsmlR1o9jk+2FLwanNO6rI9kHfyUs8=; b=l/IiS87Lso+t3QM3Zt3+s507jMAaaYMaUtbIvwpgveTY/gCj9SP1pxPkzBnuif0Zf7 EIxYx5Gqm/Z/zd/cJ04C8FdlFP5l60CjKcG1Xh2OU7UYP9Xv4OzRn0dD0xUNo61zMKuM XH7+ns6ZxV5dUpYqixkfGOPYm5/QLZmEa4edsz+3LFbOKYhVr2y3k0gmHbCKUBfb6H1r ysyY1owyDCN6i3yd4c+q7U1fRW3LPJfcBxX7o9FdM+Uj57neJKWjB/8F1W/L1Pcq89Dp gJWzT1bPgnxxEOHLoEty7ZS3+836KbeagB2QhfPMbpV7YvoF5tx62du92ds2N+T7Tsvs C5Mw== X-Gm-Message-State: AOAM532uHv1JBKpJDcrOerACG/dUOf4O1A+eVClqPVaWbJ9pwOPsDTkl XvhNVLtPlAcuieyHVglORWO/LzRtSCCPTA== X-Google-Smtp-Source: ABdhPJzRHXPAZVMZn1eYVlvv3LFjrYdKI2T8/Hzzd5+cBN0AmamkMRR9Xt0K1GhrnS8MqSDtCvd9fA== X-Received: by 2002:a17:902:bc43:b0:158:a253:b4f1 with SMTP id t3-20020a170902bc4300b00158a253b4f1mr10463899plz.10.1650284353142; Mon, 18 Apr 2022 05:19:13 -0700 (PDT) Received: from localhost ([2401:fa00:1:17:9775:a6e9:7655:6686]) by smtp.gmail.com with UTF8SMTPSA id n14-20020a17090a394e00b001c670d67b8esm12996230pjf.32.2022.04.18.05.19.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Apr 2022 05:19:12 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 18 Apr 2022 20:19:09 +0800 Message-Id: <20220418121909.470519-1-hanlinchen@chromium.org> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] libcamera: Add operator<< for classes in geometry X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Han-Lin Chen via libcamera-devel From: Hanlin Chen Reply-To: Han-Lin Chen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add operator<< for geometry classes for easier logging. Signed-off-by: Han-Lin Chen Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/geometry.h | 8 +++++ src/libcamera/geometry.cpp | 57 +++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h index 7838b679..d4a144bc 100644 --- a/include/libcamera/geometry.h +++ b/include/libcamera/geometry.h @@ -46,6 +46,8 @@ static inline bool operator!=(const Point &lhs, const Point &rhs) return !(lhs == rhs); } +std::ostream &operator<<(std::ostream &out, const Point &p); + class Size { public: @@ -192,6 +194,8 @@ static inline bool operator>=(const Size &lhs, const Size &rhs) return !(lhs < rhs); } +std::ostream &operator<<(std::ostream &out, const Size &s); + class SizeRange { public: @@ -232,6 +236,8 @@ static inline bool operator!=(const SizeRange &lhs, const SizeRange &rhs) return !(lhs == rhs); } +std::ostream &operator<<(std::ostream &out, const SizeRange &sr); + class Rectangle { public: @@ -291,4 +297,6 @@ static inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs) return !(lhs == rhs); } +std::ostream &operator<<(std::ostream &out, const Rectangle &r); + } /* namespace libcamera */ diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp index cb3c2de1..a0696c51 100644 --- a/src/libcamera/geometry.cpp +++ b/src/libcamera/geometry.cpp @@ -56,8 +56,7 @@ namespace libcamera { const std::string Point::toString() const { std::stringstream ss; - - ss << "(" << x << "," << y << ")"; + ss << *this; return ss.str(); } @@ -83,6 +82,16 @@ bool operator==(const Point &lhs, const Point &rhs) * \return True if the two points are not equal, false otherwise */ +/** + * \brief Insert operation for Point with ostream + * \return The input std::ostream + */ +std::ostream &operator<<(std::ostream &out, const Point &p) +{ + out << "(" << p.x << ", " << p.y << ")"; + return out; +} + /** * \struct Size * \brief Describe a two-dimensional size @@ -124,7 +133,10 @@ bool operator==(const Point &lhs, const Point &rhs) */ const std::string Size::toString() const { - return std::to_string(width) + "x" + std::to_string(height); + std::stringstream ss; + ss << *this; + + return ss.str(); } /** @@ -428,6 +440,16 @@ bool operator<(const Size &lhs, const Size &rhs) * \sa bool operator<(const Size &lhs, const Size &rhs) */ +/** + * \brief Insert operation for Size with ostream + * \return The input std::ostream + */ +std::ostream &operator<<(std::ostream &out, const Size &s) +{ + out << s.width << "x" << s.height; + return out; +} + /** * \struct SizeRange * \brief Describe a range of sizes @@ -528,9 +550,7 @@ bool SizeRange::contains(const Size &size) const std::string SizeRange::toString() const { std::stringstream ss; - - ss << "(" << min.toString() << ")-(" << max.toString() << ")/(+" - << hStep << ",+" << vStep << ")"; + ss << *this; return ss.str(); } @@ -550,6 +570,18 @@ bool operator==(const SizeRange &lhs, const SizeRange &rhs) * \return True if the two size ranges are not equal, false otherwise */ +/** + * \brief Insert operation for SizeRange with ostream + * \return The input std::ostream + */ +std::ostream &operator<<(std::ostream &out, const SizeRange &sr) +{ + out << "(" << sr.min << ")-(" << sr.max << ")/(+" + << sr.hStep << ",+" << sr.vStep << ")"; + + return out; +} + /** * \struct Rectangle * \brief Describe a rectangle's position and dimensions @@ -624,8 +656,7 @@ bool operator==(const SizeRange &lhs, const SizeRange &rhs) const std::string Rectangle::toString() const { std::stringstream ss; - - ss << "(" << x << "x" << y << ")/" << width << "x" << height; + ss << *this; return ss.str(); } @@ -796,4 +827,14 @@ bool operator==(const Rectangle &lhs, const Rectangle &rhs) * \return True if the two rectangles are not equal, false otherwise */ +/** + * \brief Insert operation for Rectangle with ostream + * \return The input std::ostream + */ +std::ostream &operator<<(std::ostream &out, const Rectangle &r) +{ + out << "(" << r.x << ", " << r.y << ")/" << r.width << "x" << r.height; + return out; +} + } /* namespace libcamera */