summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Klug <stefan.klug@ideasonboard.com>2024-03-07 11:27:38 +0100
committerStefan Klug <stefan.klug@ideasonboard.com>2024-03-12 17:04:28 +0100
commitd54abd32affdb7d7458cd2a0889a7afe6a5a5d33 (patch)
tree1df71fcee4f7383ae75898ce408ca492c05b5347 /src
parent2e2ba223f3a249f1c04fe88c2709ca6e7d42c242 (diff)
libcamera: controls: Add policy parameter to ControlList::merge()
This is useful in many cases although not included in the stl. Note: This is an ABI incompatible change. Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/controls.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index b808116c..16d3547c 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -908,12 +908,26 @@ ControlList::ControlList(const ControlInfoMap &infoMap,
*/
/**
+ * \enum ControlList::MergePolicy
+ * \brief The policy used by the merge function
+ *
+ * \var ControlList::MergePolicy::KeepExisting
+ * \brief Existing controls in the target list are kept
+ *
+ * \var ControlList::MergePolicy::OverwriteExisting
+ * \brief Existing controls in the target list are updated
+ */
+
+/**
* \brief Merge the \a source into the ControlList
* \param[in] source The ControlList to merge into this object
+ * \param[in] policy Controls if existing elements in *this shall be
+ * overwritten
*
* Merging two control lists copies elements from the \a source and inserts
* them in *this. If the \a source contains elements whose key is already
- * present in *this, then those elements are not overwritten.
+ * present in *this, then those elements are only overwritten if
+ * \a policy is MergePolicy::OverwriteExisting.
*
* Only control lists created from the same ControlIdMap or ControlInfoMap may
* be merged. Attempting to do otherwise results in undefined behaviour.
@@ -921,7 +935,7 @@ ControlList::ControlList(const ControlInfoMap &infoMap,
* \todo Reimplement or implement an overloaded version which internally uses
* std::unordered_map::merge() and accepts a non-const argument.
*/
-void ControlList::merge(const ControlList &source)
+void ControlList::merge(const ControlList &source, MergePolicy policy)
{
/**
* \todo ASSERT that the current and source ControlList are derived
@@ -936,7 +950,7 @@ void ControlList::merge(const ControlList &source)
*/
for (const auto &ctrl : source) {
- if (contains(ctrl.first)) {
+ if (policy == MergePolicy::KeepExisting && contains(ctrl.first)) {
const ControlId *id = idmap_->at(ctrl.first);
LOG(Controls, Warning)
<< "Control " << id->name() << " not overwritten";