[libcamera-devel] [PATCH v6 4/5] ipa: raspberrypi: Add Overwrite method to RPiController::Metadata

Naushir Patuck naush at raspberrypi.com
Fri May 7 10:40:41 CEST 2021


Add a new Overwrite method to the Metadata class. This will overwrite
all key/value pairs in a destination object that have an identical key
in the source metadata object. Once complete, the source Metadata
object will be empty.

Signed-off-by: Naushir Patuck <naush at raspberrypi.com>
---
 src/ipa/raspberrypi/controller/metadata.hpp | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp
index 319f2320fc70..ac64f17f617c 100644
--- a/src/ipa/raspberrypi/controller/metadata.hpp
+++ b/src/ipa/raspberrypi/controller/metadata.hpp
@@ -75,6 +75,26 @@ public:
 		return *this;
 	}
 
+	void Overwrite(Metadata &other)
+	{
+		std::lock_guard<std::mutex> lock(mutex_);
+		std::lock_guard<std::mutex> other_lock(other.mutex_);
+
+		/*
+		 * Overwrite any contents of data_ with identical keys from
+		 * other.data_. Any keys from other.data_ that are not preset in
+		 * data_ will simply be copied across.
+		 *
+		 * The reason for the seemingly illogical steps below is because
+		 * std::map::merge() does not overwrite existing keys.
+		 */
+		other.data_.merge(data_);
+		std::swap(data_, other.data_);
+
+		/* Render the other object as empty now! */
+		other.data_.clear();
+	}
+
 	template<typename T>
 	T *GetLocked(std::string const &tag)
 	{
-- 
2.25.1



More information about the libcamera-devel mailing list