libcamera: controls: Add comparison operators for ControlValue

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: Jacopo Mondi <jacopo@jmondi.org>
Tested-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
Laurent Pinchart 2019-10-12 06:35:21 +03:00
parent 33ee44dc16
commit 273b87c781
2 changed files with 33 additions and 0 deletions

View file

@ -40,6 +40,12 @@ public:
std::string toString() const; std::string toString() const;
bool operator==(const ControlValue &other) const;
bool operator!=(const ControlValue &other) const
{
return !(*this == other);
}
private: private:
ControlType type_; ControlType type_;

View file

@ -194,6 +194,33 @@ std::string ControlValue::toString() const
return "<ValueType Error>"; 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 * \class ControlId
* \brief Control static metadata * \brief Control static metadata