From e89c2b22957b9faa2d9521dd8d696ed1cefc7dda Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 25 Oct 2019 23:48:45 +0300 Subject: libcamera: controls: Index ControlList by unsigned int MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In preparation for serialization, index the ControlList by unsigned int. This will allow deserializing a ControlList without requiring external information. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- include/libcamera/controls.h | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index f24dc764..1ecc8fcb 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -78,12 +78,22 @@ private: ControlType type_; }; -static inline bool operator==(const ControlId &lhs, const ControlId &rhs) +static inline bool operator==(unsigned int lhs, const ControlId &rhs) { - return lhs.id() == rhs.id(); + return lhs == rhs.id(); } -static inline bool operator!=(const ControlId &lhs, const ControlId &rhs) +static inline bool operator!=(unsigned int lhs, const ControlId &rhs) +{ + return !(lhs == rhs); +} + +static inline bool operator==(const ControlId &lhs, unsigned int rhs) +{ + return lhs.id() == rhs; +} + +static inline bool operator!=(const ControlId &lhs, unsigned int rhs) { return !(lhs == rhs); } @@ -176,7 +186,7 @@ private: class ControlList { private: - using ControlListMap = std::unordered_map; + using ControlListMap = std::unordered_map; public: ControlList(const ControlIdMap &idmap, ControlValidator *validator = nullptr); @@ -200,7 +210,7 @@ public: template const T &get(const Control &ctrl) const { - const ControlValue *val = find(ctrl); + const ControlValue *val = find(ctrl.id()); if (!val) { static T t(0); return t; @@ -212,7 +222,7 @@ public: template void set(const Control &ctrl, const T &value) { - ControlValue *val = find(ctrl); + ControlValue *val = find(ctrl.id()); if (!val) return; @@ -223,8 +233,8 @@ public: void set(unsigned int id, const ControlValue &value); private: - const ControlValue *find(const ControlId &id) const; - ControlValue *find(const ControlId &id); + const ControlValue *find(unsigned int id) const; + ControlValue *find(unsigned int id); ControlValidator *validator_; const ControlIdMap *idmap_; -- cgit v1.2.1