From patchwork Wed Aug 3 09:15:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 16925 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 75536BE173 for ; Wed, 3 Aug 2022 09:15:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E9F0D63315; Wed, 3 Aug 2022 11:15:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659518110; bh=KJAK9BXM4hRThzqDTiX2ell2rwDea8AAf89/an66rYg=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=cAjxAkZniPLlrRbe2gp5zp8UoYD/wDQpZ0Btt1xQLCdEXQMlnmsd+glE3j0hU1VsH uQ7REEuJ6U2ori9fwuR6GBYy3OaH+HqH/lGhieHwyUDFkP1F1VmMTaU8HV0RzuOMyz hr3mF9IypwGoKO5UYbnZAp9cwBwdSwHXUCrqbcwvpbglxu1YL/PISAP9/6MVfUcBiu 52ACtQHh/MyyWtU60qUZjtztTO9rpL6rq1S6XXlgeDcb8p6PxBXpvUbjgsmdYkM5Yj smO55aukjkzt+Ry38N5Hktjmty+NYz65qzq33X8QX0+y97ZISQhs9foZP5wDxXNOp1 y+3s1v61YY1FQ== Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 313CD603EF for ; Wed, 3 Aug 2022 11:15:10 +0200 (CEST) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id 04A201BF20C; Wed, 3 Aug 2022 09:15:07 +0000 (UTC) To: libcamera-devel@lists.libcamera.org Date: Wed, 3 Aug 2022 11:15:02 +0200 Message-Id: <20220803091502.17280-1-jacopo@jmondi.org> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: yaml_parser: Drop std::optional<> from getList() 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: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The YamlParser::getList() function returns an std::optional>. The obvious (and only) gain in using std::optional<> is to be able to check the validity of the returned value with the dereference operator. However, usage of std::vector as the std::optional<> template argument causes issues with the usage of utils::defopt with gcc8, as the it fails to construct a vector with defopt: /usr/include/c++/8/optional:1267:8: error: call of overloaded ‘vector(const libcamera::utils::details::defopt_t&)’ is ambiguous : static_cast<_Tp>(std::forward<_Up>(__u)) As the added value of std::optional<> is debatable when used in getList(), drop it and return an std::vector directly. The few characters more that have to be typed to check the validity of the return value (value.empty() in place of just !value) are compensated by the shorter assignment statement (value = getList() in place of value = getList.value_or(utils::defopt)) Reported-by: https://buildbot.libcamera.org/#/builders/6/builds/436 Signed-off-by: Jacopo Mondi --- include/libcamera/internal/yaml_parser.h | 2 +- src/ipa/raspberrypi/controller/rpi/agc.cpp | 10 +++++----- src/ipa/rkisp1/algorithms/gsl.cpp | 8 ++++---- src/ipa/rkisp1/algorithms/lsc.cpp | 4 ++-- src/libcamera/yaml_parser.cpp | 18 +++++++++--------- test/yaml-parser.cpp | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) -- 2.37.1 diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 5ba777d364fa..6d04c556f9b1 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -197,7 +197,7 @@ public: #else template #endif - std::optional> getList() const; + std::vector getList() const; DictAdapter asDict() const { return DictAdapter{ list_ }; } ListAdapter asList() const { return ListAdapter{ list_ }; } diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index bd54a639d637..bb15d3d84186 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -74,16 +74,16 @@ readMeteringModes(std::map &metering_modes, int AgcExposureMode::read(const libcamera::YamlObject ¶ms) { - auto value = params["shutter"].getList(); - if (!value) + std::vector value = params["shutter"].getList(); + if (value.empty()) return -EINVAL; - std::transform(value->begin(), value->end(), std::back_inserter(shutter), + std::transform(value.begin(), value.end(), std::back_inserter(shutter), [](double v) { return v * 1us; }); value = params["gain"].getList(); - if (!value) + if (value.empty()) return -EINVAL; - gain = std::move(*value); + gain = std::move(value); if (shutter.size() < 2 || gain.size() < 2) { LOG(RPiAgc, Error) diff --git a/src/ipa/rkisp1/algorithms/gsl.cpp b/src/ipa/rkisp1/algorithms/gsl.cpp index 2fd1a23d3a9b..0cff1b77b058 100644 --- a/src/ipa/rkisp1/algorithms/gsl.cpp +++ b/src/ipa/rkisp1/algorithms/gsl.cpp @@ -60,7 +60,7 @@ int GammaSensorLinearization::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData) { std::vector xIntervals = - tuningData["x-intervals"].getList().value_or(utils::defopt); + tuningData["x-intervals"].getList(); if (xIntervals.size() != kDegammaXIntervals) { LOG(RkISP1Gsl, Error) << "Invalid 'x' coordinates: expected " @@ -84,7 +84,7 @@ int GammaSensorLinearization::init([[maybe_unused]] IPAContext &context, return -EINVAL; } - curveYr_ = yObject["red"].getList().value_or(utils::defopt); + curveYr_ = yObject["red"].getList(); if (curveYr_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) { LOG(RkISP1Gsl, Error) << "Invalid 'y:red' coordinates: expected " @@ -93,7 +93,7 @@ int GammaSensorLinearization::init([[maybe_unused]] IPAContext &context, return -EINVAL; } - curveYg_ = yObject["green"].getList().value_or(utils::defopt); + curveYg_ = yObject["green"].getList(); if (curveYg_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) { LOG(RkISP1Gsl, Error) << "Invalid 'y:green' coordinates: expected " @@ -102,7 +102,7 @@ int GammaSensorLinearization::init([[maybe_unused]] IPAContext &context, return -EINVAL; } - curveYb_ = yObject["blue"].getList().value_or(utils::defopt); + curveYb_ = yObject["blue"].getList(); if (curveYb_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) { LOG(RkISP1Gsl, Error) << "Invalid 'y:blue' coordinates: expected " diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp index 05c8c0dab5c8..d1a4332c9089 100644 --- a/src/ipa/rkisp1/algorithms/lsc.cpp +++ b/src/ipa/rkisp1/algorithms/lsc.cpp @@ -43,7 +43,7 @@ static std::vector parseSizes(const YamlObject &tuningData, const char *prop) { std::vector sizes = - tuningData[prop].getList().value_or(utils::defopt); + tuningData[prop].getList(); if (sizes.size() != RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE) { LOG(RkISP1Lsc, Error) << "Invalid '" << prop << "' values: expected " @@ -76,7 +76,7 @@ static std::vector parseTable(const YamlObject &tuningData, RKISP1_CIF_ISP_LSC_SAMPLES_MAX * RKISP1_CIF_ISP_LSC_SAMPLES_MAX; std::vector table = - tuningData[prop].getList().value_or(utils::defopt); + tuningData[prop].getList(); if (table.size() != kLscNumSamples) { LOG(RkISP1Lsc, Error) << "Invalid '" << prop << "' values: expected " diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 84cb57d6de83..d422e0811fa7 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -316,7 +316,7 @@ template || std::is_same_v || std::is_same_v> *> -std::optional> YamlObject::getList() const +std::vector YamlObject::getList() const { if (type_ != Type::List) return {}; @@ -334,14 +334,14 @@ std::optional> YamlObject::getList() const return values; } -template std::optional> YamlObject::getList() const; -template std::optional> YamlObject::getList() const; -template std::optional> YamlObject::getList() const; -template std::optional> YamlObject::getList() const; -template std::optional> YamlObject::getList() const; -template std::optional> YamlObject::getList() const; -template std::optional> YamlObject::getList() const; -template std::optional> YamlObject::getList() const; +template std::vector YamlObject::getList() const; +template std::vector YamlObject::getList() const; +template std::vector YamlObject::getList() const; +template std::vector YamlObject::getList() const; +template std::vector YamlObject::getList() const; +template std::vector YamlObject::getList() const; +template std::vector YamlObject::getList() const; +template std::vector YamlObject::getList() const; #endif /* __DOXYGEN__ */ diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 93ba88b8bcd5..e25944e7f6b8 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -530,7 +530,7 @@ protected: } const auto &values = firstElement.getList(); - if (!values || values->size() != 2 || (*values)[0] != 1 || (*values)[1] != 2) { + if (values.empty() || values.size() != 2 || values[0] != 1 || values[1] != 2) { cerr << "getList() failed to return correct vector" << std::endl; return TestFail; }