[libcamera-devel,RFC,1/4] cam: options: Create own enum for OptionValue types

Message ID 20190322015349.14934-2-niklas.soderlund@ragnatech.se
State Superseded
Headers show
Series
  • cam: Extend to support configuration of multiple streams
Related show

Commit Message

Niklas Söderlund March 22, 2019, 1:53 a.m. UTC
In preparation to add support specifying the same option multiple times
create a own enum for the OptionValue types as it will diverge from the
one shared one.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/cam/options.cpp | 16 ++++++++--------
 src/cam/options.h   | 11 +++++++++--
 2 files changed, 17 insertions(+), 10 deletions(-)

Comments

Laurent Pinchart March 23, 2019, 2:23 p.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Fri, Mar 22, 2019 at 02:53:46AM +0100, Niklas Söderlund wrote:
> In preparation to add support specifying the same option multiple times

"In preparation for support of multiple instances of the same option,"

> create a own enum for the OptionValue types as it will diverge from the

Did you mean "a separate enum" ?

> one shared one.

one shared one ?

> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

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

> ---
>  src/cam/options.cpp | 16 ++++++++--------
>  src/cam/options.h   | 11 +++++++++--
>  2 files changed, 17 insertions(+), 10 deletions(-)
> 
> diff --git a/src/cam/options.cpp b/src/cam/options.cpp
> index 655aa36bb9c93b85..497833397d894f82 100644
> --- a/src/cam/options.cpp
> +++ b/src/cam/options.cpp
> @@ -248,27 +248,27 @@ void KeyValueParser::usage(int indent)
>   */
>  
>  OptionValue::OptionValue()
> -	: type_(OptionNone)
> +	: type_(ValueNone)
>  {
>  }
>  
>  OptionValue::OptionValue(int value)
> -	: type_(OptionInteger), integer_(value)
> +	: type_(ValueInteger), integer_(value)
>  {
>  }
>  
>  OptionValue::OptionValue(const char *value)
> -	: type_(OptionString), string_(value)
> +	: type_(ValueString), string_(value)
>  {
>  }
>  
>  OptionValue::OptionValue(const std::string &value)
> -	: type_(OptionString), string_(value)
> +	: type_(ValueString), string_(value)
>  {
>  }
>  
>  OptionValue::OptionValue(const KeyValueParser::Options &value)
> -	: type_(OptionKeyValue), keyValues_(value)
> +	: type_(ValueKeyValue), keyValues_(value)
>  {
>  }
>  
> @@ -289,7 +289,7 @@ OptionValue::operator KeyValueParser::Options() const
>  
>  int OptionValue::toInteger() const
>  {
> -	if (type_ != OptionInteger)
> +	if (type_ != ValueInteger)
>  		return 0;
>  
>  	return integer_;
> @@ -297,7 +297,7 @@ int OptionValue::toInteger() const
>  
>  std::string OptionValue::toString() const
>  {
> -	if (type_ != OptionString)
> +	if (type_ != ValueString)
>  		return std::string();
>  
>  	return string_;
> @@ -305,7 +305,7 @@ std::string OptionValue::toString() const
>  
>  KeyValueParser::Options OptionValue::toKeyValues() const
>  {
> -	if (type_ != OptionKeyValue)
> +	if (type_ != ValueKeyValue)
>  		return KeyValueParser::Options();
>  
>  	return keyValues_;
> diff --git a/src/cam/options.h b/src/cam/options.h
> index 745f4a4a3a433f9e..b33a90fc6058febf 100644
> --- a/src/cam/options.h
> +++ b/src/cam/options.h
> @@ -79,13 +79,20 @@ private:
>  class OptionValue
>  {
>  public:
> +	enum ValueType {
> +		ValueNone,
> +		ValueInteger,
> +		ValueString,
> +		ValueKeyValue,
> +	};
> +
>  	OptionValue();
>  	OptionValue(int value);
>  	OptionValue(const char *value);
>  	OptionValue(const std::string &value);
>  	OptionValue(const KeyValueParser::Options &value);
>  
> -	OptionType type() const { return type_; }
> +	ValueType type() const { return type_; }
>  
>  	operator int() const;
>  	operator std::string() const;
> @@ -96,7 +103,7 @@ public:
>  	KeyValueParser::Options toKeyValues() const;
>  
>  private:
> -	OptionType type_;
> +	ValueType type_;
>  	int integer_;
>  	std::string string_;
>  	KeyValueParser::Options keyValues_;

Patch

diff --git a/src/cam/options.cpp b/src/cam/options.cpp
index 655aa36bb9c93b85..497833397d894f82 100644
--- a/src/cam/options.cpp
+++ b/src/cam/options.cpp
@@ -248,27 +248,27 @@  void KeyValueParser::usage(int indent)
  */
 
 OptionValue::OptionValue()
-	: type_(OptionNone)
+	: type_(ValueNone)
 {
 }
 
 OptionValue::OptionValue(int value)
-	: type_(OptionInteger), integer_(value)
+	: type_(ValueInteger), integer_(value)
 {
 }
 
 OptionValue::OptionValue(const char *value)
-	: type_(OptionString), string_(value)
+	: type_(ValueString), string_(value)
 {
 }
 
 OptionValue::OptionValue(const std::string &value)
-	: type_(OptionString), string_(value)
+	: type_(ValueString), string_(value)
 {
 }
 
 OptionValue::OptionValue(const KeyValueParser::Options &value)
-	: type_(OptionKeyValue), keyValues_(value)
+	: type_(ValueKeyValue), keyValues_(value)
 {
 }
 
@@ -289,7 +289,7 @@  OptionValue::operator KeyValueParser::Options() const
 
 int OptionValue::toInteger() const
 {
-	if (type_ != OptionInteger)
+	if (type_ != ValueInteger)
 		return 0;
 
 	return integer_;
@@ -297,7 +297,7 @@  int OptionValue::toInteger() const
 
 std::string OptionValue::toString() const
 {
-	if (type_ != OptionString)
+	if (type_ != ValueString)
 		return std::string();
 
 	return string_;
@@ -305,7 +305,7 @@  std::string OptionValue::toString() const
 
 KeyValueParser::Options OptionValue::toKeyValues() const
 {
-	if (type_ != OptionKeyValue)
+	if (type_ != ValueKeyValue)
 		return KeyValueParser::Options();
 
 	return keyValues_;
diff --git a/src/cam/options.h b/src/cam/options.h
index 745f4a4a3a433f9e..b33a90fc6058febf 100644
--- a/src/cam/options.h
+++ b/src/cam/options.h
@@ -79,13 +79,20 @@  private:
 class OptionValue
 {
 public:
+	enum ValueType {
+		ValueNone,
+		ValueInteger,
+		ValueString,
+		ValueKeyValue,
+	};
+
 	OptionValue();
 	OptionValue(int value);
 	OptionValue(const char *value);
 	OptionValue(const std::string &value);
 	OptionValue(const KeyValueParser::Options &value);
 
-	OptionType type() const { return type_; }
+	ValueType type() const { return type_; }
 
 	operator int() const;
 	operator std::string() const;
@@ -96,7 +103,7 @@  public:
 	KeyValueParser::Options toKeyValues() const;
 
 private:
-	OptionType type_;
+	ValueType type_;
 	int integer_;
 	std::string string_;
 	KeyValueParser::Options keyValues_;