[{"id":18115,"web_url":"https://patchwork.libcamera.org/comment/18115/","msgid":"<04a18b22-8217-d6dc-ddfa-660a85dde395@ideasonboard.com>","date":"2021-07-12T13:31:54","subject":"Re: [libcamera-devel] [PATCH 05/30] cam: options: Add optionName()\n\tfunction to Option structure","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"On 07/07/2021 03:19, Laurent Pinchart wrote:\n> Add an Option::optionName() function that returns a string describing\n> the option name, with leading dashes. As a result,\n> OptionsParser::parseValueError() function becomes a single-line function\n> and can be inlined in its caller.\n> \n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/cam/options.cpp | 32 ++++++++++++++++++--------------\n>  src/cam/options.h   |  2 --\n>  2 files changed, 18 insertions(+), 16 deletions(-)\n> \n> diff --git a/src/cam/options.cpp b/src/cam/options.cpp\n> index da218c4644d3..2f71860d0466 100644\n> --- a/src/cam/options.cpp\n> +++ b/src/cam/options.cpp\n> @@ -100,6 +100,7 @@ struct Option {\n>  \tbool hasShortOption() const { return isalnum(opt); }\n>  \tbool hasLongOption() const { return name != nullptr; }\n>  \tconst char *typeName() const;\n> +\tstd::string optionName() const;\n>  };\n>  \n>  /**\n> @@ -125,6 +126,20 @@ const char *Option::typeName() const\n>  \treturn \"unknown\";\n>  }\n>  \n> +/**\n> + * \\brief Retrieve a string describing the option name, with leading dashes\n> + * \\return A string describing the option name, as a long option identifier\n> + * (double dash) if the option has a name, or a short option identifier (single\n> + * dash) otherwise\n> + */\n> +std::string Option::optionName() const\n> +{\n> +\tif (name)\n> +\t\treturn \"--\" + std::string(name);\n> +\telse\n> +\t\treturn \"-\" + std::string(1, opt);\n> +}\n> +\n>  /* -----------------------------------------------------------------------------\n>   * OptionBase<T>\n>   */\n> @@ -866,7 +881,9 @@ OptionsParser::Options OptionsParser::parse(int argc, char **argv)\n>  \n>  \t\tconst Option &option = *optionsMap_[c];\n>  \t\tif (!options.parseValue(c, option, optarg)) {\n> -\t\t\tparseValueError(option);\n> +\t\t\tstd::cerr << \"Can't parse \" << option.typeName()\n> +\t\t\t\t  << \" argument for option \" << option.optionName()\n> +\t\t\t\t  << std::endl;\n>  \t\t\tusage();\n>  \t\t\treturn options;\n>  \t\t}\n> @@ -953,16 +970,3 @@ void OptionsParser::usage()\n>  \t\t\toption.keyValueParser->usage(indent);\n>  \t}\n>  }\n> -\n> -void OptionsParser::parseValueError(const Option &option)\n> -{\n> -\tstd::string optionName;\n> -\n> -\tif (option.name)\n> -\t\toptionName = \"--\" + std::string(option.name);\n> -\telse\n> -\t\toptionName = \"-\" + std::string(1, option.opt);\n> -\n> -\tstd::cerr << \"Can't parse \" << option.typeName()\n> -\t\t  << \" argument for option \" << optionName << std::endl;\n> -}\n> diff --git a/src/cam/options.h b/src/cam/options.h\n> index a3b18bb6c4ea..0b8bb172d184 100644\n> --- a/src/cam/options.h\n> +++ b/src/cam/options.h\n> @@ -95,8 +95,6 @@ public:\n>  \tvoid usage();\n>  \n>  private:\n> -\tvoid parseValueError(const Option &option);\n> -\n>  \tstd::list<Option> options_;\n>  \tstd::map<unsigned int, Option *> optionsMap_;\n>  };\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 12FCAC3225\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 Jul 2021 13:31:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 96A1068524;\n\tMon, 12 Jul 2021 15:31:57 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7C5F668513\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Jul 2021 15:31:56 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 241FCCC;\n\tMon, 12 Jul 2021 15:31:56 +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=\"X/mE1A/p\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1626096716;\n\tbh=+eDuwT6wykP3/TlUleHH2c/1GfK7f8xiPiUJvf12T1E=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=X/mE1A/poOKYD4qOSccC26oExrFgztGQvGIT6iVxSo7K9auCuS5Pliba8OAkGJaBR\n\tNN1av80pl763jISFOPZqHGonbao5bXuuDlIE1cHapD4ZqIe8qBmEIEDWUG7Rfc7BGX\n\tP3L8XInPYbxuLG83mZSmcUx0lPmgpwMA9fmLQjDE=","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20210707021941.20804-1-laurent.pinchart@ideasonboard.com>\n\t<20210707021941.20804-6-laurent.pinchart@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<04a18b22-8217-d6dc-ddfa-660a85dde395@ideasonboard.com>","Date":"Mon, 12 Jul 2021 14:31:54 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.11.0","MIME-Version":"1.0","In-Reply-To":"<20210707021941.20804-6-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH 05/30] cam: options: Add optionName()\n\tfunction to Option structure","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>"}}]