From patchwork Mon Jan 13 16:42:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2633 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EF23260703 for ; Mon, 13 Jan 2020 17:40:37 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 8CA03100005; Mon, 13 Jan 2020 16:40:37 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 13 Jan 2020 17:42:40 +0100 Message-Id: <20200113164245.52535-19-jacopo@jmondi.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200113164245.52535-1-jacopo@jmondi.org> References: <20200113164245.52535-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 18/23] libcamera: controls: Re-oder ControlValue methods X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jan 2020 16:40:38 -0000 Re-order operation in ControlValue class to group const methods together. Cosmetic change only. Signed-off-by: Jacopo Mondi --- 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 - T get() const; - template - void set(const T &value); - std::string toString() const; bool operator==(const ControlValue &other) const; @@ -63,6 +58,11 @@ public: return !(*this == other); } + template + T get() const; + template + 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 ""; + } +} + +/** + * \brief Assemble and return a string describing the value + * \return A string describing the ControlValue + */ +std::string ControlValue::toString() const +{ + if (ControlTypeNone) + return ""; + + 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 const T ControlValue::get() const * \brief Get the control values @@ -454,117 +565,6 @@ void ControlValue::set>(const Span &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 ""; - } -} - -/** - * \brief Assemble and return a string describing the value - * \return A string describing the ControlValue - */ -std::string ControlValue::toString() const -{ - if (ControlTypeNone) - return ""; - - 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