[libcamera-devel,05/21] libcamera: controls: Make ControlInfoMap a class

Message ID 20190924172503.30864-6-jacopo@jmondi.org
State Superseded
Headers show
Series
  • Implement control serialization
Related show

Commit Message

Jacopo Mondi Sept. 24, 2019, 5:24 p.m. UTC
Make a class out of ControlInfoMap to be able to serialize its content.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 include/libcamera/controls.h        | 24 +++++++++-
 src/libcamera/controls.cpp          | 68 ++++++++++++++++++++++++++++-
 src/libcamera/pipeline/uvcvideo.cpp |  4 +-
 src/libcamera/pipeline/vimc.cpp     |  4 +-
 4 files changed, 92 insertions(+), 8 deletions(-)

Patch

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 8a7ddc510497..79731c4932ae 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -42,7 +42,29 @@  private:
 	const struct ControlMetadata *meta_;
 };
 
-using ControlInfoMap = std::unordered_map<ControlId, ControlInfo>;
+class ControlInfoMap
+{
+private:
+	using InfoMap = std::unordered_map<ControlId, ControlInfo>;
+
+public:
+	using iterator = InfoMap::iterator;
+	using const_iterator = InfoMap::const_iterator;
+
+	iterator begin() { return map_.begin(); }
+	iterator end() { return map_.end(); }
+	const_iterator begin() const { return map_.begin(); }
+	const_iterator end() const { return map_.end(); }
+
+	iterator find(ControlId id) { return map_.find(id); }
+	const_iterator find(ControlId id) const { return map_.find(id); }
+
+	void emplace(const ControlId id, const DataValue &min,
+		     const DataValue &max);
+
+private:
+	InfoMap map_;
+};
 
 using ControlValue = DataValue;
 
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index ee19eb6dc014..ec7ac7ba9ed6 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -169,10 +169,76 @@  std::string ControlInfo::toString() const
 }
 
 /**
- * \typedef ControlInfoMap
+ * \class ControlInfoMap
  * \brief A map of ControlId to ControlInfo
  */
 
+/**
+ * \typedef ControlInfoMap::iterator
+ * \brief Iterator for the controls contained within the list
+ */
+
+/**
+ * \typedef ControlInfoMap::const_iterator
+ * \brief Const iterator for the controls contained within the list
+ */
+
+/**
+ * \fn iterator ControlInfoMap::begin()
+ * \brief Retrieve an iterator to the first Control in the list
+ * \return An iterator to the first Control in the list
+ */
+
+/**
+ * \fn const_iterator ControlInfoMap::begin() const
+ * \brief Retrieve a const_iterator to the first Control in the list
+ * \return A const_iterator to the first Control in the list
+ */
+
+/**
+ * \fn iterator ControlInfoMap::end()
+ * \brief Retrieve an iterator pointing to the past-the-end control in the list
+ * \return An iterator to the element following the last control in the list
+ */
+
+/**
+ * \fn const_iterator ControlInfoMap::end() const
+ * \brief Retrieve a const iterator pointing to the past-the-end control in the
+ * list
+ * \return A const iterator to the element following the last control in the
+ * list
+ */
+
+/**
+ * \fn iterator ControlInfoMap::find(ControlId id)
+ * \brief Find ControlInfo with \a id
+ * \param id The control identifier
+ * \return An interator to the ControlInfo with key \a id or the
+ * past-the-end iterator if no element with key \a id exists
+ */
+
+/**
+ * \fn const_iterator ControlInfoMap::find(ControlId id) const
+ * \brief Find ControlInfo with \a id
+ * \param id The control identifier
+ * \return A const interator to the ControlInfo with key \a id or the
+ * past-the-end iterator if no element with key \a id exists
+ */
+
+/**
+ * \brief Insert a new element in the map constructed in-place
+ * \param[in] id The control ID
+ * \param[in] min The control minimum value
+ * \param[in] max The control maximum value
+ */
+void ControlInfoMap::emplace(const ControlId id, const DataValue &min,
+			     const DataValue &max)
+{
+	map_.emplace(std::piecewise_construct,
+		     std::forward_as_tuple(id),
+		     std::forward_as_tuple(id, min, max));
+}
+
 /**
  * \typedef ControlValue
  * \brief A control value stored in the ControlList class
diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp
index 8965210550d2..02455d1ac675 100644
--- a/src/libcamera/pipeline/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo.cpp
@@ -374,9 +374,7 @@  int UVCCameraData::init(MediaEntity *entity)
 			continue;
 		}
 
-		controlInfo_.emplace(std::piecewise_construct,
-				     std::forward_as_tuple(id),
-				     std::forward_as_tuple(id, info.min(), info.max()));
+		controlInfo_.emplace(id, info.min(), info.max());
 	}
 
 	return 0;
diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp
index f26a91f86ec1..5515704df14c 100644
--- a/src/libcamera/pipeline/vimc.cpp
+++ b/src/libcamera/pipeline/vimc.cpp
@@ -443,9 +443,7 @@  int VimcCameraData::init(MediaDevice *media)
 			continue;
 		}
 
-		controlInfo_.emplace(std::piecewise_construct,
-				     std::forward_as_tuple(id),
-				     std::forward_as_tuple(id, info.min(), info.max()));
+		controlInfo_.emplace(id, info.min(), info.max());
 	}
 
 	return 0;