From 8197cc460e02c6445434eace435e3d38ebe475c6 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Fri, 19 Aug 2016 12:16:49 -0700 Subject: AAPT2: Merge Styleables instead of overriding them Styleables merge in AAPT. Preserve this behavior. Bug:30970091 Change-Id: Ie68ca675aeecd873c0648682182e2fc574e329a0 --- tools/aapt2/ResourceValues.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tools/aapt2/ResourceValues.cpp') diff --git a/tools/aapt2/ResourceValues.cpp b/tools/aapt2/ResourceValues.cpp index 73682ab110c7..321f77667b75 100644 --- a/tools/aapt2/ResourceValues.cpp +++ b/tools/aapt2/ResourceValues.cpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace aapt { @@ -732,4 +733,27 @@ void Styleable::print(std::ostream* out) const { << "]"; } +bool operator<(const Reference& a, const Reference& b) { + int cmp = a.name.valueOrDefault({}).compare(b.name.valueOrDefault({})); + if (cmp != 0) return cmp < 0; + return a.id < b.id; +} + +bool operator==(const Reference& a, const Reference& b) { + return a.name == b.name && a.id == b.id; +} + +bool operator!=(const Reference& a, const Reference& b) { + return a.name != b.name || a.id != b.id; +} + +void Styleable::mergeWith(Styleable* other) { + std::set references; + references.insert(entries.begin(), entries.end()); + references.insert(other->entries.begin(), other->entries.end()); + entries.clear(); + entries.reserve(references.size()); + entries.insert(entries.end(), references.begin(), references.end()); +} + } // namespace aapt -- cgit v1.2.3-59-g8ed1b