diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-08-14 14:26:04 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2015-10-16 12:13:08 -0700 |
commit | 1ab598f46c3ff520a67f9d80194847741f3467ab (patch) | |
tree | 4846790211599fdd7a9bb35ec94df4a6ec4839d6 /tools/aapt2/Resource.h | |
parent | 547c346bb34878b691fd53e54aa3a88efcc5dc6f (diff) |
AAPT2: Separate out the various steps
An early refactor. Some ideas became clearer as
development continued. Now the various phases are much
clearer and more easily reusable.
Also added a ton of tests!
Change-Id: Ic8f0a70c8222370352e63533b329c40457c0903e
Diffstat (limited to 'tools/aapt2/Resource.h')
-rw-r--r-- | tools/aapt2/Resource.h | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/tools/aapt2/Resource.h b/tools/aapt2/Resource.h index fa9ac07b1779..31fe298670ae 100644 --- a/tools/aapt2/Resource.h +++ b/tools/aapt2/Resource.h @@ -17,12 +17,16 @@ #ifndef AAPT_RESOURCE_H #define AAPT_RESOURCE_H -#include "StringPiece.h" +#include "ConfigDescription.h" +#include "Source.h" + +#include "util/StringPiece.h" #include <iomanip> #include <limits> #include <string> #include <tuple> +#include <vector> namespace aapt { @@ -78,6 +82,7 @@ struct ResourceName { bool operator<(const ResourceName& rhs) const; bool operator==(const ResourceName& rhs) const; bool operator!=(const ResourceName& rhs) const; + std::u16string toString() const; }; /** @@ -125,7 +130,7 @@ struct ResourceId { ResourceId(); ResourceId(const ResourceId& rhs); ResourceId(uint32_t resId); - ResourceId(size_t p, size_t t, size_t e); + ResourceId(uint8_t p, uint8_t t, uint16_t e); bool isValid() const; uint8_t packageId() const; @@ -135,6 +140,29 @@ struct ResourceId { bool operator==(const ResourceId& rhs) const; }; +struct SourcedResourceName { + ResourceName name; + size_t line; + + inline bool operator==(const SourcedResourceName& rhs) const { + return name == rhs.name && line == rhs.line; + } +}; + +struct ResourceFile { + // Name + ResourceName name; + + // Configuration + ConfigDescription config; + + // Source + Source source; + + // Exported symbols + std::vector<SourcedResourceName> exportedSymbols; +}; + // // ResourceId implementation. // @@ -148,17 +176,7 @@ inline ResourceId::ResourceId(const ResourceId& rhs) : id(rhs.id) { inline ResourceId::ResourceId(uint32_t resId) : id(resId) { } -inline ResourceId::ResourceId(size_t p, size_t t, size_t e) : id(0) { - if (p > std::numeric_limits<uint8_t>::max() || - t > std::numeric_limits<uint8_t>::max() || - e > std::numeric_limits<uint16_t>::max()) { - // This will leave the ResourceId in an invalid state. - return; - } - - id = (static_cast<uint8_t>(p) << 24) | - (static_cast<uint8_t>(t) << 16) | - static_cast<uint16_t>(e); +inline ResourceId::ResourceId(uint8_t p, uint8_t t, uint16_t e) : id((p << 24) | (t << 16) | e) { } inline bool ResourceId::isValid() const { @@ -217,6 +235,10 @@ inline bool ResourceName::operator<(const ResourceName& rhs) const { < std::tie(rhs.package, rhs.type, rhs.entry); } +inline bool operator<(const ResourceName& lhs, const ResourceNameRef& b) { + return ResourceNameRef(lhs) < b; +} + inline bool ResourceName::operator==(const ResourceName& rhs) const { return std::tie(package, type, entry) == std::tie(rhs.package, rhs.type, rhs.entry); @@ -227,6 +249,18 @@ inline bool ResourceName::operator!=(const ResourceName& rhs) const { != std::tie(rhs.package, rhs.type, rhs.entry); } +inline bool operator!=(const ResourceName& lhs, const ResourceNameRef& rhs) { + return ResourceNameRef(lhs) != rhs; +} + +inline std::u16string ResourceName::toString() const { + std::u16string result; + if (!package.empty()) { + result = package + u":"; + } + return result + aapt::toString(type).toString() + u"/" + entry; +} + inline ::std::ostream& operator<<(::std::ostream& out, const ResourceName& name) { if (!name.package.empty()) { out << name.package << ":"; |