[libcamera-devel,v2,4/7] ipa: raspberrypi: Add RPiController::Metadata::mergeCopy
diff mbox series

Message ID 20220905073956.7342-5-naush@raspberrypi.com
State Superseded
Headers show
Series
  • Raspberry Pi AGC digial gain fixes
Related show

Commit Message

Naushir Patuck Sept. 5, 2022, 7:39 a.m. UTC
Add a new member function to RPiController::Metadata that copies unique
key/value pairs from one object to the other. This is different from
std::map::merge that would remove the key/value pairs from the source object.

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

Comments

David Plowman Sept. 23, 2022, 10:13 a.m. UTC | #1
Hi Naush

Thanks for the patch.

On Mon, 5 Sept 2022 at 08:40, Naushir Patuck via libcamera-devel
<libcamera-devel@lists.libcamera.org> wrote:
>
> Add a new member function to RPiController::Metadata that copies unique
> key/value pairs from one object to the other. This is different from
> std::map::merge that would remove the key/value pairs from the source object.
>
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> ---
>  src/ipa/raspberrypi/controller/metadata.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/src/ipa/raspberrypi/controller/metadata.h b/src/ipa/raspberrypi/controller/metadata.h
> index 0f7ebfaf4c25..3816e9f8536d 100644
> --- a/src/ipa/raspberrypi/controller/metadata.h
> +++ b/src/ipa/raspberrypi/controller/metadata.h
> @@ -78,6 +78,18 @@ public:
>                 data_.merge(other.data_);
>         }
>
> +       void mergeCopy(Metadata &other)
> +       {
> +               std::scoped_lock lock(mutex_, other.mutex_);
> +               for (auto &kv : other.data_) {
> +                       /*
> +                        * If the metadata key exists, ignore this item and copy
> +                        * only unique key/value pairs.
> +                        */
> +                       data_.insert(kv);
> +               }

Just wondering if there's something like

data_.insert(other.data_.begin(), other.data_.end());

that would do what you want? Not sure, I might be completely wrong...

David

> +       }
> +
>         template<typename T>
>         T *getLocked(std::string const &tag)
>         {
> --
> 2.25.1
>
David Plowman Sept. 23, 2022, 10:18 a.m. UTC | #2
Sorry, one more thing... the "other" parameter should probably be "const".

Thanks!
David

On Fri, 23 Sept 2022 at 11:13, David Plowman
<david.plowman@raspberrypi.com> wrote:
>
> Hi Naush
>
> Thanks for the patch.
>
> On Mon, 5 Sept 2022 at 08:40, Naushir Patuck via libcamera-devel
> <libcamera-devel@lists.libcamera.org> wrote:
> >
> > Add a new member function to RPiController::Metadata that copies unique
> > key/value pairs from one object to the other. This is different from
> > std::map::merge that would remove the key/value pairs from the source object.
> >
> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> > ---
> >  src/ipa/raspberrypi/controller/metadata.h | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> >
> > diff --git a/src/ipa/raspberrypi/controller/metadata.h b/src/ipa/raspberrypi/controller/metadata.h
> > index 0f7ebfaf4c25..3816e9f8536d 100644
> > --- a/src/ipa/raspberrypi/controller/metadata.h
> > +++ b/src/ipa/raspberrypi/controller/metadata.h
> > @@ -78,6 +78,18 @@ public:
> >                 data_.merge(other.data_);
> >         }
> >
> > +       void mergeCopy(Metadata &other)
> > +       {
> > +               std::scoped_lock lock(mutex_, other.mutex_);
> > +               for (auto &kv : other.data_) {
> > +                       /*
> > +                        * If the metadata key exists, ignore this item and copy
> > +                        * only unique key/value pairs.
> > +                        */
> > +                       data_.insert(kv);
> > +               }
>
> Just wondering if there's something like
>
> data_.insert(other.data_.begin(), other.data_.end());
>
> that would do what you want? Not sure, I might be completely wrong...
>
> David
>
> > +       }
> > +
> >         template<typename T>
> >         T *getLocked(std::string const &tag)
> >         {
> > --
> > 2.25.1
> >

Patch
diff mbox series

diff --git a/src/ipa/raspberrypi/controller/metadata.h b/src/ipa/raspberrypi/controller/metadata.h
index 0f7ebfaf4c25..3816e9f8536d 100644
--- a/src/ipa/raspberrypi/controller/metadata.h
+++ b/src/ipa/raspberrypi/controller/metadata.h
@@ -78,6 +78,18 @@  public:
 		data_.merge(other.data_);
 	}
 
+	void mergeCopy(Metadata &other)
+	{
+		std::scoped_lock lock(mutex_, other.mutex_);
+		for (auto &kv : other.data_) {
+			/*
+                        * If the metadata key exists, ignore this item and copy
+                        * only unique key/value pairs.
+                        */
+			data_.insert(kv);
+		}
+	}
+
 	template<typename T>
 	T *getLocked(std::string const &tag)
 	{