[libcamera-devel,3/6] cam: options: return if addOption() succeeds or not

Message ID 20190128004109.25860-4-niklas.soderlund@ragnatech.se
State Superseded
Headers show
Series
  • cam: add --format option to configure a stream
Related show

Commit Message

Niklas Söderlund Jan. 28, 2019, 12:41 a.m. UTC
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 <niklas.soderlund@ragnatech.se>
---
 src/cam/options.cpp | 11 ++++++-----
 src/cam/options.h   |  2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)

Comments

Laurent Pinchart Jan. 31, 2019, 10:07 a.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Mon, Jan 28, 2019 at 01:41:06AM +0100, Niklas Söderlund wrote:
> 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 <niklas.soderlund@ragnatech.se>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  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 b24964a8ce413a85..c9ca017b4cf3fa3d 100644
> --- a/src/cam/options.cpp
> +++ b/src/cam/options.cpp
> @@ -12,7 +12,7 @@
>  
>  #include "options.h"
>  
> -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)
>  {
>  	/*
> @@ -20,18 +20,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 a08bfea1ba74c96b..dfb7fcc9f6fa3324 100644
> --- a/src/cam/options.h
> +++ b/src/cam/options.h
> @@ -38,7 +38,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);
>  
> -- 
> 2.20.1
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/cam/options.cpp b/src/cam/options.cpp
index b24964a8ce413a85..c9ca017b4cf3fa3d 100644
--- a/src/cam/options.cpp
+++ b/src/cam/options.cpp
@@ -12,7 +12,7 @@ 
 
 #include "options.h"
 
-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)
 {
 	/*
@@ -20,18 +20,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 a08bfea1ba74c96b..dfb7fcc9f6fa3324 100644
--- a/src/cam/options.h
+++ b/src/cam/options.h
@@ -38,7 +38,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);