From patchwork Mon Feb 13 16:43:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 18279 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 7FB4BBDB13 for ; Mon, 13 Feb 2023 16:43:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AD2FC625E3; Mon, 13 Feb 2023 17:43:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1676306597; bh=c63vt2+H4Ukd1jtYBfbVhBOfkPu8OLZiZBtYZwPlZwg=; h=Date:To:List-Id:List-Post:From:List-Subscribe:List-Unsubscribe: List-Archive:Reply-To:List-Help:Subject:From; b=WejbH/fqLwTnGb1eaRmKMtZEl7/WdlcIwKV/oN84M1bS/v3MuOF7LUHazbBkJ0GU6 dScvLYRDAH9D+gkMsgR2x/90sNWnkUkq0qP82t0Sqjv+DvTwRAg67qzIHW/c6MVtMy IqnpYzTxIZpj5JwjImrY7Y5DVLQY3sJzxEGV79FcJ+/SiInO3mxKeWfsLHZFNAsKCd LYgElndNbDVeh7gcKAnnZILiwioDzy72mj2wqHpWey2zyapMhZr2jn3nDTK/DHcn58 6M3bEhzfHC5Vt1bv4w+1BW1/s+UEPHydap/r7+D+n/nx2Y3msVpttvbu0hfviXAP/1 xZQkpDfR57ukg== Date: Mon, 13 Feb 2023 16:43:06 +0000 To: libcamera-devel@lists.libcamera.org MIME-Version: 1.0 Message-ID: List-Id: List-Post: X-Patchwork-Original-From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze_via_libcamera-devel?= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Precedence: list X-Mailman-Version: 2.1.29 X-BeenThere: libcamera-devel@lists.libcamera.org List-Subscribe: , List-Unsubscribe: , List-Archive: Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= List-Help: Subject: [libcamera-devel] [PATCH v1] apps: return std::optional from StreamKeyValueParser::parseRole() Content-Disposition: inline Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Instead of having bool return type and an out parameter, just use std::optional. Signed-off-by: Barnabás Pőcze --- src/apps/common/stream_options.cpp | 39 ++++++++++-------------------- src/apps/common/stream_options.h | 5 ++-- 2 files changed, 16 insertions(+), 28 deletions(-) -- 2.39.1 diff --git a/src/apps/common/stream_options.cpp b/src/apps/common/stream_options.cpp index 3a5625f5..d3785999 100644 --- a/src/apps/common/stream_options.cpp +++ b/src/apps/common/stream_options.cpp @@ -30,10 +30,8 @@ StreamKeyValueParser::StreamKeyValueParser() KeyValueParser::Options StreamKeyValueParser::parse(const char *arguments) { KeyValueParser::Options options = KeyValueParser::parse(arguments); - StreamRole role; - if (options.valid() && options.isSet("role") && - !parseRole(&role, options)) { + if (options.valid() && options.isSet("role") && !parseRole(options)) { std::cerr << "Unknown stream role " << options["role"].toString() << std::endl; options.invalidate(); @@ -52,13 +50,8 @@ StreamRoles StreamKeyValueParser::roles(const OptionValue &values) StreamRoles roles; for (auto const &value : streamParameters) { - StreamRole role; - /* If role is invalid or not set default to viewfinder. */ - if (!parseRole(&role, value.toKeyValues())) - role = StreamRole::Viewfinder; - - roles.push_back(role); + roles.push_back(parseRole(value.toKeyValues()).value_or(StreamRole::Viewfinder)); } return roles; @@ -108,27 +101,21 @@ int StreamKeyValueParser::updateConfiguration(CameraConfiguration *config, return 0; } -bool StreamKeyValueParser::parseRole(StreamRole *role, - const KeyValueParser::Options &options) +std::optional StreamKeyValueParser::parseRole(const KeyValueParser::Options &options) { if (!options.isSet("role")) - return false; + return {}; std::string name = options["role"].toString(); - if (name == "viewfinder") { - *role = StreamRole::Viewfinder; - return true; - } else if (name == "video") { - *role = StreamRole::VideoRecording; - return true; - } else if (name == "still") { - *role = StreamRole::StillCapture; - return true; - } else if (name == "raw") { - *role = StreamRole::Raw; - return true; - } + if (name == "viewfinder") + return StreamRole::Viewfinder; + else if (name == "video") + return StreamRole::VideoRecording; + else if (name == "still") + return StreamRole::StillCapture; + else if (name == "raw") + return StreamRole::Raw; - return false; + return {}; } diff --git a/src/apps/common/stream_options.h b/src/apps/common/stream_options.h index 35e4e7c0..fe298c84 100644 --- a/src/apps/common/stream_options.h +++ b/src/apps/common/stream_options.h @@ -7,6 +7,8 @@ #pragma once +#include + #include #include "options.h" @@ -23,6 +25,5 @@ public: const OptionValue &values); private: - static bool parseRole(libcamera::StreamRole *role, - const KeyValueParser::Options &options); + static std::optional parseRole(const KeyValueParser::Options &options); };