{"id":2632,"url":"https://patchwork.libcamera.org/api/patches/2632/?format=json","web_url":"https://patchwork.libcamera.org/patch/2632/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200113164245.52535-18-jacopo@jmondi.org>","date":"2020-01-13T16:42:39","name":"[libcamera-devel,17/23] libcamera: control: Deep-copy control values","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"f84c587c33e1e373c382554f8ab6c2bb4e8fc69f","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":{"id":15,"url":"https://patchwork.libcamera.org/api/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/2632/mbox/","series":[{"id":618,"url":"https://patchwork.libcamera.org/api/series/618/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=618","date":"2020-01-13T16:42:22","name":"Properties and compound controls","version":1,"mbox":"https://patchwork.libcamera.org/series/618/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2632/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2632/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 66A9F60703\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Jan 2020 17:40:37 +0100 (CET)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id 0428710000E;\n\tMon, 13 Jan 2020 16:40:36 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 13 Jan 2020 17:42:39 +0100","Message-Id":"<20200113164245.52535-18-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.24.0","In-Reply-To":"<20200113164245.52535-1-jacopo@jmondi.org>","References":"<20200113164245.52535-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 17/23] libcamera: control: Deep-copy\n\tcontrol values","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Mon, 13 Jan 2020 16:40:37 -0000"},"content":"Implement operator=() and copy constructor for the ControlValue class,\ndeep-copying the content of the 'other' ControlValue by using\nControlValue::set() operation which, in case of compound ControlValue,\nguarantees proper memory allocation and data copy.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/controls.h |  5 +++\n src/libcamera/controls.cpp   | 62 ++++++++++++++++++++++++++++++++++++\n 2 files changed, 67 insertions(+)","diff":"diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex bdbdb213528d..d13144b69198 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -43,6 +43,9 @@ public:\n \tControlValue(Span<float> &values);\n \t~ControlValue();\n \n+\tControlValue(const ControlValue &other);\n+\tControlValue &operator=(const ControlValue &other);\n+\n \tControlType type() const { return type_; }\n \tbool isNone() const { return type_ == ControlTypeNone; }\n \tstd::size_t numElements() const { return numElements_; }\n@@ -81,6 +84,8 @@ private:\n \tstd::size_t numElements_;\n \n \tvoid release();\n+\ttemplate<typename T>\n+\tvoid copyValue(const ControlValue &source);\n \tbool compareElement(const ControlValue &other) const;\n \tbool compareElement(const ControlValue &other, unsigned int i) const;\n \tstd::string elemToString(unsigned int i) const;\ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nindex c311ab1d6af1..fd04d2311db3 100644\n--- a/src/libcamera/controls.cpp\n+++ b/src/libcamera/controls.cpp\n@@ -189,6 +189,68 @@ ControlValue::~ControlValue()\n \trelease();\n }\n \n+template<typename T>\n+void ControlValue::copyValue(const ControlValue &other)\n+{\n+\tset<T>(other.get<T>());\n+}\n+\n+/**\n+ * \\brief Contruct a ControlValue with the content of \\a other\n+ * \\param[in] other The ControlValue to copy content from\n+ */\n+ControlValue::ControlValue(const ControlValue &other)\n+{\n+\t*this = other;\n+}\n+\n+/**\n+ * \\brief Replace the content of the ControlValue with the one of \\a other\n+ * \\param[in] other The ControlValue to copy content from\n+ *\n+ * Deep-copy the content of \\a other into the ControlValue by reserving memory\n+ * and copy data there in case \\a other transports arrays of values in one of\n+ * its pointer data members.\n+ *\n+ * \\return The ControlValue with its content replaced with the one of \\a other\n+ */\n+ControlValue &ControlValue::operator=(const ControlValue &other)\n+{\n+\tswitch (other.type_) {\n+\tcase ControlTypeBool:\n+\t\tcopyValue<bool>(other);\n+\t\tbreak;\n+\tcase ControlTypeInteger32:\n+\t\tcopyValue<int32_t>(other);\n+\t\tbreak;\n+\tcase ControlTypeInteger64:\n+\t\tcopyValue<int64_t>(other);\n+\t\tbreak;\n+\tcase ControlTypeFloat:\n+\t\tcopyValue<float>(other);\n+\t\tbreak;\n+\tcase ControlTypeCompoundBool:\n+\t\tcopyValue<Span<bool>>(other);\n+\t\tbreak;\n+\tcase ControlTypeCompoundInt32:\n+\t\tcopyValue<Span<int32_t>>(other);\n+\t\tbreak;\n+\tcase ControlTypeCompoundInt64:\n+\t\tcopyValue<Span<int64_t>>(other);\n+\t\tbreak;\n+\tcase ControlTypeCompoundFloat:\n+\t\tcopyValue<Span<float>>(other);\n+\t\tbreak;\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\ttype_ = other.type_;\n+\tnumElements_ = other.numElements_;\n+\n+\treturn *this;\n+}\n+\n /**\n  * \\fn ControlValue::type()\n  * \\brief Retrieve the data type of the value\n","prefixes":["libcamera-devel","17/23"]}