From patchwork Thu Jan 31 23:47:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 464 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 40F6B60DB8 for ; Fri, 1 Feb 2019 00:47:40 +0100 (CET) Received: from pendragon.ideasonboard.com (85-76-34-136-nat.elisa-mobile.fi [85.76.34.136]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F23DC41; Fri, 1 Feb 2019 00:47:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1548978459; bh=6PJVBEe8jV7SblGMXUXzHMRm8JFa8eyopHb7bgDPGYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r0zacOKv14p8VakAFcJs/C3JMA8oBqVsfaL4Pd0cH4CktrD0Iybdq+w/HOTTciLqs v8bRgMp+wRh2z+wIoKJmVgP1YmL8i0+fTWZu4vPYx+6CJSy6hQdY3V4/l4FZzKWtWa eGRYCcl18e8TpqaC/g52PF0+MLHz2wMOaaGv47Hc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 1 Feb 2019 01:47:17 +0200 Message-Id: <20190131234721.22606-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190131234721.22606-1-laurent.pinchart@ideasonboard.com> References: <20190131234721.22606-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/8] cam: options: Return whether addOption() succeeds or not X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2019 23:47:40 -0000 From: Niklas Söderlund To later extend the options handling to cover subparsing of arguments it will be needed to know if the addition of the option itself was successful or not. The information is already present in addOption() this change just makes it available. Signed-off-by: Niklas Söderlund Signed-off-by: Laurent Pinchart --- src/cam/options.cpp | 11 ++++++----- src/cam/options.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index f48bd1fcf1b4..c13022ce1b84 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -38,7 +38,7 @@ void OptionsBase::clear() template class OptionsBase; -void OptionsParser::addOption(int opt, const char *help, const char *name, +bool OptionsParser::addOption(int opt, const char *help, const char *name, OptionArgument argument, const char *argumentName) { /* @@ -46,18 +46,19 @@ void OptionsParser::addOption(int opt, const char *help, const char *name, * If an argument is accepted, it must be described by argumentName. */ if (!isalnum(opt) && !name) - return; + return false; if (!help || help[0] == '\0') - return; + return false; if (argument != ArgumentNone && !argumentName) - return; + return false; /* Reject duplicate options. */ if (optionsMap_.find(opt) != optionsMap_.end()) - return; + return false; options_.push_back(Option({ opt, name, argument, argumentName, help })); optionsMap_[opt] = &options_.back(); + return true; } OptionsParser::Options OptionsParser::parse(int argc, char **argv) diff --git a/src/cam/options.h b/src/cam/options.h index 2bf1f160f3c0..2272385a0b83 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -49,7 +49,7 @@ public: { }; - void addOption(int opt, const char *help, const char *name = nullptr, + bool addOption(int opt, const char *help, const char *name = nullptr, OptionArgument argument = ArgumentNone, const char *argumentName = nullptr);