[libcamera-devel] [PATCH 18/23] libcamera: controls: Re-oder ControlValue methods
Jacopo Mondi
jacopo at jmondi.org
Mon Jan 13 17:42:40 CET 2020
Re-order operation in ControlValue class to group const methods
together.
Cosmetic change only.
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
include/libcamera/controls.h | 10 +-
src/libcamera/controls.cpp | 222 +++++++++++++++++------------------
2 files changed, 116 insertions(+), 116 deletions(-)
diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index d13144b69198..9343a947764b 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -50,11 +50,6 @@ public:
bool isNone() const { return type_ == ControlTypeNone; }
std::size_t numElements() const { return numElements_; }
- template<typename T>
- T get() const;
- template<typename T>
- void set(const T &value);
-
std::string toString() const;
bool operator==(const ControlValue &other) const;
@@ -63,6 +58,11 @@ public:
return !(*this == other);
}
+ template<typename T>
+ T get() const;
+ template<typename T>
+ void set(const T &value);
+
private:
ControlType type_;
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index fd04d2311db3..750c36bd011e 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -269,6 +269,117 @@ ControlValue &ControlValue::operator=(const ControlValue &other)
* \return The number of elements stored in the ControlValue
*/
+std::string ControlValue::elemToString(unsigned int i) const
+{
+ switch (type_) {
+ case ControlTypeBool:
+ return bool_ ? "True " : "False ";
+ case ControlTypeInteger32:
+ return std::to_string(integer32_);
+ case ControlTypeInteger64:
+ return std::to_string(integer64_);
+ case ControlTypeFloat:
+ return std::to_string(float_);
+ case ControlTypeCompoundBool:
+ return pbool_[i] ? "True " : "False ";
+ case ControlTypeCompoundInt32:
+ return std::to_string(p32_[i]) + " ";
+ case ControlTypeCompoundInt64:
+ return std::to_string(p64_[i]) + " ";
+ case ControlTypeCompoundFloat:
+ return std::to_string(pfloat_[i]) + " ";
+ default:
+ return "<None>";
+ }
+}
+
+/**
+ * \brief Assemble and return a string describing the value
+ * \return A string describing the ControlValue
+ */
+std::string ControlValue::toString() const
+{
+ if (ControlTypeNone)
+ return "<ValueType Error>";
+
+ std::string str;
+ for (unsigned int i = 0; i < numElements_; ++i)
+ str += elemToString(i);
+
+ return str;
+}
+
+bool ControlValue::compareElement(const ControlValue &other) const
+{
+ switch (type_) {
+ case ControlTypeBool:
+ return bool_ == other.bool_;
+ case ControlTypeInteger32:
+ return integer32_ == other.integer32_;
+ case ControlTypeInteger64:
+ return integer64_ == other.integer64_;
+ case ControlTypeFloat:
+ return float_ == other.float_;
+ default:
+ return false;
+ }
+}
+
+bool ControlValue::compareElement(const ControlValue &other, unsigned int i) const
+{
+ switch (type_) {
+ case ControlTypeCompoundBool:
+ return pbool_[i] == other.pbool_[i];
+ case ControlTypeCompoundInt32:
+ return p32_[i] == other.p32_[i];
+ case ControlTypeCompoundInt64:
+ return p64_[i] == other.p64_[i];
+ case ControlTypeCompoundFloat:
+ return pfloat_[i] == other.pfloat_[i];
+ default:
+ return false;
+ }
+}
+
+/**
+ * \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;
+
+ if (numElements_ != other.numElements())
+ return false;
+
+ switch (type_) {
+ case ControlTypeBool:
+ case ControlTypeInteger32:
+ case ControlTypeInteger64:
+ case ControlTypeFloat:
+ return compareElement(other);
+ case ControlTypeCompoundBool:
+ case ControlTypeCompoundInt32:
+ case ControlTypeCompoundInt64:
+ case ControlTypeCompoundFloat:
+ for (unsigned int i = 0; i < numElements_; ++i) {
+ if (!compareElement(other, i))
+ return false;
+ }
+
+ return true;
+ 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
+ */
+
/**
* \fn template<typename T> const T ControlValue::get() const
* \brief Get the control values
@@ -454,117 +565,6 @@ void ControlValue::set<Span<float>>(const Span<float> &values)
#endif /* __DOXYGEN__ */
-std::string ControlValue::elemToString(unsigned int i) const
-{
- switch (type_) {
- case ControlTypeBool:
- return bool_ ? "True " : "False ";
- case ControlTypeInteger32:
- return std::to_string(integer32_);
- case ControlTypeInteger64:
- return std::to_string(integer64_);
- case ControlTypeFloat:
- return std::to_string(float_);
- case ControlTypeCompoundBool:
- return pbool_[i] ? "True " : "False ";
- case ControlTypeCompoundInt32:
- return std::to_string(p32_[i]) + " ";
- case ControlTypeCompoundInt64:
- return std::to_string(p64_[i]) + " ";
- case ControlTypeCompoundFloat:
- return std::to_string(pfloat_[i]) + " ";
- default:
- return "<None>";
- }
-}
-
-/**
- * \brief Assemble and return a string describing the value
- * \return A string describing the ControlValue
- */
-std::string ControlValue::toString() const
-{
- if (ControlTypeNone)
- return "<ValueType Error>";
-
- std::string str;
- for (unsigned int i = 0; i < numElements_; ++i)
- str += elemToString(i);
-
- return str;
-}
-
-bool ControlValue::compareElement(const ControlValue &other) const
-{
- switch (type_) {
- case ControlTypeBool:
- return bool_ == other.bool_;
- case ControlTypeInteger32:
- return integer32_ == other.integer32_;
- case ControlTypeInteger64:
- return integer64_ == other.integer64_;
- case ControlTypeFloat:
- return float_ == other.float_;
- default:
- return false;
- }
-}
-
-bool ControlValue::compareElement(const ControlValue &other, unsigned int i) const
-{
- switch (type_) {
- case ControlTypeCompoundBool:
- return pbool_[i] == other.pbool_[i];
- case ControlTypeCompoundInt32:
- return p32_[i] == other.p32_[i];
- case ControlTypeCompoundInt64:
- return p64_[i] == other.p64_[i];
- case ControlTypeCompoundFloat:
- return pfloat_[i] == other.pfloat_[i];
- default:
- return false;
- }
-}
-
-/**
- * \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;
-
- if (numElements_ != other.numElements())
- return false;
-
- switch (type_) {
- case ControlTypeBool:
- case ControlTypeInteger32:
- case ControlTypeInteger64:
- case ControlTypeFloat:
- return compareElement(other);
- case ControlTypeCompoundBool:
- case ControlTypeCompoundInt32:
- case ControlTypeCompoundInt64:
- case ControlTypeCompoundFloat:
- for (unsigned int i = 0; i < numElements_; ++i) {
- if (!compareElement(other, i))
- return false;
- }
-
- return true;
- 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
--
2.24.0
More information about the libcamera-devel
mailing list