Patch Detail
Show a patch.
GET /api/patches/1494/?format=api
{ "id": 1494, "url": "https://patchwork.libcamera.org/api/patches/1494/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1494/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20190621161401.28337-2-kieran.bingham@ideasonboard.com>", "date": "2019-06-21T16:13:53", "name": "[libcamera-devel,RFC,v2,1/9] libcamera: Value: Provide abstract value class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "9174aa23e0edf3ef5cc7f1f661f20fc915d1d4e3", "submitter": { "id": 4, "url": "https://patchwork.libcamera.org/api/people/4/?format=api", "name": "Kieran Bingham", "email": "kieran.bingham@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1494/mbox/", "series": [ { "id": 370, "url": "https://patchwork.libcamera.org/api/series/370/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=370", "date": "2019-06-21T16:13:52", "name": "Libcamera Controls", "version": 2, "mbox": "https://patchwork.libcamera.org/series/370/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1494/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1494/checks/", "tags": {}, "headers": { "Return-Path": "<kieran.bingham@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B89E160E4D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 21 Jun 2019 18:14:06 +0200 (CEST)", "from localhost.localdomain\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 43E1D33C;\n\tFri, 21 Jun 2019 18:14:06 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1561133646;\n\tbh=+5rebP32rbsRGWdoofnbvFIibREVMlWM+svdDmUePKQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=reKn0PQPRuZo9r5cT+PRJoRuYG1ZMy/p6mMed4BA/G4TTjGDGmOrUlLNmoWxz+vhw\n\tb7SPg1lwFUuE20EZibcX1+q2KVZu9XvqzriX10GCTZ+LUOr7ZMP5dwx7pFtblVR6Bg\n\tyvEjVFYWtDhUYIacpLUJ/Bc14hDPUC1JFz5Fa3TM=", "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>", "To": "LibCamera Devel <libcamera-devel@lists.libcamera.org>", "Date": "Fri, 21 Jun 2019 17:13:53 +0100", "Message-Id": "<20190621161401.28337-2-kieran.bingham@ideasonboard.com>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20190621161401.28337-1-kieran.bingham@ideasonboard.com>", "References": "<20190621161401.28337-1-kieran.bingham@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [RFC PATCH v2 1/9] libcamera: Value: Provide\n\tabstract value class", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.23", "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": "Fri, 21 Jun 2019 16:14:07 -0000" }, "content": "To facilitate passing typed data generically, implement a class which stores\nthe type and value as efficiently as possible.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/meson.build | 1 +\n include/libcamera/value.h | 63 ++++++++++\n src/libcamera/meson.build | 1 +\n src/libcamera/value.cpp | 226 ++++++++++++++++++++++++++++++++++\n 4 files changed, 291 insertions(+)\n create mode 100644 include/libcamera/value.h\n create mode 100644 src/libcamera/value.cpp", "diff": "diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 201832105457..eb2211ae1fc3 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -12,6 +12,7 @@ libcamera_api = files([\n 'signal.h',\n 'stream.h',\n 'timer.h',\n+ 'value.h',\n 'version.h',\n ])\n \ndiff --git a/include/libcamera/value.h b/include/libcamera/value.h\nnew file mode 100644\nindex 000000000000..00c5d53d5cc0\n--- /dev/null\n+++ b/include/libcamera/value.h\n@@ -0,0 +1,63 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * value.h - Abstract value handling\n+ */\n+\n+#include <map>\n+\n+#ifndef __LIBCAMERA_VALUE_H__\n+#define __LIBCAMERA_VALUE_H__\n+\n+namespace libcamera {\n+\n+enum ValueType : uint8_t {\n+\tValueNull,\n+\tValueBool,\n+\tValueInteger,\n+\tValueInteger64,\n+\tValueString,\n+};\n+\n+class Value\n+{\n+public:\n+\tValue();\n+\tValue(bool value);\n+\tValue(int value);\n+\tValue(const char *value);\n+\tValue(const std::string &value);\n+\n+\tValueType type() const { return type_; };\n+\tbool isNull() const { return type_ == ValueNull; };\n+\n+\tvoid set(bool value);\n+\tvoid set(int value);\n+\tvoid set(int64_t value);\n+\tvoid set(const char *value);\n+\tvoid set(const std::string &value);\n+\n+\tbool getBool() const;\n+\tint getInt() const;\n+\tint getInt64() const;\n+\tstd::string getString() const;\n+\n+\tstd::string toString() const;\n+\n+private:\n+\tValueType type_;\n+\n+\tunion {\n+\t\tbool bool_;\n+\t\tint integer_;\n+\t\tint64_t integer64_;\n+\t};\n+\tstd::string string_;\n+};\n+\n+std::ostream &operator<<(std::ostream &stream, const Value &value);\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_VALUE_H__ */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 68c7ce14b5b4..8e68373118df 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -27,6 +27,7 @@ libcamera_sources = files([\n 'v4l2_device.cpp',\n 'v4l2_subdevice.cpp',\n 'v4l2_videodevice.cpp',\n+ 'value.cpp',\n 'version.cpp',\n ])\n \ndiff --git a/src/libcamera/value.cpp b/src/libcamera/value.cpp\nnew file mode 100644\nindex 000000000000..f713907b38dd\n--- /dev/null\n+++ b/src/libcamera/value.cpp\n@@ -0,0 +1,226 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * value.cpp - Abstract value handling\n+ */\n+\n+#include <limits.h>\n+#include <sstream>\n+#include <string>\n+\n+#include <libcamera/value.h>\n+\n+#include \"log.h\" // For ASSERT()\n+\n+/**\n+ * \\file value.h\n+ * \\brief Handles variant value types as an abstract object\n+ */\n+\n+namespace libcamera {\n+\n+/**\n+ * \\enum ValueType\n+ * Determines the type of value represented by a \\a Value\n+ * \\var ValueNull\n+ * Identifies an unset value\n+ * \\var ValueBool\n+ * Identifies controls storing a boolean value\n+ * \\var ValueInteger\n+ * Identifies controls storing an integer value\n+ * \\var ValueString\n+ * Identifies controls storing a string value\n+ */\n+\n+/**\n+ * \\class Value\n+ * \\brief Abstract a value for a common data exchange\n+ */\n+\n+/**\n+ * \\brief Construct an empty Value.\n+ * The Value must be \\a set() before being used.\n+ */\n+Value::Value()\n+\t: type_(ValueNull)\n+{\n+}\n+\n+/**\n+ * \\brief Construct a Boolean Value\n+ * \\param[in] value Boolean value to store\n+ */\n+Value::Value(bool value)\n+\t: type_(ValueBool), bool_(value)\n+{\n+}\n+\n+/**\n+ * \\brief Construct an integer Value\n+ * \\param[in] value Integer value to store\n+ */\n+Value::Value(int value)\n+\t: type_(ValueInteger), integer_(value)\n+{\n+}\n+\n+/**\n+ * \\brief Construct a string Value\n+ * \\param[in] value String representation to store\n+ */\n+Value::Value(const char *value)\n+\t: type_(ValueString), string_(value)\n+{\n+}\n+\n+/**\n+ * \\brief Construct a string Value\n+ * \\param[in] value String representation to store\n+ */\n+Value::Value(const std::string &value)\n+\t: type_(ValueString), string_(value)\n+{\n+}\n+\n+/**\n+ * \\fn Value::type\n+ * \\brief Return the type of value represented by the object\n+ */\n+\n+/**\n+ * \\fn Value::isNull\n+ * \\brief Determines if the Value is initialised\n+ * \\return true if the value type is ValueNull, false otherwise\n+ */\n+\n+/**\n+ * \\brief Set the value with a boolean\n+ * \\param[in] value Boolean value to store\n+ */\n+void Value::set(bool value)\n+{\n+\ttype_ = ValueBool;\n+\tbool_ = value;\n+}\n+\n+/**\n+ * \\brief Set the value with an integer\n+ * \\param[in] value Integer value to store\n+ */\n+void Value::set(int value)\n+{\n+\ttype_ = ValueInteger;\n+\tinteger_ = value;\n+}\n+\n+/**\n+ * \\brief Set the value with a 64 bit integer\n+ * \\param[in] value Integer value to store\n+ */\n+void Value::set(int64_t value)\n+{\n+\ttype_ = ValueInteger64;\n+\tinteger64_ = value;\n+}\n+\n+/**\n+ * \\brief Set the value with a string representation\n+ * \\param[in] value String value to store\n+ */\n+void Value::set(const char *value)\n+{\n+\ttype_ = ValueString;\n+\tstring_ = value;\n+}\n+\n+/**\n+ * \\brief Set the value with a string representation\n+ * \\param[in] value String value to store\n+ */\n+void Value::set(const std::string &value)\n+{\n+\ttype_ = ValueString;\n+\tstring_ = value;\n+}\n+\n+/**\n+ * \\brief Get the boolean value.\n+ *\n+ * The Value type must be Boolean.\n+ */\n+bool Value::getBool() const\n+{\n+\tASSERT(type_ == ValueBool);\n+\n+\treturn bool_;\n+}\n+\n+/**\n+ * \\brief Get the integer value.\n+ *\n+ * The Value type must be Integer.\n+ */\n+int Value::getInt() const\n+{\n+\tASSERT(type_ == ValueInteger);\n+\n+\treturn integer_;\n+}\n+\n+/**\n+ * \\brief Get the 64bit integer value.\n+ *\n+ * The Value type must be Integer64.\n+ */\n+int Value::getInt64() const\n+{\n+\tASSERT(type_ == ValueInteger64);\n+\n+\treturn integer64_;\n+}\n+\n+/**\n+ * \\brief Get the string value.\n+ *\n+ * The Value type must be String.\n+ */\n+std::string Value::getString() const\n+{\n+\tASSERT(type_ == ValueString);\n+\n+\treturn string_;\n+}\n+\n+/**\n+ * \\brief Prepare a string representation of the Value\n+ */\n+std::string Value::toString() const\n+{\n+\tswitch (type_) {\n+\tcase ValueNull:\n+\t\treturn \"<NULL>\";\n+\tcase ValueBool:\n+\t\treturn bool_ ? \"True\" : \"False\";\n+\tcase ValueInteger:\n+\t\treturn std::to_string(integer_);\n+\tcase ValueInteger64:\n+\t\treturn std::to_string(integer64_);\n+\tcase ValueString:\n+\t\treturn string_;\n+\t}\n+\n+\t/* Unreachable */\n+\treturn \"<ValueType Error>\";\n+}\n+\n+/**\n+ * \\brief Provide a string stream representation of the Value \\a value to\n+ * the \\a stream.\n+ */\n+std::ostream &operator<<(std::ostream &stream, const Value &value)\n+{\n+\treturn stream << value.toString();\n+}\n+\n+} /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "RFC", "v2", "1/9" ] }