[libcamera-devel,v2,04/14] libcamera: controls: Add comparison operators for ControlValue

Message ID 20191012184407.31684-5-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Use ControlList for both libcamera and V4L2 controls
Related show

Commit Message

Laurent Pinchart Oct. 12, 2019, 6:43 p.m. UTC
Add equality and non equality comparison operators for the ControlValue
class. This simplifies code that deals with control values.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 include/libcamera/controls.h |  6 ++++++
 src/libcamera/controls.cpp   | 27 +++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

Comments

Niklas Söderlund Oct. 13, 2019, 3:28 p.m. UTC | #1
Hi Laurent,

Thanks for your work.

On 2019-10-12 21:43:57 +0300, Laurent Pinchart wrote:
> Add equality and non equality comparison operators for the ControlValue
> class. This simplifies code that deals with control values.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

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

> ---
>  include/libcamera/controls.h |  6 ++++++
>  src/libcamera/controls.cpp   | 27 +++++++++++++++++++++++++++
>  2 files changed, 33 insertions(+)
> 
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index d8acd800b143..342251c21018 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -40,6 +40,12 @@ public:
>  
>  	std::string toString() const;
>  
> +	bool operator==(const ControlValue &other) const;
> +	bool operator!=(const ControlValue &other) const
> +	{
> +		return !(*this == other);
> +	}
> +
>  private:
>  	ControlType type_;
>  
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index 70c1af481af2..bfab177fc508 100644
> --- a/src/libcamera/controls.cpp
> +++ b/src/libcamera/controls.cpp
> @@ -194,6 +194,33 @@ std::string ControlValue::toString() const
>  	return "<ValueType Error>";
>  }
>  
> +/**
> + * \brief Compare ControlValue instances for equality
> + * \return True if the values have identical types and values, false otherwise
> + */
> +bool ControlValue::operator==(const ControlValue &other) const
> +{
> +	if (type_ != other.type_)
> +		return false;
> +
> +	switch (type_) {
> +	case ControlTypeBool:
> +		return bool_ == other.bool_;
> +	case ControlTypeInteger32:
> +		return integer32_ == other.integer32_;
> +	case ControlTypeInteger64:
> +		return integer64_ == other.integer64_;
> +	default:
> +		return false;
> +	}
> +}
> +
> +/**
> + * \fn bool ControlValue::operator!=()
> + * \brief Compare ControlValue instances for non equality
> + * \return False if the values have identical types and values, true otherwise
> + */
> +
>  /**
>   * \class ControlId
>   * \brief Control static metadata
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index d8acd800b143..342251c21018 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -40,6 +40,12 @@  public:
 
 	std::string toString() const;
 
+	bool operator==(const ControlValue &other) const;
+	bool operator!=(const ControlValue &other) const
+	{
+		return !(*this == other);
+	}
+
 private:
 	ControlType type_;
 
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index 70c1af481af2..bfab177fc508 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -194,6 +194,33 @@  std::string ControlValue::toString() const
 	return "<ValueType Error>";
 }
 
+/**
+ * \brief Compare ControlValue instances for equality
+ * \return True if the values have identical types and values, false otherwise
+ */
+bool ControlValue::operator==(const ControlValue &other) const
+{
+	if (type_ != other.type_)
+		return false;
+
+	switch (type_) {
+	case ControlTypeBool:
+		return bool_ == other.bool_;
+	case ControlTypeInteger32:
+		return integer32_ == other.integer32_;
+	case ControlTypeInteger64:
+		return integer64_ == other.integer64_;
+	default:
+		return false;
+	}
+}
+
+/**
+ * \fn bool ControlValue::operator!=()
+ * \brief Compare ControlValue instances for non equality
+ * \return False if the values have identical types and values, true otherwise
+ */
+
 /**
  * \class ControlId
  * \brief Control static metadata