HalManifests can be merged.
assemble_vintf and VintfObject can now merge manifests
correctly (previously, only <hal>'s are merged).
Test: libvintf_test
Test: vintf_object_test
Fixes: 78943004
Change-Id: I5e2987e9c97e0b60e976fe4e0bb8833edf043a53
diff --git a/utils.h b/utils.h
index dccc811..5378b67 100644
--- a/utils.h
+++ b/utils.h
@@ -81,6 +81,25 @@
virtual bool getBoolProperty(const std::string& key, bool defaultValue) const override;
};
+// Merge src into dst.
+// postcondition (if successful): *src == empty.
+template <typename T>
+static bool mergeField(T* dst, T* src, const T& empty = T{}) {
+ if (*dst == *src) {
+ *src = empty;
+ return true; // no conflict
+ }
+ if (*src == empty) {
+ return true;
+ }
+ if (*dst == empty) {
+ *dst = std::move(*src);
+ *src = empty;
+ return true;
+ }
+ return false;
+}
+
} // namespace details
} // namespace vintf
} // namespace android