From patchwork Sun Jul 25 17:18:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13115 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 48A71C322D for ; Sun, 25 Jul 2021 17:18:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 019C6687C6; Sun, 25 Jul 2021 19:18:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="WNRayWby"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 292676877B for ; Sun, 25 Jul 2021 19:18:38 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C47044A8 for ; Sun, 25 Jul 2021 19:18:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1627233517; bh=FxQnIzmjXVgGIX1UNVwGfFOL7j8CJVND9ab+jOAYod0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WNRayWbyjWhqvrFfWrrI7efJXb455ySnE/+SKCMaP+QCnIVMDhkLdKK/ELP/f5wkc 4qcTfjUN15Zw9Gbb+sCcYRyYXRUx4QS/tTX9lK8kW6z86vdsVEHb01T3J1xev7W7xk KMAGG+n9zHNkPe8UZxVPDH/GeS/qM4ABTKuhDO04= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 25 Jul 2021 20:18:26 +0300 Message-Id: <20210725171827.23643-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210725171827.23643-1-laurent.pinchart@ideasonboard.com> References: <20210725171827.23643-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/5] libcamera: file: Use Flags<> class for open flags 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Use the newly introduced Flags<> class to store a bitfield of File::OpenMode in a type-safe way. The existing File::OpenMode enum is renamed to File::OpenModeFlag to free the File::OpenMode for the Flags<> type alias. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Changes since v1: - Don't enable bitwise operators on File::OpenMode --- include/libcamera/base/file.h | 4 +++- src/libcamera/base/file.cpp | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/libcamera/base/file.h b/include/libcamera/base/file.h index 452a658b409f..eebb24024025 100644 --- a/include/libcamera/base/file.h +++ b/include/libcamera/base/file.h @@ -30,13 +30,15 @@ public: using MapFlags = Flags; - enum OpenMode { + enum OpenModeFlag { NotOpen = 0, ReadOnly = (1 << 0), WriteOnly = (1 << 1), ReadWrite = ReadOnly | WriteOnly, }; + using OpenMode = Flags; + File(const std::string &name); File(); ~File(); diff --git a/src/libcamera/base/file.cpp b/src/libcamera/base/file.cpp index e180c5479098..0860457421a1 100644 --- a/src/libcamera/base/file.cpp +++ b/src/libcamera/base/file.cpp @@ -58,7 +58,7 @@ LOG_DEFINE_CATEGORY(File) */ /** - * \enum File::OpenMode + * \enum File::OpenModeFlag * \brief Mode in which a file is opened * \var File::NotOpen * \brief The file is not open @@ -70,6 +70,11 @@ LOG_DEFINE_CATEGORY(File) * \brief The file is open for reading and writing */ +/** + * \typedef File::OpenMode + * \brief An OR combination of File::OpenModeFlag values + */ + /** * \brief Construct a File to represent the file \a name * \param[in] name The file name @@ -168,7 +173,7 @@ bool File::open(File::OpenMode mode) return false; } - int flags = (mode & ReadWrite) - 1; + int flags = static_cast(mode & ReadWrite) - 1; if (mode & WriteOnly) flags |= O_CREAT;